Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package automerge
|
|
|
|
import (
|
|
"context"
|
|
|
|
git_model "gitea.dev/models/git"
|
|
issues_model "gitea.dev/models/issues"
|
|
repo_model "gitea.dev/models/repo"
|
|
user_model "gitea.dev/models/user"
|
|
"gitea.dev/modules/log"
|
|
"gitea.dev/modules/repository"
|
|
"gitea.dev/services/automergequeue"
|
|
notify_service "gitea.dev/services/notify"
|
|
pull_service "gitea.dev/services/pull"
|
|
)
|
|
|
|
type automergeNotifier struct {
|
|
notify_service.NullNotifier
|
|
}
|
|
|
|
var _ notify_service.Notifier = &automergeNotifier{}
|
|
|
|
// NewNotifier create a new automergeNotifier notifier
|
|
func NewNotifier() notify_service.Notifier {
|
|
return &automergeNotifier{}
|
|
}
|
|
|
|
func (n *automergeNotifier) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
|
|
// as a missing / blocking reviews could have blocked a pending automerge let's recheck
|
|
if review.Type == issues_model.ReviewTypeApprove {
|
|
automergequeue.StartAutoMergeCheckByPullHead(ctx, pr)
|
|
}
|
|
}
|
|
|
|
func (n *automergeNotifier) PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
|
|
if err := review.LoadIssue(ctx); err != nil {
|
|
log.Error("LoadIssue: %v", err)
|
|
return
|
|
}
|
|
if err := review.Issue.LoadPullRequest(ctx); err != nil {
|
|
log.Error("LoadPullRequest: %v", err)
|
|
return
|
|
}
|
|
// as reviews could have blocked a pending automerge let's recheck
|
|
automergequeue.StartAutoMergeCheckByPullHead(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() {
|
|
return
|
|
}
|
|
|
|
pulls, err := pull_service.GetMergeablePullRequestsByHeadCommitID(ctx, repo, commit.Sha1)
|
|
if err != nil {
|
|
log.Error("GetMergeablePullRequestsByHeadCommitID: %v", err)
|
|
return
|
|
}
|
|
for _, pr := range pulls {
|
|
automergequeue.StartAutoMergeCheckByPullHead(ctx, pr)
|
|
}
|
|
}
|