Skip to content

Commit 8cbc4a3

Browse files
wolfogresilverwind
andauthored
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 <[email protected]>
1 parent 4e33481 commit 8cbc4a3

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

services/actions/commit_status.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,19 @@ func createCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
108108
description = "Blocked by required conditions"
109109
}
110110

111+
index, err := getIndexOfJob(ctx, job)
112+
if err != nil {
113+
return fmt.Errorf("getIndexOfJob: %w", err)
114+
}
115+
111116
creator := user_model.NewActionsUser()
112117
if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{
113118
Repo: repo,
114119
SHA: sha,
115120
Creator: creator,
116121
CommitStatus: &git_model.CommitStatus{
117122
SHA: sha,
118-
TargetURL: run.Link(),
123+
TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), index),
119124
Description: description,
120125
Context: ctxname,
121126
CreatorID: creator.ID,
@@ -142,3 +147,17 @@ func toCommitStatus(status actions_model.Status) api.CommitStatusState {
142147
return api.CommitStatusError
143148
}
144149
}
150+
151+
func getIndexOfJob(ctx context.Context, job *actions_model.ActionRunJob) (int, error) {
152+
// TODO: store job index as a field in ActionRunJob to avoid this
153+
jobs, err := actions_model.GetRunJobsByRunID(ctx, job.RunID)
154+
if err != nil {
155+
return 0, err
156+
}
157+
for i, v := range jobs {
158+
if v.ID == job.ID {
159+
return i, nil
160+
}
161+
}
162+
return 0, nil
163+
}

0 commit comments

Comments
 (0)