loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(api): return `run_number` in workflow dispatch (#7286)

- This is a follow up on #7193 and resolves #6312.
- The ID by itself is not very useful, so also return the index of the workflow run.

Co-authored-by: Klaus Fyhn <klausfyhn@gmail.com>
Co-authored-by: Klaus Fyhn <klfj@mir-robots.com>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7286
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: klausfyhn <klausfyhn@noreply.codeberg.org>
Co-committed-by: klausfyhn <klausfyhn@noreply.codeberg.org>

authored by

klausfyhn
Klaus Fyhn
Klaus Fyhn
klausfyhn
and committed by
Gusted
c531b8f0 513319c1

+76 -2
+2
modules/structs/workflow.go
··· 22 22 type DispatchWorkflowRun struct { 23 23 // the workflow run id 24 24 ID int64 `json:"id"` 25 + // a unique number for each run of a repository 26 + RunNumber int64 `json:"run_number"` 25 27 // the jobs name 26 28 Jobs []string `json:"jobs"` 27 29 }
+5 -2
routers/api/v1/repo/action.go
··· 640 640 // schema: 641 641 // "$ref": "#/definitions/DispatchWorkflowOption" 642 642 // responses: 643 + // "201": 644 + // "$ref": "#/responses/DispatchWorkflowRun" 643 645 // "204": 644 646 // "$ref": "#/responses/empty" 645 647 // "404": ··· 681 683 } 682 684 683 685 workflowRun := &api.DispatchWorkflowRun{ 684 - ID: run.ID, 685 - Jobs: jobs, 686 + ID: run.ID, 687 + RunNumber: run.Index, 688 + Jobs: jobs, 686 689 } 687 690 688 691 if opt.ReturnRunInfo {
+9
templates/swagger/v1_json.tmpl
··· 5414 5414 } 5415 5415 ], 5416 5416 "responses": { 5417 + "201": { 5418 + "$ref": "#/responses/DispatchWorkflowRun" 5419 + }, 5417 5420 "204": { 5418 5421 "$ref": "#/responses/empty" 5419 5422 }, ··· 23193 23196 "type": "string" 23194 23197 }, 23195 23198 "x-go-name": "Jobs" 23199 + }, 23200 + "run_number": { 23201 + "description": "a unique number for each run of a repository", 23202 + "type": "integer", 23203 + "format": "int64", 23204 + "x-go-name": "RunNumber" 23196 23205 } 23197 23206 }, 23198 23207 "x-go-package": "code.gitea.io/gitea/modules/structs"
+60
tests/integration/api_repo_actions_test.go
··· 4 4 package integration 5 5 6 6 import ( 7 + "fmt" 7 8 "net/http" 9 + "net/url" 10 + "strings" 8 11 "testing" 9 12 10 13 actions_model "code.gitea.io/gitea/models/actions" 11 14 auth_model "code.gitea.io/gitea/models/auth" 12 15 repo_model "code.gitea.io/gitea/models/repo" 16 + unit_model "code.gitea.io/gitea/models/unit" 13 17 "code.gitea.io/gitea/models/unittest" 14 18 user_model "code.gitea.io/gitea/models/user" 15 19 api "code.gitea.io/gitea/modules/structs" 20 + files_service "code.gitea.io/gitea/services/repository/files" 16 21 "code.gitea.io/gitea/tests" 17 22 18 23 "github.com/stretchr/testify/assert" ··· 41 46 assert.Len(t, jobs, 1) 42 47 assert.EqualValues(t, job.ID, jobs[0].ID) 43 48 } 49 + 50 + func TestAPIWorkflowDispatchReturnInfo(t *testing.T) { 51 + onGiteaRun(t, func(t *testing.T, u *url.URL) { 52 + workflowName := "dispatch.yml" 53 + user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 54 + token := getUserToken(t, user2.LowerName, auth_model.AccessTokenScopeWriteRepository) 55 + 56 + // create the repo 57 + repo, _, f := tests.CreateDeclarativeRepo(t, user2, "api-repo-workflow-dispatch", 58 + []unit_model.Type{unit_model.TypeActions}, nil, 59 + []*files_service.ChangeRepoFile{ 60 + { 61 + Operation: "create", 62 + TreePath: fmt.Sprintf(".forgejo/workflows/%s", workflowName), 63 + ContentReader: strings.NewReader(`name: WD 64 + on: [workflow-dispatch] 65 + jobs: 66 + t1: 67 + runs-on: docker 68 + steps: 69 + - run: echo "test 1" 70 + t2: 71 + runs-on: docker 72 + steps: 73 + - run: echo "test 2" 74 + `, 75 + ), 76 + }, 77 + }, 78 + ) 79 + defer f() 80 + 81 + req := NewRequestWithJSON( 82 + t, 83 + http.MethodPost, 84 + fmt.Sprintf( 85 + "/api/v1/repos/%s/%s/actions/workflows/%s/dispatches", 86 + repo.OwnerName, repo.Name, workflowName, 87 + ), 88 + &api.DispatchWorkflowOption{ 89 + Ref: repo.DefaultBranch, 90 + ReturnRunInfo: true, 91 + }, 92 + ) 93 + req.AddTokenAuth(token) 94 + 95 + res := MakeRequest(t, req, http.StatusCreated) 96 + run := new(api.DispatchWorkflowRun) 97 + DecodeJSON(t, res, run) 98 + 99 + assert.NotZero(t, run.ID) 100 + assert.NotZero(t, run.RunNumber) 101 + assert.Len(t, run.Jobs, 2) 102 + }) 103 + }