Skip to content

Commit

Permalink
Use actions job link as commit status URL instead of run link (#24023) (
Browse files Browse the repository at this point in the history
#24032)

Backport #24023.

A commit status is bound to a job, not a run.
  • Loading branch information
wolfogre authored Apr 10, 2023
1 parent 27dbe97 commit f55fe98
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion services/actions/commit_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,18 @@ func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
return fmt.Errorf("GetLatestCommitStatus: %w", err)
}

index, err := getIndexOfJob(ctx, job)
if err != nil {
return fmt.Errorf("getIndexOfJob: %w", err)
}

if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{
Repo: repo,
SHA: sha,
Creator: creator,
CommitStatus: &git_model.CommitStatus{
SHA: sha,
TargetURL: run.Link(),
TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), index),
Description: "",
Context: ctxname,
CreatorID: creatorID,
Expand All @@ -121,3 +126,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
}

0 comments on commit f55fe98

Please sign in to comment.