WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 762eca3

Browse files
committed
feat: add Actions API endpoints for workflow run and job management
- Add API endpoints for managing workflow runs (rerun, cancel, approve) - Add API endpoints for managing workflow jobs (rerun, logs) - Add streaming logs endpoint with step-level support - Update test fixtures and regenerate Swagger - Move shared logic to services for reuse
1 parent 3ab8ae5 commit 762eca3

File tree

15 files changed

+1588
-102
lines changed

15 files changed

+1588
-102
lines changed

models/fixtures/repo_unit.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,3 @@
733733
type: 3
734734
config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}"
735735
created_unix: 946684810
736-
737-
-
738-
id: 111
739-
repo_id: 3
740-
type: 10
741-
config: "{}"
742-
created_unix: 946684810

models/perm/access/access.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ func refreshAccesses(ctx context.Context, repo *repo_model.Repository, accessMap
105105
}
106106

107107
newAccesses := make([]Access, 0, len(accessMap))
108+
keysToDelete := []int64{}
108109
for userID, ua := range accessMap {
109110
if ua.Mode < minMode && !ua.User.IsRestricted {
111+
keysToDelete = append(keysToDelete, userID)
110112
continue
111113
}
112114

@@ -116,6 +118,9 @@ func refreshAccesses(ctx context.Context, repo *repo_model.Repository, accessMap
116118
Mode: ua.Mode,
117119
})
118120
}
121+
for _, uid := range keysToDelete {
122+
delete(accessMap, uid)
123+
}
119124

120125
// Delete old accesses and insert new ones for repository.
121126
if _, err = db.DeleteByBean(ctx, &Access{RepoID: repo.ID}); err != nil {

modules/git/notes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ func TestGetNonExistentNotes(t *testing.T) {
4747
note := Note{}
4848
err = GetNote(t.Context(), bareRepo1, "non_existent_sha", &note)
4949
assert.Error(t, err)
50-
assert.ErrorAs(t, err, &ErrNotExist{})
50+
assert.IsType(t, ErrNotExist{}, err)
5151
}

modules/setting/indexer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func checkGlobMatch(t *testing.T, globstr string, list []indexerMatchList) {
6565
}
6666
}
6767
if !found {
68-
assert.Equal(t, -1, m.position, "Test string `%s` doesn't match `%s` anywhere; expected @%d", m.value, globstr, m.position)
68+
assert.Equal(t, m.position, -1, "Test string `%s` doesn't match `%s` anywhere; expected @%d", m.value, globstr, m.position)
6969
}
7070
}
7171
}

modules/structs/repo_actions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ type ActionWorkflowRun struct {
123123
HeadRepository *Repository `json:"head_repository,omitempty"`
124124
Conclusion string `json:"conclusion,omitempty"`
125125
// swagger:strfmt date-time
126+
CreatedAt time.Time `json:"created_at"`
127+
// swagger:strfmt date-time
126128
StartedAt time.Time `json:"started_at"`
127129
// swagger:strfmt date-time
128130
CompletedAt time.Time `json:"completed_at"`

routers/api/v1/api.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,17 @@ func Routes() *web.Router {
12721272
m.Group("/{run}", func() {
12731273
m.Get("", repo.GetWorkflowRun)
12741274
m.Delete("", reqToken(), reqRepoWriter(unit.TypeActions), repo.DeleteActionRun)
1275-
m.Get("/jobs", repo.ListWorkflowRunJobs)
1275+
m.Post("/rerun", reqToken(), reqRepoWriter(unit.TypeActions), repo.RerunWorkflowRun)
1276+
m.Post("/cancel", reqToken(), reqRepoWriter(unit.TypeActions), repo.CancelWorkflowRun)
1277+
m.Post("/approve", reqToken(), reqRepoWriter(unit.TypeActions), repo.ApproveWorkflowRun)
1278+
m.Group("/jobs", func() {
1279+
m.Get("", repo.ListWorkflowRunJobs)
1280+
m.Post("/{job_id}/rerun", reqToken(), reqRepoWriter(unit.TypeActions), repo.RerunWorkflowJob)
1281+
})
1282+
m.Group("/logs", func() {
1283+
m.Get("", repo.GetWorkflowRunLogs)
1284+
m.Post("", reqToken(), reqRepoReader(unit.TypeActions), repo.GetWorkflowRunLogsStream)
1285+
})
12761286
m.Get("/artifacts", repo.GetArtifactsOfRun)
12771287
})
12781288
})

0 commit comments

Comments
 (0)