Skip to content

Commit 5be456b

Browse files
committed
add actor and triggerActor
1 parent 48379a2 commit 5be456b

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

modules/structs/repo_actions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ type ActionWorkflowRun struct {
9898
HeadSha string `json:"head_sha"`
9999
HeadBranch string `json:"head_branch,omitempty"`
100100
Status string `json:"status"`
101+
Actor *User `json:"actor,omitempty"`
102+
TriggerActor *User `json:"trigger_actor,omitempty"`
101103
Repository *Repository `json:"repository,omitempty"`
102104
HeadRepository *Repository `json:"head_repository,omitempty"`
103105
Conclusion string `json:"conclusion,omitempty"`

routers/api/v1/shared/runners.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func ListJobs(ctx *context.APIContext, ownerID, repoID, runID int64) {
167167
if isRepoLevel {
168168
repository = ctx.Repo.Repository
169169
} else {
170-
repository, err = repo_model.GetRepositoryByID(ctx, repoID)
170+
repository, err = repo_model.GetRepositoryByID(ctx, jobs[i].RepoID)
171171
if err != nil {
172172
ctx.APIErrorInternal(err)
173173
return

services/convert/convert.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func ToActionTask(ctx context.Context, t *actions_model.ActionTask) (*api.Action
248248
}
249249

250250
func ToActionWorkflowRun(ctx context.Context, repo *repo_model.Repository, run *actions_model.ActionRun) (*api.ActionWorkflowRun, error) {
251-
err := run.LoadRepo(ctx)
251+
err := run.LoadAttributes(ctx)
252252
if err != nil {
253253
return nil, err
254254
}
@@ -268,6 +268,9 @@ func ToActionWorkflowRun(ctx context.Context, repo *repo_model.Repository, run *
268268
Conclusion: conclusion,
269269
Path: fmt.Sprintf("%s@%s", run.WorkflowID, run.Ref),
270270
Repository: ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeNone}),
271+
TriggerActor: ToUser(ctx, run.TriggerUser, nil),
272+
// We do not have a way to get a different User for the actor than the trigger user
273+
Actor: ToUser(ctx, run.TriggerUser, nil),
271274
}, nil
272275
}
273276

tests/integration/workflow_run_api_check_test.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,25 @@ import (
1818

1919
func TestAPIWorkflowRun(t *testing.T) {
2020
t.Run("AdminRunner", func(t *testing.T) {
21-
testAPIWorkflowRunBasic(t, "/api/v1/admin/actions/runs", 6, "User1", 802, auth_model.AccessTokenScopeReadAdmin, auth_model.AccessTokenScopeReadRepository)
21+
testAPIWorkflowRunBasic(t, "/api/v1/admin/actions", 6, "User1", 802, auth_model.AccessTokenScopeReadAdmin, auth_model.AccessTokenScopeReadRepository)
2222
})
2323
t.Run("UserRunner", func(t *testing.T) {
24-
testAPIWorkflowRunBasic(t, "/api/v1/user/actions/runs", 1, "User2", 803, auth_model.AccessTokenScopeReadUser, auth_model.AccessTokenScopeReadRepository)
24+
testAPIWorkflowRunBasic(t, "/api/v1/user/actions", 1, "User2", 803, auth_model.AccessTokenScopeReadUser, auth_model.AccessTokenScopeReadRepository)
2525
})
2626
t.Run("OrgRuns", func(t *testing.T) {
27-
testAPIWorkflowRunBasic(t, "/api/v1/orgs/org3/actions/runs", 1, "User1", 802, auth_model.AccessTokenScopeReadOrganization, auth_model.AccessTokenScopeReadRepository)
27+
testAPIWorkflowRunBasic(t, "/api/v1/orgs/org3/actions", 1, "User1", 802, auth_model.AccessTokenScopeReadOrganization, auth_model.AccessTokenScopeReadRepository)
2828
})
2929
t.Run("RepoRuns", func(t *testing.T) {
30-
testAPIWorkflowRunBasic(t, "/api/v1/repos/org3/repo5/actions/runs", 1, "User2", 802, auth_model.AccessTokenScopeReadRepository)
30+
testAPIWorkflowRunBasic(t, "/api/v1/repos/org3/repo5/actions", 1, "User2", 802, auth_model.AccessTokenScopeReadRepository)
3131
})
3232
}
3333

34-
func testAPIWorkflowRunBasic(t *testing.T, runAPIURL string, itemCount int, userUsername string, runID int64, scope ...auth_model.AccessTokenScope) {
34+
func testAPIWorkflowRunBasic(t *testing.T, apiRootURL string, itemCount int, userUsername string, runID int64, scope ...auth_model.AccessTokenScope) {
3535
defer tests.PrepareTestEnv(t)()
3636
token := getUserToken(t, userUsername, scope...)
3737

38-
req := NewRequest(t, "GET", runAPIURL).AddTokenAuth(token)
38+
apiRunsURL := fmt.Sprintf("%s/%s", apiRootURL, "runs")
39+
req := NewRequest(t, "GET", apiRunsURL).AddTokenAuth(token)
3940
runnerListResp := MakeRequest(t, req, http.StatusOK)
4041
runnerList := api.ActionWorkflowRunsResponse{}
4142
DecodeJSON(t, runnerListResp, &runnerList)
@@ -45,10 +46,11 @@ func testAPIWorkflowRunBasic(t *testing.T, runAPIURL string, itemCount int, user
4546
foundRun := false
4647

4748
for _, run := range runnerList.Entries {
48-
verifyWorkflowRunCanbeFoundWithStatusFilter(t, runAPIURL, token, run.ID, "", run.Status, "", "")
49-
verifyWorkflowRunCanbeFoundWithStatusFilter(t, runAPIURL, token, run.ID, run.Conclusion, "", "", "")
50-
verifyWorkflowRunCanbeFoundWithStatusFilter(t, runAPIURL, token, run.ID, "", "", "", run.HeadBranch)
51-
verifyWorkflowRunCanbeFoundWithStatusFilter(t, runAPIURL, token, run.ID, "", "", run.Event, "")
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)
5254

5355
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s", run.URL, "jobs")).AddTokenAuth(token)
5456
jobsResp := MakeRequest(t, req, http.StatusOK)
@@ -59,8 +61,12 @@ func testAPIWorkflowRunBasic(t *testing.T, runAPIURL string, itemCount int, user
5961
foundRun = true
6062
assert.Len(t, jobList.Entries, 1)
6163
for _, job := range jobList.Entries {
64+
// Check the jobs list of the run
6265
verifyWorkflowJobCanbeFoundWithStatusFilter(t, fmt.Sprintf("%s/%s", run.URL, "jobs"), token, job.ID, "", job.Status)
6366
verifyWorkflowJobCanbeFoundWithStatusFilter(t, fmt.Sprintf("%s/%s", run.URL, "jobs"), token, job.ID, job.Conclusion, "")
67+
// Check the run independent job list
68+
verifyWorkflowJobCanbeFoundWithStatusFilter(t, fmt.Sprintf("%s/%s", apiRootURL, "jobs"), token, job.ID, "", job.Status)
69+
verifyWorkflowJobCanbeFoundWithStatusFilter(t, fmt.Sprintf("%s/%s", apiRootURL, "jobs"), token, job.ID, job.Conclusion, "")
6470

6571
req := NewRequest(t, "GET", job.URL).AddTokenAuth(token)
6672
jobsResp := MakeRequest(t, req, http.StatusOK)
@@ -76,7 +82,7 @@ func testAPIWorkflowRunBasic(t *testing.T, runAPIURL string, itemCount int, user
7682
assert.True(t, foundRun, "Expected to find run with ID %d", runID)
7783
}
7884

79-
func verifyWorkflowRunCanbeFoundWithStatusFilter(t *testing.T, runAPIURL, token string, id int64, conclusion, status, event, branch string) {
85+
func verifyWorkflowRunCanbeFoundWithStatusFilter(t *testing.T, runAPIURL, token string, id int64, conclusion, status, event, branch, actor string) {
8086
filter := url.Values{}
8187
if conclusion != "" {
8288
filter.Add("status", conclusion)
@@ -90,6 +96,9 @@ func verifyWorkflowRunCanbeFoundWithStatusFilter(t *testing.T, runAPIURL, token
9096
if branch != "" {
9197
filter.Set("branch", branch)
9298
}
99+
if actor != "" {
100+
filter.Set("actor", actor)
101+
}
93102
req := NewRequest(t, "GET", runAPIURL+"?"+filter.Encode()).AddTokenAuth(token)
94103
runResp := MakeRequest(t, req, http.StatusOK)
95104
runList := api.ActionWorkflowRunsResponse{}
@@ -109,6 +118,9 @@ func verifyWorkflowRunCanbeFoundWithStatusFilter(t *testing.T, runAPIURL, token
109118
if branch != "" {
110119
assert.Equal(t, branch, run.HeadBranch)
111120
}
121+
if actor != "" {
122+
assert.Equal(t, actor, run.Actor.UserName)
123+
}
112124
found = found || run.ID == id
113125
}
114126
assert.True(t, found, "Expected to find run with ID %d", id)

0 commit comments

Comments
 (0)