From 8e9fb4d14c26e0cc72258a51e4dd312913093523 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Thu, 15 Jan 2026 09:25:14 +1100 Subject: [PATCH] Indicate when only optional checks failed (#36367) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently it's not clear that you can merge a PR when only optional checks failed: Screenshot 2026-01-14 at 4 08 17 pm This PR changes the text to say "Some optional checks failed" when only optional checks failed: Screenshot 2026-01-14 at 3 59 08 pm When a required check fails it'll still say "Some checks failed": Screenshot 2026-01-14 at 3 59 20 pm --------- Co-authored-by: wxiaoguang --- options/locale/locale_en-US.json | 3 +- routers/web/repo/pull.go | 36 +++++++++++++++---- .../issue/view_content/pull_merge_box.tmpl | 16 +++++---- templates/repo/pulls/status.tmpl | 14 +------- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index 1dbb0975a3..96a541a947 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -1847,7 +1847,8 @@ "repo.pulls.status_checking": "Some checks are pending", "repo.pulls.status_checks_success": "All checks were successful", "repo.pulls.status_checks_warning": "Some checks reported warnings", - "repo.pulls.status_checks_failure": "Some checks failed", + "repo.pulls.status_checks_failure_required": "Some required checks failed", + "repo.pulls.status_checks_failure_optional": "Some optional checks failed", "repo.pulls.status_checks_error": "Some checks reported errors", "repo.pulls.status_checks_requested": "Required", "repo.pulls.status_checks_details": "Details", diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 60f0ee6db8..627fe93b77 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -23,6 +23,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/commitstatus" "code.gitea.io/gitea/modules/emoji" "code.gitea.io/gitea/modules/fileicon" "code.gitea.io/gitea/modules/git" @@ -35,6 +36,7 @@ import ( "code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" + "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/utils" @@ -320,6 +322,26 @@ type pullCommitStatusCheckData struct { RequireApprovalRunCount int // number of workflow runs that require approval CanApprove bool // whether the user can approve workflow runs ApproveLink string // link to approve all checks + RequiredChecksState commitstatus.CommitStatusState + LatestCommitStatus *git_model.CommitStatus +} + +func (d *pullCommitStatusCheckData) CommitStatusCheckPrompt(locale translation.Locale) string { + if d.RequiredChecksState.IsPending() || len(d.MissingRequiredChecks) > 0 { + return locale.TrString("repo.pulls.status_checking") + } else if d.RequiredChecksState.IsSuccess() { + if d.LatestCommitStatus != nil && d.LatestCommitStatus.State.IsFailure() { + return locale.TrString("repo.pulls.status_checks_failure_optional") + } + return locale.TrString("repo.pulls.status_checks_success") + } else if d.RequiredChecksState.IsWarning() { + return locale.TrString("repo.pulls.status_checks_warning") + } else if d.RequiredChecksState.IsFailure() { + return locale.TrString("repo.pulls.status_checks_failure_required") + } else if d.RequiredChecksState.IsError() { + return locale.TrString("repo.pulls.status_checks_error") + } + return locale.TrString("repo.pulls.status_checking") } // prepareViewPullInfo show meta information for a pull request preview page @@ -360,6 +382,8 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git_s defer baseGitRepo.Close() } + statusCheckData := &pullCommitStatusCheckData{} + if exist, _ := git_model.IsBranchExist(ctx, pull.BaseRepo.ID, pull.BaseBranch); !exist { ctx.Data["BaseBranchNotExist"] = true ctx.Data["IsPullRequestBroken"] = true @@ -380,9 +404,10 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git_s git_model.CommitStatusesHideActionsURL(ctx, commitStatuses) } + statusCheckData.LatestCommitStatus = git_model.CalcCommitStatus(commitStatuses) if len(commitStatuses) > 0 { ctx.Data["LatestCommitStatuses"] = commitStatuses - ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(commitStatuses) + ctx.Data["LatestCommitStatus"] = statusCheckData.LatestCommitStatus } compareInfo, err := git_service.GetCompareInfo(ctx, pull.BaseRepo, pull.BaseRepo, baseGitRepo, @@ -467,10 +492,8 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git_s return nil } - statusCheckData := &pullCommitStatusCheckData{ - ApproveLink: fmt.Sprintf("%s/actions/approve-all-checks?commit_id=%s", repo.Link(), sha), - } ctx.Data["StatusCheckData"] = statusCheckData + statusCheckData.ApproveLink = fmt.Sprintf("%s/actions/approve-all-checks?commit_id=%s", repo.Link(), sha) commitStatuses, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptionsAll) if err != nil { @@ -495,9 +518,10 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git_s statusCheckData.CanApprove = ctx.Repo.CanWrite(unit.TypeActions) } + statusCheckData.LatestCommitStatus = git_model.CalcCommitStatus(commitStatuses) if len(commitStatuses) > 0 { ctx.Data["LatestCommitStatuses"] = commitStatuses - ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(commitStatuses) + ctx.Data["LatestCommitStatus"] = statusCheckData.LatestCommitStatus } if pb != nil && pb.EnableStatusCheck { @@ -534,7 +558,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git_s } return false } - ctx.Data["RequiredStatusCheckState"] = pull_service.MergeRequiredContextsCommitStatus(commitStatuses, pb.StatusCheckContexts) + statusCheckData.RequiredChecksState = pull_service.MergeRequiredContextsCommitStatus(commitStatuses, pb.StatusCheckContexts) } ctx.Data["HeadBranchMovedOn"] = headBranchSha != sha diff --git a/templates/repo/issue/view_content/pull_merge_box.tmpl b/templates/repo/issue/view_content/pull_merge_box.tmpl index 5e89ef5e69..d47d426dfa 100644 --- a/templates/repo/issue/view_content/pull_merge_box.tmpl +++ b/templates/repo/issue/view_content/pull_merge_box.tmpl @@ -8,6 +8,8 @@ data-pull-link="{{.Issue.Link}}" {{end}} > + {{$statusCheckData := .StatusCheckData}} + {{$requiredStatusCheckState := $statusCheckData.RequiredChecksState}}
{{end}} @@ -145,12 +147,12 @@
  • {{.}}
  • {{end}} - {{else if and .EnableStatusCheck (or .RequiredStatusCheckState.IsError .RequiredStatusCheckState.IsFailure)}} + {{else if and .EnableStatusCheck (or $requiredStatusCheckState.IsError $requiredStatusCheckState.IsFailure)}}
    {{svg "octicon-x"}} {{ctx.Locale.Tr "repo.pulls.required_status_check_failed"}}
    - {{else if and .EnableStatusCheck (not .RequiredStatusCheckState.IsSuccess)}} + {{else if and .EnableStatusCheck (not $requiredStatusCheckState.IsSuccess)}}
    {{svg "octicon-x"}} {{ctx.Locale.Tr "repo.pulls.required_status_check_missing"}} @@ -166,7 +168,7 @@
    {{end}} - {{$notAllOverridableChecksOk := or .IsBlockedByApprovals .IsBlockedByRejection .IsBlockedByOfficialReviewRequests .IsBlockedByOutdatedBranch .IsBlockedByChangedProtectedFiles (and .EnableStatusCheck (not .RequiredStatusCheckState.IsSuccess))}} + {{$notAllOverridableChecksOk := or .IsBlockedByApprovals .IsBlockedByRejection .IsBlockedByOfficialReviewRequests .IsBlockedByOutdatedBranch .IsBlockedByChangedProtectedFiles (and .EnableStatusCheck (not $requiredStatusCheckState.IsSuccess))}} {{/* admin can merge without checks, writer can merge when checks succeed */}} {{$canMergeNow := and (or (and (not $.ProtectedBranch.BlockAdminMergeOverride) $.IsRepoAdmin) (not $notAllOverridableChecksOk)) (or (not .AllowMerge) (not .RequireSigned) .WillSign)}} @@ -351,7 +353,7 @@
  • {{.}}
  • {{end}} - {{else if and .EnableStatusCheck (not .RequiredStatusCheckState.IsSuccess)}} + {{else if and .EnableStatusCheck (not $requiredStatusCheckState.IsSuccess)}}
    {{svg "octicon-x"}} {{ctx.Locale.Tr "repo.pulls.required_status_check_failed"}} diff --git a/templates/repo/pulls/status.tmpl b/templates/repo/pulls/status.tmpl index f3c1973c2b..7962b2ffbf 100644 --- a/templates/repo/pulls/status.tmpl +++ b/templates/repo/pulls/status.tmpl @@ -8,19 +8,7 @@ {{if .CommitStatus}}
    - {{if or (eq .CommitStatus.State "pending") (.MissingRequiredChecks)}} - {{ctx.Locale.Tr "repo.pulls.status_checking"}} - {{else if eq .CommitStatus.State "success"}} - {{ctx.Locale.Tr "repo.pulls.status_checks_success"}} - {{else if eq .CommitStatus.State "warning"}} - {{ctx.Locale.Tr "repo.pulls.status_checks_warning"}} - {{else if eq .CommitStatus.State "failure"}} - {{ctx.Locale.Tr "repo.pulls.status_checks_failure"}} - {{else if eq .CommitStatus.State "error"}} - {{ctx.Locale.Tr "repo.pulls.status_checks_error"}} - {{else}} - {{ctx.Locale.Tr "repo.pulls.status_checking"}} - {{end}} + {{$statusCheckData.CommitStatusCheckPrompt ctx.Locale}} {{if .ShowHideChecks}}