mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 13:28:25 +00:00
fix: commit status
This commit is contained in:
+12
-14
@@ -66,19 +66,17 @@ func DeleteResourceOfRepository(ctx context.Context, repo *repo_model.Repository
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateCommitStatus(ctx context.Context, task *bots_model.BotTask) error {
|
||||
if err := task.LoadJob(ctx); err != nil {
|
||||
return fmt.Errorf("load job: %w", err)
|
||||
}
|
||||
if err := task.Job.LoadAttributes(ctx); err != nil {
|
||||
func CreateCommitStatus(ctx context.Context, job *bots_model.BotRunJob) error {
|
||||
if err := job.LoadAttributes(ctx); err != nil {
|
||||
return fmt.Errorf("load run: %w", err)
|
||||
}
|
||||
|
||||
if task.Job.Run.Event != webhook.HookEventPush {
|
||||
run := job.Run
|
||||
if run.Event != webhook.HookEventPush {
|
||||
return nil
|
||||
}
|
||||
|
||||
payload, err := task.Job.Run.GetPushEventPayload()
|
||||
payload, err := run.GetPushEventPayload()
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetPushEventPayload: %w", err)
|
||||
}
|
||||
@@ -88,17 +86,17 @@ func CreateCommitStatus(ctx context.Context, task *bots_model.BotTask) error {
|
||||
return fmt.Errorf("GetUserByID: %w", err)
|
||||
}
|
||||
|
||||
repo := task.Job.Run.Repo
|
||||
repo := run.Repo
|
||||
sha := payload.HeadCommit.ID
|
||||
ctxname := task.Job.Name
|
||||
state := toCommitStatus(task.Job.Status)
|
||||
ctxname := job.Name
|
||||
state := toCommitStatus(job.Status)
|
||||
|
||||
if statuses, _, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{}); err != nil {
|
||||
return fmt.Errorf("GetLatestCommitStatus: %w", err)
|
||||
} else {
|
||||
for _, status := range statuses {
|
||||
if status.Context == ctxname {
|
||||
if status.State == state {
|
||||
for _, v := range statuses {
|
||||
if v.Context == ctxname {
|
||||
if v.State == state {
|
||||
return nil
|
||||
}
|
||||
break
|
||||
@@ -112,7 +110,7 @@ func CreateCommitStatus(ctx context.Context, task *bots_model.BotTask) error {
|
||||
Creator: creator,
|
||||
CommitStatus: &git_model.CommitStatus{
|
||||
SHA: sha,
|
||||
TargetURL: task.Job.Run.HTMLURL(),
|
||||
TargetURL: run.HTMLURL(),
|
||||
Description: "",
|
||||
Context: ctxname,
|
||||
CreatorID: payload.Pusher.ID,
|
||||
|
||||
@@ -33,7 +33,13 @@ func StopZombieTasks(ctx context.Context) error {
|
||||
|
||||
for _, task := range tasks {
|
||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||
return bots_model.StopTask(ctx, task.ID, bots_model.StatusFailure)
|
||||
if err := bots_model.StopTask(ctx, task.ID, bots_model.StatusFailure); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := task.LoadJob(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return CreateCommitStatus(ctx, task.Job)
|
||||
}); err != nil {
|
||||
log.Warn("stop zombie task %v: %v", task.ID, err)
|
||||
// go on
|
||||
@@ -55,7 +61,13 @@ func StopEndlessTasks(ctx context.Context) error {
|
||||
|
||||
for _, task := range tasks {
|
||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||
return bots_model.StopTask(ctx, task.ID, bots_model.StatusFailure)
|
||||
if err := bots_model.StopTask(ctx, task.ID, bots_model.StatusFailure); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := task.LoadJob(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return CreateCommitStatus(ctx, task.Job)
|
||||
}); err != nil {
|
||||
log.Warn("stop endless task %v: %v", task.ID, err)
|
||||
// go on
|
||||
@@ -80,8 +92,10 @@ func CancelAbandonedJobs(ctx context.Context) error {
|
||||
job.Status = bots_model.StatusCancelled
|
||||
job.Stopped = now
|
||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||
_, err := bots_model.UpdateRunJob(ctx, job, nil, "status", "stopped")
|
||||
return err
|
||||
if _, err := bots_model.UpdateRunJob(ctx, job, nil, "status", "stopped"); err != nil {
|
||||
return err
|
||||
}
|
||||
return CreateCommitStatus(ctx, job)
|
||||
}); err != nil {
|
||||
log.Warn("cancel abandoned job %v: %v", job.ID, err)
|
||||
// go on
|
||||
|
||||
Reference in New Issue
Block a user