diff options
author | Jason Song <i@wolfogre.com> | 2023-04-10 18:40:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-10 06:40:30 -0400 |
commit | 8cbc4a367d7424df5069e38bf791300cfaace519 (patch) | |
tree | 0a3a03bd2cbf265d7115a397da93a4098a3301b1 | |
parent | 4e3348135723dfc03dcc91b196b5da6f20b8a4ea (diff) | |
download | gitea-8cbc4a367d7424df5069e38bf791300cfaace519.tar.gz gitea-8cbc4a367d7424df5069e38bf791300cfaace519.zip |
Use actions job link as commit status URL instead of run link (#24023)
A commit status is bound to a job, not a run.
---------
Co-authored-by: silverwind <me@silverwind.io>
-rw-r--r-- | services/actions/commit_status.go | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/services/actions/commit_status.go b/services/actions/commit_status.go index 984c412956..97643e5f35 100644 --- a/services/actions/commit_status.go +++ b/services/actions/commit_status.go @@ -108,6 +108,11 @@ func createCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er description = "Blocked by required conditions" } + index, err := getIndexOfJob(ctx, job) + if err != nil { + return fmt.Errorf("getIndexOfJob: %w", err) + } + creator := user_model.NewActionsUser() if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{ Repo: repo, @@ -115,7 +120,7 @@ func createCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er Creator: creator, CommitStatus: &git_model.CommitStatus{ SHA: sha, - TargetURL: run.Link(), + TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), index), Description: description, Context: ctxname, CreatorID: creator.ID, @@ -142,3 +147,17 @@ func toCommitStatus(status actions_model.Status) api.CommitStatusState { return api.CommitStatusError } } + +func getIndexOfJob(ctx context.Context, job *actions_model.ActionRunJob) (int, error) { + // TODO: store job index as a field in ActionRunJob to avoid this + jobs, err := actions_model.GetRunJobsByRunID(ctx, job.RunID) + if err != nil { + return 0, err + } + for i, v := range jobs { + if v.ID == job.ID { + return i, nil + } + } + return 0, nil +} |