mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 14:34:43 +02:00
add headsha filter
This commit is contained in:
parent
5be456b05b
commit
7c7bd1d586
@ -72,6 +72,7 @@ type FindRunOptions struct {
|
|||||||
TriggerEvent webhook_module.HookEventType
|
TriggerEvent webhook_module.HookEventType
|
||||||
Approved bool // not util.OptionalBool, it works only when it's true
|
Approved bool // not util.OptionalBool, it works only when it's true
|
||||||
Status []Status
|
Status []Status
|
||||||
|
CommitSHA string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts FindRunOptions) ToConds() builder.Cond {
|
func (opts FindRunOptions) ToConds() builder.Cond {
|
||||||
@ -97,6 +98,9 @@ func (opts FindRunOptions) ToConds() builder.Cond {
|
|||||||
if opts.TriggerEvent != "" {
|
if opts.TriggerEvent != "" {
|
||||||
cond = cond.And(builder.Eq{"`action_run`.trigger_event": 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
|
return cond
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,6 +253,9 @@ func ListRuns(ctx *context.APIContext, ownerID, repoID int64) {
|
|||||||
}
|
}
|
||||||
opts.TriggerUserID = user.ID
|
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)
|
runs, total, err := db.FindAndCount[actions_model.ActionRun](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -46,11 +46,12 @@ func testAPIWorkflowRunBasic(t *testing.T, apiRootURL string, itemCount int, use
|
|||||||
foundRun := false
|
foundRun := false
|
||||||
|
|
||||||
for _, run := range runnerList.Entries {
|
for _, run := range runnerList.Entries {
|
||||||
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", run.Status, "", "", "")
|
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", run.Status, "", "", "", "")
|
||||||
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, run.Conclusion, "", "", "", "")
|
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, run.Conclusion, "", "", "", "", "")
|
||||||
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", run.HeadBranch, "")
|
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", run.HeadBranch, "", "")
|
||||||
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", run.Event, "", "")
|
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, "")
|
||||||
|
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", "", "", "", run.TriggerActor.UserName, run.HeadSha)
|
||||||
|
|
||||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s", run.URL, "jobs")).AddTokenAuth(token)
|
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s", run.URL, "jobs")).AddTokenAuth(token)
|
||||||
jobsResp := MakeRequest(t, req, http.StatusOK)
|
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)
|
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{}
|
filter := url.Values{}
|
||||||
if conclusion != "" {
|
if conclusion != "" {
|
||||||
filter.Add("status", conclusion)
|
filter.Add("status", conclusion)
|
||||||
@ -99,6 +100,9 @@ func verifyWorkflowRunCanbeFoundWithStatusFilter(t *testing.T, runAPIURL, token
|
|||||||
if actor != "" {
|
if actor != "" {
|
||||||
filter.Set("actor", actor)
|
filter.Set("actor", actor)
|
||||||
}
|
}
|
||||||
|
if headSHA != "" {
|
||||||
|
filter.Set("head_sha", headSHA)
|
||||||
|
}
|
||||||
req := NewRequest(t, "GET", runAPIURL+"?"+filter.Encode()).AddTokenAuth(token)
|
req := NewRequest(t, "GET", runAPIURL+"?"+filter.Encode()).AddTokenAuth(token)
|
||||||
runResp := MakeRequest(t, req, http.StatusOK)
|
runResp := MakeRequest(t, req, http.StatusOK)
|
||||||
runList := api.ActionWorkflowRunsResponse{}
|
runList := api.ActionWorkflowRunsResponse{}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user