From 8cfb0479837ceec77118f3a209925216b934122d Mon Sep 17 00:00:00 2001 From: Christopher Homberger Date: Fri, 21 Mar 2025 15:48:00 +0100 Subject: [PATCH] fix lint --- modules/actions/workflows.go | 2 +- routers/api/v1/repo/action.go | 2 - services/actions/notifier.go | 8 +- services/convert/convert.go | 5 +- services/webhook/notifier.go | 4 + templates/swagger/v1_json.tmpl | 254 +++++++++++++++++++++++++ tests/integration/repo_webhook_test.go | 4 +- 7 files changed, 270 insertions(+), 9 deletions(-) diff --git a/modules/actions/workflows.go b/modules/actions/workflows.go index 5afcab145b..70d8de4687 100644 --- a/modules/actions/workflows.go +++ b/modules/actions/workflows.go @@ -716,7 +716,7 @@ func matchWorkflowRunEvent(payload *api.WorkflowRunPayload, evt *jobparser.Event case "types": action := payload.Action for _, val := range vals { - if glob.MustCompile(val, '/').Match(string(action)) { + if glob.MustCompile(val, '/').Match(action) { matchTimes++ break } diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index c03f735710..d2abab9577 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -1017,7 +1017,6 @@ func GetWorkflowRun(ctx *context.APIContext) { return } ctx.JSON(http.StatusOK, convertedArtifact) - return } // GetWorkflowJobs Lists all jobs for a workflow run. @@ -1130,7 +1129,6 @@ func GetWorkflowJob(ctx *context.APIContext) { return } ctx.JSON(http.StatusOK, convertedWorkflowJob) - return } // GetArtifacts Lists all artifacts for a repository. diff --git a/services/actions/notifier.go b/services/actions/notifier.go index 0b96ee06b9..a7ae52d4f3 100644 --- a/services/actions/notifier.go +++ b/services/actions/notifier.go @@ -10,7 +10,6 @@ import ( issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/organization" packages_model "code.gitea.io/gitea/models/packages" - "code.gitea.io/gitea/models/perm" perm_model "code.gitea.io/gitea/models/perm" access_model "code.gitea.io/gitea/models/perm/access" repo_model "code.gitea.io/gitea/models/repo" @@ -785,7 +784,10 @@ func (n *actionsNotifier) WorkflowRunStatusUpdate(ctx context.Context, repo *rep defer gitRepo.Close() convertedWorkflow, err := convert.GetActionWorkflow(ctx, gitRepo, repo, run.WorkflowID) - + if err != nil { + log.Error("GetActionWorkflow: %v", err) + return + } convertedRun, err := convert.ToActionWorkflowRun(ctx, repo, run) if err != nil { log.Error("ToActionWorkflowRun: %v", err) @@ -797,7 +799,7 @@ func (n *actionsNotifier) WorkflowRunStatusUpdate(ctx context.Context, repo *rep Workflow: convertedWorkflow, WorkflowRun: convertedRun, Organization: org, - Repo: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), + Repo: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeOwner}), Sender: convert.ToUser(ctx, sender, nil), }).Notify(ctx) } diff --git a/services/convert/convert.go b/services/convert/convert.go index bb34d97a34..9fcda5f46f 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -235,7 +235,10 @@ func ToActionTask(ctx context.Context, t *actions_model.ActionTask) (*api.Action } func ToActionWorkflowRun(ctx context.Context, repo *repo_model.Repository, run *actions_model.ActionRun) (*api.ActionWorkflowRun, error) { - run.LoadRepo(ctx) + err := run.LoadRepo(ctx) + if err != nil { + return nil, err + } status, conclusion := ToActionsStatus(run.Status) return &api.ActionWorkflowRun{ ID: run.ID, diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index 5689748724..cc40dd3377 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -995,6 +995,10 @@ func (*webhookNotifier) WorkflowRunStatusUpdate(ctx context.Context, repo *repo_ defer gitRepo.Close() convertedWorkflow, err := convert.GetActionWorkflow(ctx, gitRepo, repo, run.WorkflowID) + if err != nil { + log.Error("GetActionWorkflow: %v", err) + return + } convertedRun, err := convert.ToActionWorkflowRun(ctx, repo, run) if err != nil { diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 1efaf1a875..e93add7642 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -4187,6 +4187,52 @@ } } }, + "/repos/{owner}/{repo}/actions/jobs/{job_id}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Gets a specific workflow job for a workflow run", + "operationId": "getWorkflowJob", + "parameters": [ + { + "type": "string", + "description": "name of the owner", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repository", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "id of the job", + "name": "job_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/Artifact" + }, + "400": { + "$ref": "#/responses/error" + }, + "404": { + "$ref": "#/responses/notFound" + } + } + } + }, "/repos/{owner}/{repo}/actions/runners/registration-token": { "get": { "produces": [ @@ -4220,6 +4266,104 @@ } } }, + "/repos/{owner}/{repo}/actions/runs": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Lists all runs for a repository run", + "operationId": "getWorkflowRuns", + "parameters": [ + { + "type": "string", + "description": "name of the owner", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repository", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "runid of the workflow run", + "name": "run", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the artifact", + "name": "name", + "in": "query" + } + ], + "responses": { + "200": { + "$ref": "#/responses/ArtifactsList" + }, + "400": { + "$ref": "#/responses/error" + }, + "404": { + "$ref": "#/responses/notFound" + } + } + } + }, + "/repos/{owner}/{repo}/actions/runs/{run}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Gets a specific workflow run", + "operationId": "GetWorkflowRun", + "parameters": [ + { + "type": "string", + "description": "name of the owner", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repository", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "id of the run", + "name": "run", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/Artifact" + }, + "400": { + "$ref": "#/responses/error" + }, + "404": { + "$ref": "#/responses/notFound" + } + } + } + }, "/repos/{owner}/{repo}/actions/runs/{run}/artifacts": { "get": { "produces": [ @@ -4272,6 +4416,58 @@ } } }, + "/repos/{owner}/{repo}/actions/runs/{run}/jobs": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Lists all jobs for a workflow run", + "operationId": "getWorkflowJobs", + "parameters": [ + { + "type": "string", + "description": "name of the owner", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repository", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "runid of the workflow run", + "name": "run", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the artifact", + "name": "name", + "in": "query" + } + ], + "responses": { + "200": { + "$ref": "#/responses/ArtifactsList" + }, + "400": { + "$ref": "#/responses/error" + }, + "404": { + "$ref": "#/responses/notFound" + } + } + } + }, "/repos/{owner}/{repo}/actions/secrets": { "get": { "produces": [ @@ -19404,19 +19600,77 @@ "description": "ActionWorkflowRun represents a WorkflowRun", "type": "object", "properties": { + "completed_at": { + "type": "string", + "format": "date-time", + "x-go-name": "CompletedAt" + }, + "conclusion": { + "type": "string", + "x-go-name": "Conclusion" + }, + "display_title": { + "type": "string", + "x-go-name": "DisplayTitle" + }, + "event": { + "type": "string", + "x-go-name": "Event" + }, + "head_branch": { + "type": "string", + "x-go-name": "HeadBranch" + }, + "head_repository": { + "$ref": "#/definitions/Repository" + }, "head_sha": { "type": "string", "x-go-name": "HeadSha" }, + "html_url": { + "type": "string", + "x-go-name": "HTMLURL" + }, "id": { "type": "integer", "format": "int64", "x-go-name": "ID" }, + "path": { + "type": "string", + "x-go-name": "Path" + }, + "repository": { + "$ref": "#/definitions/Repository" + }, "repository_id": { "type": "integer", "format": "int64", "x-go-name": "RepositoryID" + }, + "run_attempt": { + "type": "integer", + "format": "int64", + "x-go-name": "RunAttempt" + }, + "run_number": { + "type": "integer", + "format": "int64", + "x-go-name": "RunNumber" + }, + "started_at": { + "type": "string", + "format": "date-time", + "x-go-name": "StartedAt" + }, + "status": { + "type": "string", + "x-go-name": "Status" + }, + "url": { + "type": "string", + "x-go-name": "URL" } }, "x-go-package": "code.gitea.io/gitea/modules/structs" diff --git a/tests/integration/repo_webhook_test.go b/tests/integration/repo_webhook_test.go index 7e85c10d4b..4dfe1945c3 100644 --- a/tests/integration/repo_webhook_test.go +++ b/tests/integration/repo_webhook_test.go @@ -707,7 +707,7 @@ jobs: assert.EqualValues(t, commitID, payloads[3].WorkflowJob.HeadSha) assert.EqualValues(t, "repo1", payloads[3].Repo.Name) assert.EqualValues(t, "user2/repo1", payloads[3].Repo.FullName) - assert.Contains(t, payloads[3].WorkflowJob.URL, fmt.Sprintf("/actions/runs/%d/jobs/%d", payloads[3].WorkflowJob.RunID, payloads[3].WorkflowJob.ID)) + assert.Contains(t, payloads[3].WorkflowJob.URL, fmt.Sprintf("/actions/jobs/%d", payloads[3].WorkflowJob.ID)) assert.Contains(t, payloads[3].WorkflowJob.URL, payloads[3].WorkflowJob.RunURL) assert.Contains(t, payloads[3].WorkflowJob.HTMLURL, fmt.Sprintf("/jobs/%d", 0)) assert.Len(t, payloads[3].WorkflowJob.Steps, 1) @@ -745,7 +745,7 @@ jobs: assert.EqualValues(t, commitID, payloads[6].WorkflowJob.HeadSha) assert.EqualValues(t, "repo1", payloads[6].Repo.Name) assert.EqualValues(t, "user2/repo1", payloads[6].Repo.FullName) - assert.Contains(t, payloads[6].WorkflowJob.URL, fmt.Sprintf("/actions/runs/%d/jobs/%d", payloads[6].WorkflowJob.RunID, payloads[6].WorkflowJob.ID)) + assert.Contains(t, payloads[6].WorkflowJob.URL, fmt.Sprintf("/actions/jobs/%d", payloads[6].WorkflowJob.ID)) assert.Contains(t, payloads[6].WorkflowJob.URL, payloads[6].WorkflowJob.RunURL) assert.Contains(t, payloads[6].WorkflowJob.HTMLURL, fmt.Sprintf("/jobs/%d", 1)) assert.Len(t, payloads[6].WorkflowJob.Steps, 2)