Skip to content

Commit 7c7bd1d

Browse files
committed
add headsha filter
1 parent 5be456b commit 7c7bd1d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

models/actions/run_list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type FindRunOptions struct {
7272
TriggerEvent webhook_module.HookEventType
7373
Approved bool // not util.OptionalBool, it works only when it's true
7474
Status []Status
75+
CommitSHA string
7576
}
7677

7778
func (opts FindRunOptions) ToConds() builder.Cond {
@@ -97,6 +98,9 @@ func (opts FindRunOptions) ToConds() builder.Cond {
9798
if opts.TriggerEvent != "" {
9899
cond = cond.And(builder.Eq{"`action_run`.trigger_event": opts.TriggerEvent})
99100
}
101+
if opts.CommitSHA != "" {
102+
cond = cond.And(builder.Eq{"`action_run`.commit_sha": opts.CommitSHA})
103+
}
100104
return cond
101105
}
102106

routers/api/v1/shared/runners.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ func ListRuns(ctx *context.APIContext, ownerID, repoID int64) {
253253
}
254254
opts.TriggerUserID = user.ID
255255
}
256+
if headSHA := ctx.Req.URL.Query().Get("head_sha"); headSHA != "" {
257+
opts.CommitSHA = headSHA
258+
}
256259

257260
runs, total, err := db.FindAndCount[actions_model.ActionRun](ctx, opts)
258261
if err != nil {

tests/integration/workflow_run_api_check_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ func testAPIWorkflowRunBasic(t *testing.T, apiRootURL string, itemCount int, use
4646
foundRun := false
4747

4848
for _, run := range runnerList.Entries {
49-
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", run.Status, "", "", "")
50-
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, run.Conclusion, "", "", "", "")
51-
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", run.HeadBranch, "")
52-
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", run.Event, "", "")
53-
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", "", run.TriggerActor.UserName)
49+
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", run.Status, "", "", "", "")
50+
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, run.Conclusion, "", "", "", "", "")
51+
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", run.HeadBranch, "", "")
52+
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", run.Event, "", "", "")
53+
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", "", run.TriggerActor.UserName, "")
54+
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", "", run.TriggerActor.UserName, run.HeadSha)
5455

5556
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s", run.URL, "jobs")).AddTokenAuth(token)
5657
jobsResp := MakeRequest(t, req, http.StatusOK)
@@ -82,7 +83,7 @@ func testAPIWorkflowRunBasic(t *testing.T, apiRootURL string, itemCount int, use
8283
assert.True(t, foundRun, "Expected to find run with ID %d", runID)
8384
}
8485

85-
func verifyWorkflowRunCanbeFoundWithStatusFilter(t *testing.T, runAPIURL, token string, id int64, conclusion, status, event, branch, actor string) {
86+
func verifyWorkflowRunCanbeFoundWithStatusFilter(t *testing.T, runAPIURL, token string, id int64, conclusion, status, event, branch, actor, headSHA string) {
8687
filter := url.Values{}
8788
if conclusion != "" {
8889
filter.Add("status", conclusion)
@@ -99,6 +100,9 @@ func verifyWorkflowRunCanbeFoundWithStatusFilter(t *testing.T, runAPIURL, token
99100
if actor != "" {
100101
filter.Set("actor", actor)
101102
}
103+
if headSHA != "" {
104+
filter.Set("head_sha", headSHA)
105+
}
102106
req := NewRequest(t, "GET", runAPIURL+"?"+filter.Encode()).AddTokenAuth(token)
103107
runResp := MakeRequest(t, req, http.StatusOK)
104108
runList := api.ActionWorkflowRunsResponse{}

0 commit comments

Comments
 (0)