summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorJason Song <i@wolfogre.com>2023-03-29 23:27:37 +0800
committerGitHub <noreply@github.com>2023-03-29 11:27:37 -0400
commit3e8db31a5b5a7be731b19da4bd666b0ddc35bd31 (patch)
tree0c51783184dcb015fda3ca03c611bd3d9476349c /routers
parente57e1144c5ae7a2995e6818c6ae32139e563add7 (diff)
downloadgitea-3e8db31a5b5a7be731b19da4bd666b0ddc35bd31.tar.gz
gitea-3e8db31a5b5a7be731b19da4bd666b0ddc35bd31.zip
Refactor commit status for Actions jobs (#23786)
Before: <img width="353" alt="xnip_230329_163852" src="https://user-images.githubusercontent.com/9418365/228479807-424452df-10fa-45cf-ae4b-09939c0ed54c.png"> After: <img width="508" alt="xnip_230329_163358" src="https://user-images.githubusercontent.com/9418365/228479923-537b54fe-9564-4105-a068-bcc75fa2a7ea.png"> Highlights: - Treat `StatusSkipped` as `CommitStatusSuccess` instead of `CommitStatusFailure`, so it fixed #23599. - Use the bot user `gitea-actions` instead of the trigger as the creator of commit status. - New format `<run_name> / <job_name> / (<event>)` for the context of commit status to avoid conflicts. - Add descriptions for commit status. - Add the missing calls to `CreateCommitStatus`. - Refactor `CreateCommitStatus` to make it easier to use.
Diffstat (limited to 'routers')
-rw-r--r--routers/api/actions/runner/runner.go5
-rw-r--r--routers/api/actions/runner/utils.go3
-rw-r--r--routers/web/repo/actions/view.go15
3 files changed, 8 insertions, 15 deletions
diff --git a/routers/api/actions/runner/runner.go b/routers/api/actions/runner/runner.go
index 07657c9120..a445864858 100644
--- a/routers/api/actions/runner/runner.go
+++ b/routers/api/actions/runner/runner.go
@@ -149,10 +149,7 @@ func (s *Service) UpdateTask(
return nil, status.Errorf(codes.Internal, "load job: %v", err)
}
- if err := actions_service.CreateCommitStatus(ctx, task.Job); err != nil {
- log.Error("Update commit status for job %v failed: %v", task.Job.ID, err)
- // go on
- }
+ actions_service.CreateCommitStatus(ctx, task.Job)
if req.Msg.State.Result != runnerv1.Result_RESULT_UNSPECIFIED {
if err := actions_service.EmitJobsIfReady(task.Job.RunID); err != nil {
diff --git a/routers/api/actions/runner/utils.go b/routers/api/actions/runner/utils.go
index 80e71941f2..a022445ff3 100644
--- a/routers/api/actions/runner/utils.go
+++ b/routers/api/actions/runner/utils.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/log"
secret_module "code.gitea.io/gitea/modules/secret"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/services/actions"
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
"google.golang.org/protobuf/types/known/structpb"
@@ -27,6 +28,8 @@ func pickTask(ctx context.Context, runner *actions_model.ActionRunner) (*runnerv
return nil, false, nil
}
+ actions.CreateCommitStatus(ctx, t.Job)
+
task := &runnerv1.Task{
Id: t.ID,
WorkflowPayload: t.Job.WorkflowPayload,
diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go
index 0fa255b7e6..b2b625ea23 100644
--- a/routers/web/repo/actions/view.go
+++ b/routers/web/repo/actions/view.go
@@ -16,7 +16,6 @@ import (
"code.gitea.io/gitea/modules/actions"
"code.gitea.io/gitea/modules/base"
context_module "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
@@ -264,10 +263,7 @@ func Rerun(ctx *context_module.Context) {
return
}
- if err := actions_service.CreateCommitStatus(ctx, job); err != nil {
- log.Error("Update commit status for job %v failed: %v", job.ID, err)
- // go on
- }
+ actions_service.CreateCommitStatus(ctx, job)
ctx.JSON(http.StatusOK, struct{}{})
}
@@ -308,12 +304,7 @@ func Cancel(ctx *context_module.Context) {
return
}
- for _, job := range jobs {
- if err := actions_service.CreateCommitStatus(ctx, job); err != nil {
- log.Error("Update commit status for job %v failed: %v", job.ID, err)
- // go on
- }
- }
+ actions_service.CreateCommitStatus(ctx, jobs...)
ctx.JSON(http.StatusOK, struct{}{})
}
@@ -349,6 +340,8 @@ func Approve(ctx *context_module.Context) {
return
}
+ actions_service.CreateCommitStatus(ctx, jobs...)
+
ctx.JSON(http.StatusOK, struct{}{})
}