feat!: release v2 (#6545)

Co-authored-by: Artur <145776561+arturict@users.noreply.github.com>
Co-authored-by: arturict <arturict@users.noreply.github.com>
Co-authored-by: Thomas <thomas@ajnart.fr>
Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com>
Co-authored-by: Danura30082 <danura30082+github@gmail.com>
Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com>
Co-authored-by: ajnart <thomas@ajnart.fr>
Co-authored-by: ajnart <thomas@ajnart.dev>
Co-authored-by: chenjun <chenjun@foxmail.com>
Co-authored-by: Wikibear <wikibear@users.noreply.github.com>
Co-authored-by: Bergasha <bergasha@gmail.com>
Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com>
Co-authored-by: Lucas Araujo <lucas.lra@gmail.com>
Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com>
Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social>
Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com>
Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com>
Co-authored-by: thrawnx <tight.bulb9384@fastmail.com>
Co-authored-by: Chris <58918656+nordada@users.noreply.github.com>
Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com>
Co-authored-by: Yanis <naamaneyanis@gmail.com>
Co-authored-by: Wikibear <me@sej.de>
Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
This commit is contained in:
3286 files changed
+284386 -139176

No files matched your search

+149
View File
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
"strings"
"sync"
@@ -197,3 +198,151 @@ func GetPR(ctx context.Context, number int) (*PR, error) {
UpdatedAt: r.UpdatedAt,
}, nil
}
type Check struct {
Name string `json:"name"`
State string `json:"state"`
Bucket string `json:"bucket"`
Workflow string `json:"workflow"`
Link string `json:"link"`
StartedAt string `json:"startedAt"`
CompletedAt string `json:"completedAt"`
Description string `json:"description"`
Event string `json:"event"`
}
var checkBucketKeys = map[string]string{
"pass": "pass",
"fail": "fail",
"pending": "pending",
"skipping": "skipping",
"cancel": "cancel",
}
func (c Check) BucketKey() string {
if key, found := checkBucketKeys[strings.ToLower(c.Bucket)]; found {
return key
}
return "pending"
}
func (c Check) IsPending() bool {
return c.Bucket == "pending" || c.State == "PENDING" || c.State == "IN_PROGRESS" || c.State == "STARTING"
}
func (c Check) IsSuccess() bool {
return c.Bucket == "pass" || c.State == "SUCCESS"
}
func (c Check) IsFailure() bool {
return c.Bucket == "fail" || c.State == "FAILURE" || c.State == "ERROR"
}
func (c Check) IsSkipped() bool {
return c.Bucket == "skipping" || c.Bucket == "cancel" || c.State == "SKIPPED" || c.State == "CANCELLED"
}
func (c Check) Duration() string {
if c.StartedAt == "" {
return ""
}
start, err := time.Parse(time.RFC3339, c.StartedAt)
if err != nil || start.IsZero() {
return ""
}
end := time.Now()
if c.CompletedAt != "" {
if tEnd, err := time.Parse(time.RFC3339, c.CompletedAt); err == nil && !tEnd.IsZero() {
end = tEnd
}
}
d := end.Sub(start).Round(time.Second)
if d < 0 {
return ""
}
if d < time.Minute {
return fmt.Sprintf("%ds", int(d.Seconds()))
}
if d < time.Hour {
return fmt.Sprintf("%dm%02ds", int(d.Minutes()), int(d.Seconds())%60)
}
return fmt.Sprintf("%dh%02dm", int(d.Hours()), int(d.Minutes())%60)
}
var prChecksCache = struct {
sync.Mutex
entries map[int]cachedChecks
}{entries: make(map[int]cachedChecks)}
type cachedChecks struct {
checks []Check
fetchedAt time.Time
}
func GetPRChecks(ctx context.Context, number int, refresh bool) ([]Check, error) {
if number <= 0 {
return nil, fmt.Errorf("invalid PR number: %d", number)
}
prChecksCache.Lock()
entry, found := prChecksCache.entries[number]
prChecksCache.Unlock()
if !refresh && found && time.Since(entry.fetchedAt) < 15*time.Second {
return append([]Check(nil), entry.checks...), nil
}
cmd := exec.CommandContext(ctx, "gh", "pr", "checks", fmt.Sprint(number),
"--repo", Repo,
"--json", "name,state,bucket,workflow,link,startedAt,completedAt,description,event",
)
out, err := cmd.CombinedOutput()
if err != nil && len(out) == 0 {
return nil, commandError(err, out)
}
var checks []Check
if jsonErr := json.Unmarshal(out, &checks); jsonErr != nil {
if err != nil {
return nil, commandError(err, out)
}
return nil, fmt.Errorf("parse checks JSON: %w", jsonErr)
}
prChecksCache.Lock()
prChecksCache.entries[number] = cachedChecks{checks: checks, fetchedAt: time.Now()}
prChecksCache.Unlock()
return checks, nil
}
func WatchPRChecks(ctx context.Context, number int) error {
cmd := exec.CommandContext(ctx, "gh", "pr", "checks", fmt.Sprint(number), "--repo", Repo, "--watch")
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func CurrentBranchPR(ctx context.Context) (*PR, error) {
out, err := exec.CommandContext(ctx, "gh", "pr", "view",
"--repo", Repo,
"--json", "number,title,author,headRefName,headRefOid,updatedAt,isDraft,statusCheckRollup",
).CombinedOutput()
if err != nil {
return nil, commandError(err, out)
}
var r rawPR
if err := json.Unmarshal(out, &r); err != nil {
return nil, err
}
return &PR{
Number: r.Number,
Title: r.Title,
Author: r.Author.Login,
HeadRef: r.HeadRefName,
HeadSHA: r.HeadRefOID,
CIState: rollupState(r.StatusCheckRollup),
IsDraft: r.IsDraft,
UpdatedAt: r.UpdatedAt,
}, nil
}
+44
View File
@@ -89,3 +89,47 @@ func TestListPRsExcludesBotsIntegration(t *testing.T) {
}
}
}
func TestCheckHelpersAndDuration(t *testing.T) {
c1 := Check{
Name: "Test Job",
State: "SUCCESS",
Bucket: "pass",
StartedAt: "2026-08-21T10:00:00Z",
CompletedAt: "2026-08-21T10:05:30Z",
}
if !c1.IsSuccess() || c1.IsFailure() || c1.IsPending() || c1.IsSkipped() {
t.Fatalf("unexpected state helpers for c1: success=%v, fail=%v, pend=%v, skip=%v", c1.IsSuccess(), c1.IsFailure(), c1.IsPending(), c1.IsSkipped())
}
if d := c1.Duration(); d != "5m30s" {
t.Fatalf("Duration() = %q, want 5m30s", d)
}
c2 := Check{
Name: "Fail Job",
State: "FAILURE",
Bucket: "fail",
}
if !c2.IsFailure() {
t.Fatalf("expected c2 to be failure")
}
if c2.Duration() != "" {
t.Fatalf("expected empty duration for missing timestamps")
}
c3 := Check{
Name: "Pending Job",
Bucket: "pending",
}
if !c3.IsPending() {
t.Fatalf("expected c3 to be pending")
}
c4 := Check{
Name: "Skipped Job",
Bucket: "skipping",
}
if !c4.IsSkipped() {
t.Fatalf("expected c4 to be skipped")
}
}