code.gitea.io/gitea@v1.22.3/services/automerge/notify.go (about)

     1  // Copyright 2024 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package automerge
     5  
     6  import (
     7  	"context"
     8  
     9  	issues_model "code.gitea.io/gitea/models/issues"
    10  	user_model "code.gitea.io/gitea/models/user"
    11  	"code.gitea.io/gitea/modules/log"
    12  	notify_service "code.gitea.io/gitea/services/notify"
    13  )
    14  
    15  type automergeNotifier struct {
    16  	notify_service.NullNotifier
    17  }
    18  
    19  var _ notify_service.Notifier = &automergeNotifier{}
    20  
    21  // NewNotifier create a new automergeNotifier notifier
    22  func NewNotifier() notify_service.Notifier {
    23  	return &automergeNotifier{}
    24  }
    25  
    26  func (n *automergeNotifier) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
    27  	// as a missing / blocking reviews could have blocked a pending automerge let's recheck
    28  	if review.Type == issues_model.ReviewTypeApprove {
    29  		if err := StartPRCheckAndAutoMergeBySHA(ctx, review.CommitID, pr.BaseRepo); err != nil {
    30  			log.Error("StartPullRequestAutoMergeCheckBySHA: %v", err)
    31  		}
    32  	}
    33  }
    34  
    35  func (n *automergeNotifier) PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
    36  	if err := review.LoadIssue(ctx); err != nil {
    37  		log.Error("LoadIssue: %v", err)
    38  		return
    39  	}
    40  	if err := review.Issue.LoadPullRequest(ctx); err != nil {
    41  		log.Error("LoadPullRequest: %v", err)
    42  		return
    43  	}
    44  	// as reviews could have blocked a pending automerge let's recheck
    45  	StartPRCheckAndAutoMerge(ctx, review.Issue.PullRequest)
    46  }