mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-23 10:44:37 +00:00
enhance(actions): create commit status for workflow_dispatch runs (#39961)
Runs triggered by `workflow_dispatch` never created a commit status, so the commit showed no sign that a workflow ran on it. - Post the status on the run's commit, e.g. `ci / e2e (workflow_dispatch)`. `schedule` runs stay unchanged. - These statuses don't count for pull requests. They don't show in a PR's checks and can't satisfy or fail its required checks, even through broad globs like `ci / e2e*`. Closes https://github.com/go-gitea/gitea/issues/39639 --------- Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
1 parent
4f69599981
commit
3aca9c8fb7
12 files changed
+48
-36
No files matched your search
@@ -9,12 +9,14 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
actions_model "gitea.dev/models/actions"
|
||||
"gitea.dev/models/db"
|
||||
git_model "gitea.dev/models/git"
|
||||
issues_model "gitea.dev/models/issues"
|
||||
repo_model "gitea.dev/models/repo"
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/commitstatus"
|
||||
"gitea.dev/modules/container"
|
||||
"gitea.dev/modules/git"
|
||||
@@ -139,9 +141,9 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullR
|
||||
return "", fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
|
||||
commitStatuses, err := git_model.GetLatestCommitStatus(ctx, pr.BaseRepo.ID, sha, db.ListOptionsAll)
|
||||
commitStatuses, err := GetLatestPullCommitStatuses(ctx, pr.BaseRepo.ID, sha)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("GetLatestCommitStatus: %w", err)
|
||||
return "", fmt.Errorf("GetLatestPullCommitStatuses: %w", err)
|
||||
}
|
||||
|
||||
pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pr.BaseRepoID, pr.BaseBranch)
|
||||
@@ -156,6 +158,14 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullR
|
||||
return MergeRequiredContextsCommitStatus(commitStatuses, requiredContexts), nil
|
||||
}
|
||||
|
||||
// GetLatestPullCommitStatuses returns a pull request head commit's latest statuses without workflow_dispatch runs', which don't count for pull requests
|
||||
func GetLatestPullCommitStatuses(ctx context.Context, repoID int64, sha string) ([]*git_model.CommitStatus, error) {
|
||||
statuses, err := git_model.GetLatestCommitStatus(ctx, repoID, sha, db.ListOptionsAll)
|
||||
return slices.DeleteFunc(statuses, func(status *git_model.CommitStatus) bool {
|
||||
return status.CreatorID == user_model.ActionsUserID && strings.HasSuffix(status.Context, " (workflow_dispatch)")
|
||||
}), err
|
||||
}
|
||||
|
||||
// EffectiveRequiredContexts returns the required status-check contexts to enforce, drawn from:
|
||||
// 1. every required scoped workflow's status-check patterns effective for the repo (always)
|
||||
// 2. each given protected branch rule's own configured contexts, only when that rule's status check is enabled
|
||||
|
||||
Reference in new issue
Block a user