mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-29 17:20:39 +00:00
60326ca03d
* Refactor "automerge" related code, clarify many details (including "unique queue item", start check by pull head or commit) * Fix automerge queue handler's error handling, clarify error messages * Populate recent automerge tasks on restart to restore the previous aborted automerge tasks Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
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)
|
|
}
|
|
}
|