mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-23 22:05:51 +02:00
fix: commit status
This commit is contained in:
parent
564937a657
commit
3793d55eca
@ -29,6 +29,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/repository"
|
"code.gitea.io/gitea/modules/repository"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
bots_service "code.gitea.io/gitea/services/bots"
|
||||||
|
|
||||||
"github.com/nektos/act/pkg/jobparser"
|
"github.com/nektos/act/pkg/jobparser"
|
||||||
)
|
)
|
||||||
@ -44,11 +45,11 @@ func NewNotifier() base.Notifier {
|
|||||||
return &botsNotifier{}
|
return &botsNotifier{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func notify(repo *repo_model.Repository, doer *user_model.User, ref string, evt webhook.HookEventType, payload api.Payloader) error {
|
func notify(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, ref string, evt webhook.HookEventType, payload api.Payloader) error {
|
||||||
return notifyWithPR(repo, doer, ref, evt, payload, nil)
|
return notifyWithPR(ctx, repo, doer, ref, evt, payload, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func notifyWithPR(repo *repo_model.Repository, doer *user_model.User, ref string, evt webhook.HookEventType, payload api.Payloader, pr *issues_model.PullRequest) error {
|
func notifyWithPR(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, ref string, evt webhook.HookEventType, payload api.Payloader, pr *issues_model.PullRequest) error {
|
||||||
if unit.TypeBots.UnitGlobalDisabled() {
|
if unit.TypeBots.UnitGlobalDisabled() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -109,7 +110,18 @@ func notifyWithPR(repo *repo_model.Repository, doer *user_model.User, ref string
|
|||||||
}
|
}
|
||||||
if err := bots_model.InsertRun(&run, jobs); err != nil {
|
if err := bots_model.InsertRun(&run, jobs); err != nil {
|
||||||
log.Error("InsertRun: %v", err)
|
log.Error("InsertRun: %v", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
if jobs, _, err := bots_model.FindRunJobs(ctx, bots_model.FindRunJobOptions{RunID: run.ID}); err != nil {
|
||||||
|
log.Error("FindRunJobs: %v", err)
|
||||||
|
} else {
|
||||||
|
for _, job := range jobs {
|
||||||
|
if err := bots_service.CreateCommitStatus(ctx, job); err != nil {
|
||||||
|
log.Error("CreateCommitStatus: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -126,7 +138,7 @@ func (a *botsNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.I
|
|||||||
}
|
}
|
||||||
|
|
||||||
mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
|
mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
|
||||||
if err := notify(issue.Repo, issue.Poster, issue.Repo.DefaultBranch,
|
if err := notify(ctx, issue.Repo, issue.Poster, issue.Repo.DefaultBranch,
|
||||||
webhook.HookEventIssues, &api.IssuePayload{
|
webhook.HookEventIssues, &api.IssuePayload{
|
||||||
Action: api.HookIssueOpened,
|
Action: api.HookIssueOpened,
|
||||||
Index: issue.Index,
|
Index: issue.Index,
|
||||||
@ -159,7 +171,7 @@ func (a *botsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_m
|
|||||||
} else {
|
} else {
|
||||||
apiPullRequest.Action = api.HookIssueReOpened
|
apiPullRequest.Action = api.HookIssueReOpened
|
||||||
}
|
}
|
||||||
err = notify(issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventPullRequest, apiPullRequest)
|
err = notify(ctx, issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventPullRequest, apiPullRequest)
|
||||||
} else {
|
} else {
|
||||||
apiIssue := &api.IssuePayload{
|
apiIssue := &api.IssuePayload{
|
||||||
Index: issue.Index,
|
Index: issue.Index,
|
||||||
@ -172,7 +184,7 @@ func (a *botsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_m
|
|||||||
} else {
|
} else {
|
||||||
apiIssue.Action = api.HookIssueReOpened
|
apiIssue.Action = api.HookIssueReOpened
|
||||||
}
|
}
|
||||||
err = notify(issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventIssues, apiIssue)
|
err = notify(ctx, issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventIssues, apiIssue)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("PrepareWebhooks [is_pull: %v, is_closed: %v]: %v", issue.IsPull, isClosed, err)
|
log.Error("PrepareWebhooks [is_pull: %v, is_closed: %v]: %v", issue.IsPull, isClosed, err)
|
||||||
@ -203,7 +215,7 @@ func (a *botsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_m
|
|||||||
log.Error("LoadIssue: %v", err)
|
log.Error("LoadIssue: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = notify(issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventPullRequestLabel, &api.PullRequestPayload{
|
err = notify(ctx, issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventPullRequestLabel, &api.PullRequestPayload{
|
||||||
Action: api.HookIssueLabelUpdated,
|
Action: api.HookIssueLabelUpdated,
|
||||||
Index: issue.Index,
|
Index: issue.Index,
|
||||||
PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil),
|
PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil),
|
||||||
@ -211,7 +223,7 @@ func (a *botsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_m
|
|||||||
Sender: convert.ToUser(doer, nil),
|
Sender: convert.ToUser(doer, nil),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
err = notify(issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventIssueLabel, &api.IssuePayload{
|
err = notify(ctx, issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventIssueLabel, &api.IssuePayload{
|
||||||
Action: api.HookIssueLabelUpdated,
|
Action: api.HookIssueLabelUpdated,
|
||||||
Index: issue.Index,
|
Index: issue.Index,
|
||||||
Issue: convert.ToAPIIssue(ctx, issue),
|
Issue: convert.ToAPIIssue(ctx, issue),
|
||||||
@ -232,7 +244,7 @@ func (a *botsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
if issue.IsPull {
|
if issue.IsPull {
|
||||||
err = notify(issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventPullRequestComment, &api.IssueCommentPayload{
|
err = notify(ctx, issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventPullRequestComment, &api.IssueCommentPayload{
|
||||||
Action: api.HookIssueCommentCreated,
|
Action: api.HookIssueCommentCreated,
|
||||||
Issue: convert.ToAPIIssue(ctx, issue),
|
Issue: convert.ToAPIIssue(ctx, issue),
|
||||||
Comment: convert.ToComment(comment),
|
Comment: convert.ToComment(comment),
|
||||||
@ -241,7 +253,7 @@ func (a *botsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_
|
|||||||
IsPull: true,
|
IsPull: true,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
err = notify(issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventIssueComment, &api.IssueCommentPayload{
|
err = notify(ctx, issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventIssueComment, &api.IssueCommentPayload{
|
||||||
Action: api.HookIssueCommentCreated,
|
Action: api.HookIssueCommentCreated,
|
||||||
Issue: convert.ToAPIIssue(ctx, issue),
|
Issue: convert.ToAPIIssue(ctx, issue),
|
||||||
Comment: convert.ToComment(comment),
|
Comment: convert.ToComment(comment),
|
||||||
@ -271,7 +283,7 @@ func (a *botsNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues_mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
mode, _ := access_model.AccessLevel(ctx, pull.Issue.Poster, pull.Issue.Repo)
|
mode, _ := access_model.AccessLevel(ctx, pull.Issue.Poster, pull.Issue.Repo)
|
||||||
if err := notifyWithPR(pull.Issue.Repo, pull.Issue.Poster, pull.Issue.Repo.DefaultBranch, webhook.HookEventPullRequest, &api.PullRequestPayload{
|
if err := notifyWithPR(ctx, pull.Issue.Repo, pull.Issue.Poster, pull.Issue.Repo.DefaultBranch, webhook.HookEventPullRequest, &api.PullRequestPayload{
|
||||||
Action: api.HookIssueOpened,
|
Action: api.HookIssueOpened,
|
||||||
Index: pull.Issue.Index,
|
Index: pull.Issue.Index,
|
||||||
PullRequest: convert.ToAPIPullRequest(ctx, pull, nil),
|
PullRequest: convert.ToAPIPullRequest(ctx, pull, nil),
|
||||||
@ -289,7 +301,7 @@ func (a *botsNotifier) NotifyTransferRepository(ctx context.Context, doer *user_
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *botsNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
func (a *botsNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||||
if err := notify(repo, doer, repo.DefaultBranch,
|
if err := notify(ctx, repo, doer, repo.DefaultBranch,
|
||||||
webhook.HookEventRepository,
|
webhook.HookEventRepository,
|
||||||
&api.RepositoryPayload{
|
&api.RepositoryPayload{
|
||||||
Action: api.HookRepoCreated,
|
Action: api.HookRepoCreated,
|
||||||
@ -306,7 +318,7 @@ func (a *botsNotifier) NotifyForkRepository(ctx context.Context, doer *user_mode
|
|||||||
mode, _ := access_model.AccessLevel(ctx, doer, repo)
|
mode, _ := access_model.AccessLevel(ctx, doer, repo)
|
||||||
|
|
||||||
// forked webhook
|
// forked webhook
|
||||||
if err := notify(oldRepo, doer, oldRepo.DefaultBranch, webhook.HookEventFork, &api.ForkPayload{
|
if err := notify(ctx, oldRepo, doer, oldRepo.DefaultBranch, webhook.HookEventFork, &api.ForkPayload{
|
||||||
Forkee: convert.ToRepo(oldRepo, oldMode),
|
Forkee: convert.ToRepo(oldRepo, oldMode),
|
||||||
Repo: convert.ToRepo(repo, mode),
|
Repo: convert.ToRepo(repo, mode),
|
||||||
Sender: convert.ToUser(doer, nil),
|
Sender: convert.ToUser(doer, nil),
|
||||||
@ -318,7 +330,7 @@ func (a *botsNotifier) NotifyForkRepository(ctx context.Context, doer *user_mode
|
|||||||
|
|
||||||
// Add to hook queue for created repo after session commit.
|
// Add to hook queue for created repo after session commit.
|
||||||
if u.IsOrganization() {
|
if u.IsOrganization() {
|
||||||
if err := notify(repo, doer, oldRepo.DefaultBranch, webhook.HookEventRepository, &api.RepositoryPayload{
|
if err := notify(ctx, repo, doer, oldRepo.DefaultBranch, webhook.HookEventRepository, &api.RepositoryPayload{
|
||||||
Action: api.HookRepoCreated,
|
Action: api.HookRepoCreated,
|
||||||
Repository: convert.ToRepo(repo, perm.AccessModeOwner),
|
Repository: convert.ToRepo(repo, perm.AccessModeOwner),
|
||||||
Organization: convert.ToUser(u, nil),
|
Organization: convert.ToUser(u, nil),
|
||||||
@ -355,7 +367,7 @@ func (a *botsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_m
|
|||||||
log.Error("models.AccessLevel: %v", err)
|
log.Error("models.AccessLevel: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := notifyWithPR(review.Issue.Repo, review.Reviewer, review.CommitID, reviewHookType, &api.PullRequestPayload{
|
if err := notifyWithPR(ctx, review.Issue.Repo, review.Reviewer, review.CommitID, reviewHookType, &api.PullRequestPayload{
|
||||||
Action: api.HookIssueReviewed,
|
Action: api.HookIssueReviewed,
|
||||||
Index: review.Issue.Index,
|
Index: review.Issue.Index,
|
||||||
PullRequest: convert.ToAPIPullRequest(db.DefaultContext, pr, nil),
|
PullRequest: convert.ToAPIPullRequest(db.DefaultContext, pr, nil),
|
||||||
@ -402,7 +414,7 @@ func (*botsNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_mode
|
|||||||
Action: api.HookIssueClosed,
|
Action: api.HookIssueClosed,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = notifyWithPR(pr.Issue.Repo, doer, pr.MergedCommitID, webhook.HookEventPullRequest, apiPullRequest, pr)
|
err = notifyWithPR(ctx, pr.Issue.Repo, doer, pr.MergedCommitID, webhook.HookEventPullRequest, apiPullRequest, pr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("PrepareWebhooks: %v", err)
|
log.Error("PrepareWebhooks: %v", err)
|
||||||
}
|
}
|
||||||
@ -416,7 +428,7 @@ func (a *botsNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := notify(repo, pusher, opts.RefFullName, webhook.HookEventPush, &api.PushPayload{
|
if err := notify(ctx, repo, pusher, opts.RefFullName, webhook.HookEventPush, &api.PushPayload{
|
||||||
Ref: opts.RefFullName,
|
Ref: opts.RefFullName,
|
||||||
Before: opts.OldCommitID,
|
Before: opts.OldCommitID,
|
||||||
After: opts.NewCommitID,
|
After: opts.NewCommitID,
|
||||||
@ -436,7 +448,7 @@ func (a *botsNotifier) NotifyCreateRef(ctx context.Context, pusher *user_model.U
|
|||||||
apiRepo := convert.ToRepo(repo, perm.AccessModeNone)
|
apiRepo := convert.ToRepo(repo, perm.AccessModeNone)
|
||||||
refName := git.RefEndName(refFullName)
|
refName := git.RefEndName(refFullName)
|
||||||
|
|
||||||
if err := notify(repo, pusher, refName, webhook.HookEventCreate, &api.CreatePayload{
|
if err := notify(ctx, repo, pusher, refName, webhook.HookEventCreate, &api.CreatePayload{
|
||||||
Ref: refName,
|
Ref: refName,
|
||||||
Sha: refID,
|
Sha: refID,
|
||||||
RefType: refType,
|
RefType: refType,
|
||||||
@ -452,7 +464,7 @@ func (a *botsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.U
|
|||||||
apiRepo := convert.ToRepo(repo, perm.AccessModeNone)
|
apiRepo := convert.ToRepo(repo, perm.AccessModeNone)
|
||||||
refName := git.RefEndName(refFullName)
|
refName := git.RefEndName(refFullName)
|
||||||
|
|
||||||
if err := notify(repo, pusher, refName, webhook.HookEventDelete, &api.DeletePayload{
|
if err := notify(ctx, repo, pusher, refName, webhook.HookEventDelete, &api.DeletePayload{
|
||||||
Ref: refName,
|
Ref: refName,
|
||||||
RefType: refType,
|
RefType: refType,
|
||||||
PusherType: api.PusherTypeUser,
|
PusherType: api.PusherTypeUser,
|
||||||
@ -471,7 +483,7 @@ func (a *botsNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_m
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := notify(repo, pusher, opts.RefFullName, webhook.HookEventPush, &api.PushPayload{
|
if err := notify(ctx, repo, pusher, opts.RefFullName, webhook.HookEventPush, &api.PushPayload{
|
||||||
Ref: opts.RefFullName,
|
Ref: opts.RefFullName,
|
||||||
Before: opts.OldCommitID,
|
Before: opts.OldCommitID,
|
||||||
After: opts.NewCommitID,
|
After: opts.NewCommitID,
|
||||||
@ -502,7 +514,7 @@ func sendReleaseNofiter(ctx context.Context, doer *user_model.User, rel *repo_mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
mode, _ := access_model.AccessLevel(ctx, doer, rel.Repo)
|
mode, _ := access_model.AccessLevel(ctx, doer, rel.Repo)
|
||||||
if err := notify(rel.Repo, doer, ref, webhook.HookEventRelease, &api.ReleasePayload{
|
if err := notify(ctx, rel.Repo, doer, ref, webhook.HookEventRelease, &api.ReleasePayload{
|
||||||
Action: action,
|
Action: action,
|
||||||
Release: convert.ToRelease(rel),
|
Release: convert.ToRelease(rel),
|
||||||
Repository: convert.ToRepo(rel.Repo, mode),
|
Repository: convert.ToRepo(rel.Repo, mode),
|
||||||
@ -547,7 +559,7 @@ func notifyPackage(sender *user_model.User, pd *packages_model.PackageDescriptor
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := notify(pd.Repository, sender, "", webhook.HookEventPackage, &api.PackagePayload{
|
if err := notify(ctx, pd.Repository, sender, "", webhook.HookEventPackage, &api.PackagePayload{
|
||||||
Action: action,
|
Action: action,
|
||||||
Package: apiPackage,
|
Package: apiPackage,
|
||||||
Sender: convert.ToUser(sender, nil),
|
Sender: convert.ToUser(sender, nil),
|
||||||
|
@ -172,11 +172,8 @@ func (s *Service) UpdateTask(
|
|||||||
if err := task.LoadJob(ctx); err != nil {
|
if err := task.LoadJob(ctx); err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "load job: %v", err)
|
return nil, status.Errorf(codes.Internal, "load job: %v", err)
|
||||||
}
|
}
|
||||||
if err := task.Job.LoadAttributes(ctx); err != nil {
|
|
||||||
return nil, status.Errorf(codes.Internal, "load run: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := bots_service.CreateCommitStatus(ctx, task); err != nil {
|
if err := bots_service.CreateCommitStatus(ctx, task.Job); err != nil {
|
||||||
log.Error("Update commit status failed: %v", err)
|
log.Error("Update commit status failed: %v", err)
|
||||||
// go on
|
// go on
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
context_module "code.gitea.io/gitea/modules/context"
|
context_module "code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
|
bots_service "code.gitea.io/gitea/services/bots"
|
||||||
|
|
||||||
runnerv1 "code.gitea.io/bots-proto-go/runner/v1"
|
runnerv1 "code.gitea.io/bots-proto-go/runner/v1"
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
@ -211,8 +212,10 @@ func Rerun(ctx *context_module.Context) {
|
|||||||
job.Stopped = 0
|
job.Stopped = 0
|
||||||
|
|
||||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
_, err := bots_model.UpdateRunJob(ctx, job, builder.Eq{"status": status}, "task_id", "status", "started", "stopped")
|
if _, err := bots_model.UpdateRunJob(ctx, job, builder.Eq{"status": status}, "task_id", "status", "started", "stopped"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
return bots_service.CreateCommitStatus(ctx, job)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
@ -250,6 +253,9 @@ func Cancel(ctx *context_module.Context) {
|
|||||||
if err := bots_model.StopTask(ctx, job.TaskID, bots_model.StatusCancelled); err != nil {
|
if err := bots_model.StopTask(ctx, job.TaskID, bots_model.StatusCancelled); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := bots_service.CreateCommitStatus(ctx, job); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
@ -66,19 +66,17 @@ func DeleteResourceOfRepository(ctx context.Context, repo *repo_model.Repository
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateCommitStatus(ctx context.Context, task *bots_model.BotTask) error {
|
func CreateCommitStatus(ctx context.Context, job *bots_model.BotRunJob) error {
|
||||||
if err := task.LoadJob(ctx); err != nil {
|
if err := job.LoadAttributes(ctx); err != nil {
|
||||||
return fmt.Errorf("load job: %w", err)
|
|
||||||
}
|
|
||||||
if err := task.Job.LoadAttributes(ctx); err != nil {
|
|
||||||
return fmt.Errorf("load run: %w", err)
|
return fmt.Errorf("load run: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if task.Job.Run.Event != webhook.HookEventPush {
|
run := job.Run
|
||||||
|
if run.Event != webhook.HookEventPush {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
payload, err := task.Job.Run.GetPushEventPayload()
|
payload, err := run.GetPushEventPayload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("GetPushEventPayload: %w", err)
|
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)
|
return fmt.Errorf("GetUserByID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := task.Job.Run.Repo
|
repo := run.Repo
|
||||||
sha := payload.HeadCommit.ID
|
sha := payload.HeadCommit.ID
|
||||||
ctxname := task.Job.Name
|
ctxname := job.Name
|
||||||
state := toCommitStatus(task.Job.Status)
|
state := toCommitStatus(job.Status)
|
||||||
|
|
||||||
if statuses, _, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{}); err != nil {
|
if statuses, _, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{}); err != nil {
|
||||||
return fmt.Errorf("GetLatestCommitStatus: %w", err)
|
return fmt.Errorf("GetLatestCommitStatus: %w", err)
|
||||||
} else {
|
} else {
|
||||||
for _, status := range statuses {
|
for _, v := range statuses {
|
||||||
if status.Context == ctxname {
|
if v.Context == ctxname {
|
||||||
if status.State == state {
|
if v.State == state {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@ -112,7 +110,7 @@ func CreateCommitStatus(ctx context.Context, task *bots_model.BotTask) error {
|
|||||||
Creator: creator,
|
Creator: creator,
|
||||||
CommitStatus: &git_model.CommitStatus{
|
CommitStatus: &git_model.CommitStatus{
|
||||||
SHA: sha,
|
SHA: sha,
|
||||||
TargetURL: task.Job.Run.HTMLURL(),
|
TargetURL: run.HTMLURL(),
|
||||||
Description: "",
|
Description: "",
|
||||||
Context: ctxname,
|
Context: ctxname,
|
||||||
CreatorID: payload.Pusher.ID,
|
CreatorID: payload.Pusher.ID,
|
||||||
|
@ -33,7 +33,13 @@ func StopZombieTasks(ctx context.Context) error {
|
|||||||
|
|
||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
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 {
|
}); err != nil {
|
||||||
log.Warn("stop zombie task %v: %v", task.ID, err)
|
log.Warn("stop zombie task %v: %v", task.ID, err)
|
||||||
// go on
|
// go on
|
||||||
@ -55,7 +61,13 @@ func StopEndlessTasks(ctx context.Context) error {
|
|||||||
|
|
||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
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 {
|
}); err != nil {
|
||||||
log.Warn("stop endless task %v: %v", task.ID, err)
|
log.Warn("stop endless task %v: %v", task.ID, err)
|
||||||
// go on
|
// go on
|
||||||
@ -80,8 +92,10 @@ func CancelAbandonedJobs(ctx context.Context) error {
|
|||||||
job.Status = bots_model.StatusCancelled
|
job.Status = bots_model.StatusCancelled
|
||||||
job.Stopped = now
|
job.Stopped = now
|
||||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
_, err := bots_model.UpdateRunJob(ctx, job, nil, "status", "stopped")
|
if _, err := bots_model.UpdateRunJob(ctx, job, nil, "status", "stopped"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
return CreateCommitStatus(ctx, job)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Warn("cancel abandoned job %v: %v", job.ID, err)
|
log.Warn("cancel abandoned job %v: %v", job.ID, err)
|
||||||
// go on
|
// go on
|
||||||
|
Loading…
x
Reference in New Issue
Block a user