diff --git a/plugins/auto_merge/checks/has_assignee.go b/plugins/auto_merge/checks/has_assignee.go new file mode 100644 index 0000000..58a45ba --- /dev/null +++ b/plugins/auto_merge/checks/has_assignee.go @@ -0,0 +1,25 @@ +package checks + +import ( + "github.com/GEPROG/lassie-bot-dog/plugins/auto_merge/config" + "github.com/xanzy/go-gitlab" +) + +type HasAssignee struct { +} + +func (check HasAssignee) Check(_ *config.AutoMergeConfig, _ *gitlab.Project, mergeRequest *gitlab.MergeRequest) bool { + return mergeRequest.Assignee != nil +} + +func (check HasAssignee) Name() string { + return "has-assignee" +} + +func (check HasAssignee) PassedText(_ int) string { + return "Someone is assigned to your Merge-Request" +} + +func (check HasAssignee) FailedText(_ int) string { + return "No one is assigned to your Merge-Request" +} diff --git a/plugins/auto_merge/checks/has_enough_approvals.go b/plugins/auto_merge/checks/has_enough_approvals.go index 665976c..f7d2088 100644 --- a/plugins/auto_merge/checks/has_enough_approvals.go +++ b/plugins/auto_merge/checks/has_enough_approvals.go @@ -36,7 +36,7 @@ func (check HasEnoughApprovalsCheck) Check(config *config.AutoMergeConfig, proje } // get amount of users that need to approve and already approved - approvedBy := len(check.getApprovals(approvals.ApprovedBy, neededApproval.Users)) + approvedBy := len(check.getApprovals(approvals.ApprovedBy, neededApproval.Users, mergeRequest.Assignee)) atLeast := utils.Max(neededApproval.AtLeast, 1) if approvedBy < atLeast { @@ -64,11 +64,11 @@ func (check HasEnoughApprovalsCheck) FailedText(mergeRequestID int) string { return fmt.Sprintf("You still need some review for your changes %s", missingLabels) } -func (check HasEnoughApprovalsCheck) getApprovals(approvedByAll []*gitlab.MergeRequestApproverUser, possibleApprovers []string) []string { +func (check HasEnoughApprovalsCheck) getApprovals(approvedByAll []*gitlab.MergeRequestApproverUser, possibleApprovers []string, assignee *gitlab.BasicUser) []string { var approvedBy []string for _, approver := range approvedByAll { - if utils.StringInSlice(approver.User.Username, possibleApprovers) { + if utils.StringInSlice(approver.User.Username, possibleApprovers) && (assignee == nil || approver.User.Username != assignee.Username) { approvedBy = append(approvedBy, approver.User.Username) } } diff --git a/plugins/auto_merge/merge_checks.go b/plugins/auto_merge/merge_checks.go index 94c84ad..b91bc5e 100644 --- a/plugins/auto_merge/merge_checks.go +++ b/plugins/auto_merge/merge_checks.go @@ -70,6 +70,7 @@ func (plugin AutoMergePlugin) setupMergeChecks() { checks.HasNoConflictsCheck{}, checks.HasNoOpenDiscussionsCheck{Client: plugin.Client}, checks.IsNotWorkInProgressCheck{}, + checks.HasAssignee{}, checks.PassesCICheck{ Client: plugin.Client, },