Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disallow self approval #73

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions plugins/auto_merge/checks/has_assignee.go
Original file line number Diff line number Diff line change
@@ -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"
}
6 changes: 3 additions & 3 deletions plugins/auto_merge/checks/has_enough_approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) && approver.User.Username != assignee.Username {
lukashass marked this conversation as resolved.
Show resolved Hide resolved
approvedBy = append(approvedBy, approver.User.Username)
}
}
Expand Down
1 change: 1 addition & 0 deletions plugins/auto_merge/merge_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (plugin AutoMergePlugin) setupMergeChecks() {
checks.HasNoConflictsCheck{},
checks.HasNoOpenDiscussionsCheck{Client: plugin.Client},
checks.IsNotWorkInProgressCheck{},
checks.HasAssignee{},
checks.PassesCICheck{
Client: plugin.Client,
},
Expand Down
Loading