diff options
Diffstat (limited to 'services')
-rw-r--r-- | services/actions/commit_status.go | 6 | ||||
-rw-r--r-- | services/automerge/notify.go | 11 | ||||
-rw-r--r-- | services/notify/notifier.go | 3 | ||||
-rw-r--r-- | services/notify/notify.go | 7 | ||||
-rw-r--r-- | services/notify/null.go | 4 | ||||
-rw-r--r-- | services/repository/commitstatus/commitstatus.go | 11 | ||||
-rw-r--r-- | services/webhook/notifier.go | 31 |
7 files changed, 62 insertions, 11 deletions
diff --git a/services/actions/commit_status.go b/services/actions/commit_status.go index 8d86ec4dfa..7f52c9d31b 100644 --- a/services/actions/commit_status.go +++ b/services/actions/commit_status.go @@ -128,18 +128,16 @@ func createCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er if err != nil { return fmt.Errorf("HashTypeInterfaceFromHashString: %w", err) } - if err := commitstatus_service.CreateCommitStatus(ctx, repo, creator, commitID.String(), &git_model.CommitStatus{ + status := git_model.CommitStatus{ SHA: sha, TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), index), Description: description, Context: ctxname, CreatorID: creator.ID, State: state, - }); err != nil { - return fmt.Errorf("NewCommitStatus: %w", err) } - return nil + return commitstatus_service.CreateCommitStatus(ctx, repo, creator, commitID.String(), &status) } func toCommitStatus(status actions_model.Status) api.CommitStatusState { diff --git a/services/automerge/notify.go b/services/automerge/notify.go index cb078214f6..b6bbca333b 100644 --- a/services/automerge/notify.go +++ b/services/automerge/notify.go @@ -6,9 +6,12 @@ package automerge import ( "context" + git_model "code.gitea.io/gitea/models/git" issues_model "code.gitea.io/gitea/models/issues" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/repository" notify_service "code.gitea.io/gitea/services/notify" ) @@ -44,3 +47,11 @@ func (n *automergeNotifier) PullReviewDismiss(ctx context.Context, doer *user_mo // as reviews could have blocked a pending automerge let's recheck StartPRCheckAndAutoMerge(ctx, review.Issue.PullRequest) } + +func (n *automergeNotifier) CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit *repository.PushCommit, sender *user_model.User, status *git_model.CommitStatus) { + if status.State.IsSuccess() { + if err := StartPRCheckAndAutoMergeBySHA(ctx, commit.Sha1, repo); err != nil { + log.Error("MergeScheduledPullRequest[repo_id: %d, user_id: %d, sha: %s]: %w", repo.ID, sender.ID, commit.Sha1, err) + } + } +} diff --git a/services/notify/notifier.go b/services/notify/notifier.go index ed053a812a..29bbb5702b 100644 --- a/services/notify/notifier.go +++ b/services/notify/notifier.go @@ -6,6 +6,7 @@ package notify import ( "context" + git_model "code.gitea.io/gitea/models/git" issues_model "code.gitea.io/gitea/models/issues" packages_model "code.gitea.io/gitea/models/packages" repo_model "code.gitea.io/gitea/models/repo" @@ -74,4 +75,6 @@ type Notifier interface { PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) + + CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit *repository.PushCommit, sender *user_model.User, status *git_model.CommitStatus) } diff --git a/services/notify/notify.go b/services/notify/notify.go index 0c8262ef7a..3b5f24340b 100644 --- a/services/notify/notify.go +++ b/services/notify/notify.go @@ -6,6 +6,7 @@ package notify import ( "context" + git_model "code.gitea.io/gitea/models/git" issues_model "code.gitea.io/gitea/models/issues" packages_model "code.gitea.io/gitea/models/packages" repo_model "code.gitea.io/gitea/models/repo" @@ -367,3 +368,9 @@ func ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) { notifier.ChangeDefaultBranch(ctx, repo) } } + +func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit *repository.PushCommit, sender *user_model.User, status *git_model.CommitStatus) { + for _, notifier := range notifiers { + notifier.CreateCommitStatus(ctx, repo, commit, sender, status) + } +} diff --git a/services/notify/null.go b/services/notify/null.go index dddd421bef..7354efd701 100644 --- a/services/notify/null.go +++ b/services/notify/null.go @@ -6,6 +6,7 @@ package notify import ( "context" + git_model "code.gitea.io/gitea/models/git" issues_model "code.gitea.io/gitea/models/issues" packages_model "code.gitea.io/gitea/models/packages" repo_model "code.gitea.io/gitea/models/repo" @@ -208,3 +209,6 @@ func (*NullNotifier) PackageDelete(ctx context.Context, doer *user_model.User, p // ChangeDefaultBranch places a place holder function func (*NullNotifier) ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) { } + +func (*NullNotifier) CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit *repository.PushCommit, sender *user_model.User, status *git_model.CommitStatus) { +} diff --git a/services/repository/commitstatus/commitstatus.go b/services/repository/commitstatus/commitstatus.go index adc59abed8..f369a303e6 100644 --- a/services/repository/commitstatus/commitstatus.go +++ b/services/repository/commitstatus/commitstatus.go @@ -18,8 +18,9 @@ import ( "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" + repo_module "code.gitea.io/gitea/modules/repository" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/services/automerge" + "code.gitea.io/gitea/services/notify" ) func getCacheKey(repoID int64, brancheName string) string { @@ -103,6 +104,8 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato return err } + notify.CreateCommitStatus(ctx, repo, repo_module.CommitToPushCommit(commit), creator, status) + defaultBranchCommit, err := gitRepo.GetBranchCommit(repo.DefaultBranch) if err != nil { return fmt.Errorf("GetBranchCommit[%s]: %w", repo.DefaultBranch, err) @@ -114,12 +117,6 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato } } - if status.State.IsSuccess() { - if err := automerge.StartPRCheckAndAutoMergeBySHA(ctx, sha, repo); err != nil { - return fmt.Errorf("MergeScheduledPullRequest[repo_id: %d, user_id: %d, sha: %s]: %w", repo.ID, creator.ID, sha, err) - } - } - return nil } diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index 38fad7f5e8..cc263947e9 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -6,6 +6,7 @@ package webhook import ( "context" + git_model "code.gitea.io/gitea/models/git" issues_model "code.gitea.io/gitea/models/issues" packages_model "code.gitea.io/gitea/models/packages" "code.gitea.io/gitea/models/perm" @@ -861,6 +862,36 @@ func (m *webhookNotifier) SyncPushCommits(ctx context.Context, pusher *user_mode } } +func (m *webhookNotifier) CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit *repository.PushCommit, sender *user_model.User, status *git_model.CommitStatus) { + apiSender := convert.ToUser(ctx, sender, nil) + apiCommit, err := repository.ToAPIPayloadCommit(ctx, map[string]*user_model.User{}, repo.RepoPath(), repo.HTMLURL(), commit) + if err != nil { + log.Error("commits.ToAPIPayloadCommits failed: %v", err) + return + } + + payload := api.CommitStatusPayload{ + Context: status.Context, + CreatedAt: status.CreatedUnix.AsTime().UTC(), + Description: status.Description, + ID: status.ID, + SHA: commit.Sha1, + State: status.State.String(), + TargetURL: status.TargetURL, + + Commit: apiCommit, + Repo: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), + Sender: apiSender, + } + if !status.UpdatedUnix.IsZero() { + t := status.UpdatedUnix.AsTime().UTC() + payload.UpdatedAt = &t + } + if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventStatus, &payload); err != nil { + log.Error("PrepareWebhooks: %v", err) + } +} + func (m *webhookNotifier) SyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) { m.CreateRef(ctx, pusher, repo, refFullName, refID) } |