mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-12-01 14:26:10 +01:00
Backport #24023. A commit status is bound to a job, not a run.
This commit is contained in:
parent
27dbe97542
commit
f55fe989a4
|
@ -88,13 +88,18 @@ func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
|
||||||
return fmt.Errorf("GetLatestCommitStatus: %w", err)
|
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{
|
if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
SHA: sha,
|
SHA: sha,
|
||||||
Creator: creator,
|
Creator: creator,
|
||||||
CommitStatus: &git_model.CommitStatus{
|
CommitStatus: &git_model.CommitStatus{
|
||||||
SHA: sha,
|
SHA: sha,
|
||||||
TargetURL: run.Link(),
|
TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), index),
|
||||||
Description: "",
|
Description: "",
|
||||||
Context: ctxname,
|
Context: ctxname,
|
||||||
CreatorID: creatorID,
|
CreatorID: creatorID,
|
||||||
|
@ -121,3 +126,17 @@ func toCommitStatus(status actions_model.Status) api.CommitStatusState {
|
||||||
return api.CommitStatusError
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue