diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index 783d6e4b9d4..26bd76e98f3 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -1875,13 +1875,14 @@ "repo.pulls.push_rejected_summary": "Full Rejection Message", "repo.pulls.push_rejected_no_message": "Push Failed: The push was rejected but there was no remote message. Review the Git Hooks for this repository.", "repo.pulls.open_unmerged_pull_exists": "You cannot perform a reopen operation because there is a pending pull request (#%d) with identical properties.", - "repo.pulls.status_checking": "Some checks are pending", + "repo.pulls.status_checking": "Some checks haven't completed yet", "repo.pulls.status_checks_success": "All checks were successful", "repo.pulls.status_checks_failure": "Some checks were not successful", "repo.pulls.status_checks_all_failed": "All checks have failed", "repo.pulls.status_checks_count_1": "%s check", "repo.pulls.status_checks_count_n": "%s checks", "repo.pulls.status_checks_failing": "%d failing", + "repo.pulls.status_checks_cancelled": "%d canceled", "repo.pulls.status_checks_pending": "%d pending", "repo.pulls.status_checks_in_progress": "%d in progress", "repo.pulls.status_checks_expected": "%d expected", diff --git a/routers/web/repo/pull_merge_box_devtest.go b/routers/web/repo/pull_merge_box_devtest.go index b34cbacfa02..390aa2e6322 100644 --- a/routers/web/repo/pull_merge_box_devtest.go +++ b/routers/web/repo/pull_merge_box_devtest.go @@ -26,8 +26,11 @@ func DevtestPullMergeBox(ctx *context.Context) { actionsStatuses := actions_module.CommitActionsStatusMap{} for i, cs := range statuses { cs.ID, cs.TargetURL = int64(i+1), "#" - if cs.Description == "Running" { + switch cs.Description { + case "Running": actionsStatuses[cs.ID] = actions_model.StatusRunning + case "Canceled after 1m": + actionsStatuses[cs.ID] = actions_model.StatusCancelled } } data := &pullCommitStatusCheckData{} @@ -94,6 +97,13 @@ func DevtestPullMergeBox(ctx *context.Context) { ) prInfo.MergeBoxData.hasOverridableBlockers = true }) + add("Checks canceled", func(prInfo *pullRequestViewInfo) { + prInfo.MergeBoxData.StatusCheckData = checks( + status("ci/test", commitstatus.CommitStatusFailure, "Canceled after 1m"), + status("ci/lint", commitstatus.CommitStatusSuccess, "Successful in 32s"), + ) + prInfo.MergeBoxData.hasOverridableBlockers = true + }) add("Changes requested, auto-merge enabled", func(prInfo *pullRequestViewInfo) { data := prInfo.MergeBoxData review(data, "octicon-file-diff", "tw-bg-red", "repo.issues.review.rejected", ctx.Locale.Tr("repo.pulls.blocked_by_rejection"), true) diff --git a/routers/web/repo/pull_status_checks.go b/routers/web/repo/pull_status_checks.go index 7ffb94f7b78..681ac585a4e 100644 --- a/routers/web/repo/pull_status_checks.go +++ b/routers/web/repo/pull_status_checks.go @@ -8,7 +8,6 @@ import ( "slices" "strings" - actions_model "gitea.dev/models/actions" git_model "gitea.dev/models/git" actions_module "gitea.dev/modules/actions" "gitea.dev/modules/base" @@ -20,6 +19,7 @@ type statusCheckKind struct{ KindName, countTrKey, strokeClass string } var ( statusCheckFailing = statusCheckKind{"failing", "repo.pulls.status_checks_failing", "tw-stroke-red"} + statusCheckCancelled = statusCheckKind{"cancelled", "repo.pulls.status_checks_cancelled", "tw-stroke-red"} statusCheckPending = statusCheckKind{"pending", "repo.pulls.status_checks_pending", "tw-stroke-yellow"} statusCheckInProgress = statusCheckKind{"in_progress", "repo.pulls.status_checks_in_progress", "tw-stroke-yellow"} statusCheckExpected = statusCheckKind{"expected", "repo.pulls.status_checks_expected", "tw-stroke-yellow"} @@ -27,7 +27,19 @@ var ( statusCheckSuccessful = statusCheckKind{"successful", "repo.pulls.status_checks_successful", "tw-stroke-green"} ) -var statusCheckKinds = []statusCheckKind{statusCheckFailing, statusCheckPending, statusCheckInProgress, statusCheckSkipped, statusCheckExpected, statusCheckSuccessful} +var statusCheckKinds = []statusCheckKind{statusCheckFailing, statusCheckCancelled, statusCheckPending, statusCheckInProgress, statusCheckSkipped, statusCheckExpected, statusCheckSuccessful} + +// listGroup is the group a kind's checks are listed in, GitHub lists cancelled checks with the failing ones +func (k statusCheckKind) listGroup() statusCheckKind { + switch k { + case statusCheckCancelled: + return statusCheckFailing + case statusCheckExpected: + return statusCheckPending + default: + return k + } +} type pullStatusCheck struct { StatusContext, StatusDescription, StatusTargetURL string @@ -48,25 +60,31 @@ func (g *statusCheckGroup) GroupTitle(locale translation.Locale) template.HTML { func (d *pullCommitStatusCheckData) groupStatuses(commitStatuses []*git_model.CommitStatus, requiredContexts []string, actionsStatuses actions_module.CommitActionsStatusMap, locale translation.Locale) { d.counts = map[statusCheckKind]int{} byKind := map[statusCheckKind][]*pullStatusCheck{} + add := func(kind statusCheckKind, check *pullStatusCheck) { + d.counts[kind]++ + byKind[kind.listGroup()] = append(byKind[kind.listGroup()], check) + } checks := make([]*pullStatusCheck, len(commitStatuses)) for i, cs := range commitStatuses { checks[i] = &pullStatusCheck{ StatusContext: cs.Context, StatusDescription: cs.Description, StatusTargetURL: cs.TargetURL, StatusState: cs.State, ActionStatus: actionsStatuses.IconStatus(cs), } + actionStatus := actionsStatuses[cs.ID] kind := statusCheckPending // unknown states count as pending, like in the combined status switch { + case actionStatus.IsCancelled() && cs.State.IsFailure(): + kind = statusCheckCancelled case cs.State.IsError() || cs.State.IsFailure() || cs.State.IsWarning(): kind = statusCheckFailing - case cs.State == commitstatus.CommitStatusRunning || actionsStatuses[cs.ID] == actions_model.StatusRunning && cs.State.IsPending(): + case cs.State == commitstatus.CommitStatusRunning || actionStatus.IsRunning() && cs.State.IsPending(): kind = statusCheckInProgress case cs.State.IsSuccess(): kind = statusCheckSuccessful case cs.State.IsSkipped(): kind = statusCheckSkipped } - d.counts[kind]++ - byKind[kind] = append(byKind[kind], checks[i]) + add(kind, checks[i]) } for _, requiredContext := range requiredContexts { matchesRequiredContext := createRequiredContextMatcher(requiredContext) @@ -78,8 +96,7 @@ func (d *pullCommitStatusCheckData) groupStatuses(commitStatuses []*git_model.Co } } if !contextFound { - d.counts[statusCheckExpected]++ - byKind[statusCheckPending] = append(byKind[statusCheckPending], &pullStatusCheck{ + add(statusCheckExpected, &pullStatusCheck{ StatusContext: requiredContext, StatusDescription: locale.TrString("repo.pulls.status_checks_waiting"), StatusState: commitstatus.CommitStatusPending, IsRequired: true, }) @@ -103,7 +120,7 @@ func (d *pullCommitStatusCheckData) count(kinds ...statusCheckKind) (count int) } func (d *pullCommitStatusCheckData) allFinishedSuccessfully() bool { - return d.count(statusCheckFailing, statusCheckPending, statusCheckInProgress, statusCheckExpected) == 0 + return d.count(statusCheckSuccessful, statusCheckSkipped) == d.count(statusCheckKinds...) } func (d *pullCommitStatusCheckData) AllPassed() bool { @@ -117,11 +134,12 @@ func (d *pullCommitStatusCheckData) StatusChecksSection(locale translation.Local parts = append(parts, string(locale.Tr(kind.countTrKey, count))) } } + total := d.count(statusCheckKinds...) section := &pullMergeBoxSection{ StatusIcon: "octicon-check", StatusIconClass: "tw-bg-green", SectionTitle: locale.Tr("repo.pulls.status_checks_success"), - SectionDetails: []template.HTML{locale.TrN(d.count(statusCheckKinds...), "repo.pulls.status_checks_count_1", "repo.pulls.status_checks_count_n", template.HTML(strings.Join(parts, ", ")))}, + SectionDetails: []template.HTML{locale.TrN(total, "repo.pulls.status_checks_count_1", "repo.pulls.status_checks_count_n", template.HTML(strings.Join(parts, ", ")))}, } - allFailed := d.RequireApprovalRunCount == 0 && len(d.StatusCheckGroups) == 1 && d.StatusCheckGroups[0].CheckKind == statusCheckFailing + allFailed := d.RequireApprovalRunCount == 0 && d.count(statusCheckFailing) == total switch { case d.RequireApprovalRunCount > 0: section.StatusIcon, section.StatusIconClass = "octicon-alert-fill", "tw-bg-grey-light" @@ -148,7 +166,7 @@ type statusCheckProgressSegment struct { func (d *pullCommitStatusCheckData) progressSegments() (segments []statusCheckProgressSegment) { const segmentGap = 5 total, start := float64(d.count(statusCheckKinds...)), segmentGap/2.0 - for _, kinds := range [][]statusCheckKind{{statusCheckSuccessful}, {statusCheckSkipped}, {statusCheckPending, statusCheckInProgress, statusCheckExpected}, {statusCheckFailing}} { + for _, kinds := range [][]statusCheckKind{{statusCheckSuccessful}, {statusCheckSkipped}, {statusCheckPending, statusCheckInProgress, statusCheckExpected}, {statusCheckFailing, statusCheckCancelled}} { count := d.count(kinds...) if count == 0 { continue diff --git a/routers/web/repo/pull_status_checks_test.go b/routers/web/repo/pull_status_checks_test.go index 08675ebaa15..998963e9072 100644 --- a/routers/web/repo/pull_status_checks_test.go +++ b/routers/web/repo/pull_status_checks_test.go @@ -25,7 +25,8 @@ func TestGroupStatusChecks(t *testing.T) { {ID: 6, Context: "docs", State: commitstatus.CommitStatusSkipped}, {ID: 7, Context: "CI10", State: commitstatus.CommitStatusPending}, {ID: 8, Context: "ci2", State: commitstatus.CommitStatusPending}, - }, []string{"[Cc][Ii]*", "missing", "missing*", "test"}, actions_module.CommitActionsStatusMap{3: actions_model.StatusRunning}, translation.MockLocale{}) + {ID: 9, Context: "e2e", State: commitstatus.CommitStatusFailure}, + }, []string{"[Cc][Ii]*", "missing", "missing*", "test"}, actions_module.CommitActionsStatusMap{3: actions_model.StatusRunning, 9: actions_model.StatusCancelled}, translation.MockLocale{}) require.Len(t, checkData.StatusCheckGroups, 5) assert.Equal(t, statusCheckPending, checkData.StatusCheckGroups[1].CheckKind) @@ -37,10 +38,11 @@ func TestGroupStatusChecks(t *testing.T) { StatusContext: "missing", StatusDescription: "repo.pulls.status_checks_waiting", StatusState: commitstatus.CommitStatusPending, IsRequired: true, }, checkData.StatusCheckGroups[1].StatusChecks[2]) - assert.False(t, checkData.StatusCheckGroups[0].StatusChecks[0].IsRequired) + assert.Equal(t, "cancelled", checkData.StatusCheckGroups[0].StatusChecks[0].ActionStatus) + assert.False(t, checkData.StatusCheckGroups[0].StatusChecks[1].IsRequired) assert.Equal(t, "running", checkData.StatusCheckGroups[2].StatusChecks[0].ActionStatus) assert.True(t, checkData.StatusCheckGroups[4].StatusChecks[0].IsRequired) - assert.EqualValues(t, "repo.pulls.status_checks_count_1:repo.pulls.status_checks_failing:1, repo.pulls.status_checks_pending:2, repo.pulls.status_checks_in_progress:1, repo.pulls.status_checks_skipped:1, repo.pulls.status_checks_expected:2, repo.pulls.status_checks_successful:1", checkData.StatusChecksSection(translation.MockLocale{}).SectionDetails[0]) + assert.EqualValues(t, "repo.pulls.status_checks_count_1:repo.pulls.status_checks_failing:1, repo.pulls.status_checks_cancelled:1, repo.pulls.status_checks_pending:2, repo.pulls.status_checks_in_progress:1, repo.pulls.status_checks_skipped:1, repo.pulls.status_checks_expected:2, repo.pulls.status_checks_successful:1", checkData.StatusChecksSection(translation.MockLocale{}).SectionDetails[0]) externalData := &pullCommitStatusCheckData{} externalData.groupStatuses([]*git_model.CommitStatus{ @@ -51,6 +53,13 @@ func TestGroupStatusChecks(t *testing.T) { assert.Equal(t, 1, externalData.count(statusCheckInProgress)) assert.Equal(t, 1, externalData.count(statusCheckPending)) + cancelledData := &pullCommitStatusCheckData{} + cancelledData.groupStatuses([]*git_model.CommitStatus{{ID: 1, Context: "lint", State: commitstatus.CommitStatusFailure}}, nil, actions_module.CommitActionsStatusMap{1: actions_model.StatusCancelled}, translation.MockLocale{}) + assert.False(t, cancelledData.AllPassed()) + cancelledSection := cancelledData.StatusChecksSection(translation.MockLocale{}) + assert.EqualValues(t, "repo.pulls.status_checking", cancelledSection.SectionTitle) + assert.Equal(t, []statusCheckProgressSegment{{StrokeClass: "tw-stroke-red", DashLength: 100}}, cancelledSection.ProgressSegments) + approvalData := &pullCommitStatusCheckData{RequireApprovalRunCount: 1} approvalData.groupStatuses([]*git_model.CommitStatus{{ID: 1, Context: "lint", State: commitstatus.CommitStatusSuccess}}, nil, nil, translation.MockLocale{}) assert.False(t, approvalData.AllPassed())