0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-20 10:28:36 +02:00

add headsha filter

This commit is contained in:
Christopher Homberger 2025-05-03 18:35:28 +02:00
parent 5be456b05b
commit 7c7bd1d586
3 changed files with 17 additions and 6 deletions

View File

@ -72,6 +72,7 @@ type FindRunOptions struct {
TriggerEvent webhook_module.HookEventType
Approved bool // not util.OptionalBool, it works only when it's true
Status []Status
CommitSHA string
}
func (opts FindRunOptions) ToConds() builder.Cond {
@ -97,6 +98,9 @@ func (opts FindRunOptions) ToConds() builder.Cond {
if opts.TriggerEvent != "" {
cond = cond.And(builder.Eq{"`action_run`.trigger_event": opts.TriggerEvent})
}
if opts.CommitSHA != "" {
cond = cond.And(builder.Eq{"`action_run`.commit_sha": opts.CommitSHA})
}
return cond
}

View File

@ -253,6 +253,9 @@ func ListRuns(ctx *context.APIContext, ownerID, repoID int64) {
}
opts.TriggerUserID = user.ID
}
if headSHA := ctx.Req.URL.Query().Get("head_sha"); headSHA != "" {
opts.CommitSHA = headSHA
}
runs, total, err := db.FindAndCount[actions_model.ActionRun](ctx, opts)
if err != nil {

View File

@ -46,11 +46,12 @@ func testAPIWorkflowRunBasic(t *testing.T, apiRootURL string, itemCount int, use
foundRun := false
for _, run := range runnerList.Entries {
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", run.Status, "", "", "")
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, run.Conclusion, "", "", "", "")
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", run.HeadBranch, "")
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", run.Event, "", "")
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", "", run.TriggerActor.UserName)
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", run.Status, "", "", "", "")
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, run.Conclusion, "", "", "", "", "")
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", run.HeadBranch, "", "")
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", run.Event, "", "", "")
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", "", run.TriggerActor.UserName, "")
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", "", run.TriggerActor.UserName, run.HeadSha)
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s", run.URL, "jobs")).AddTokenAuth(token)
jobsResp := MakeRequest(t, req, http.StatusOK)
@ -82,7 +83,7 @@ func testAPIWorkflowRunBasic(t *testing.T, apiRootURL string, itemCount int, use
assert.True(t, foundRun, "Expected to find run with ID %d", runID)
}
func verifyWorkflowRunCanbeFoundWithStatusFilter(t *testing.T, runAPIURL, token string, id int64, conclusion, status, event, branch, actor string) {
func verifyWorkflowRunCanbeFoundWithStatusFilter(t *testing.T, runAPIURL, token string, id int64, conclusion, status, event, branch, actor, headSHA string) {
filter := url.Values{}
if conclusion != "" {
filter.Add("status", conclusion)
@ -99,6 +100,9 @@ func verifyWorkflowRunCanbeFoundWithStatusFilter(t *testing.T, runAPIURL, token
if actor != "" {
filter.Set("actor", actor)
}
if headSHA != "" {
filter.Set("head_sha", headSHA)
}
req := NewRequest(t, "GET", runAPIURL+"?"+filter.Encode()).AddTokenAuth(token)
runResp := MakeRequest(t, req, http.StatusOK)
runList := api.ActionWorkflowRunsResponse{}