Skip to content

Commit f55fe98

Browse files
authored
Use actions job link as commit status URL instead of run link (#24023) (#24032)
Backport #24023. A commit status is bound to a job, not a run.
1 parent 27dbe97 commit f55fe98

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
@@ -88,13 +88,18 @@ func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
8888
return fmt.Errorf("GetLatestCommitStatus: %w", err)
8989
}
9090

91+
index, err := getIndexOfJob(ctx, job)
92+
if err != nil {
93+
return fmt.Errorf("getIndexOfJob: %w", err)
94+
}
95+
9196
if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{
9297
Repo: repo,
9398
SHA: sha,
9499
Creator: creator,
95100
CommitStatus: &git_model.CommitStatus{
96101
SHA: sha,
97-
TargetURL: run.Link(),
102+
TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), index),
98103
Description: "",
99104
Context: ctxname,
100105
CreatorID: creatorID,
@@ -121,3 +126,17 @@ func toCommitStatus(status actions_model.Status) api.CommitStatusState {
121126
return api.CommitStatusError
122127
}
123128
}
129+
130+
func getIndexOfJob(ctx context.Context, job *actions_model.ActionRunJob) (int, error) {
131+
// TODO: store job index as a field in ActionRunJob to avoid this
132+
jobs, err := actions_model.GetRunJobsByRunID(ctx, job.RunID)
133+
if err != nil {
134+
return 0, err
135+
}
136+
for i, v := range jobs {
137+
if v.ID == job.ID {
138+
return i, nil
139+
}
140+
}
141+
return 0, nil
142+
}

0 commit comments

Comments
 (0)