Skip to content

Commit f7f037b

Browse files
feat: Add validator approval option to exclude users (#594)
* Add validator `approval` option to exclude users * Add unit test * Add feature to changelog * Add exclude option to docs
1 parent 62f007c commit f7f037b

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

__tests__/unit/validators/approvals.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,30 @@ test('mergeable is false if required member(s) has not approved', async () => {
115115
expect(validation.validations[0].description).toBe('approval: userC required')
116116
})
117117

118+
test('mergeable is false if excluded member(s) has approved', async () => {
119+
const approval = new Approval()
120+
const reviewList = [
121+
{
122+
user: {
123+
login: 'userA'
124+
},
125+
state: 'APPROVED'
126+
}
127+
]
128+
const settings = {
129+
do: 'approval',
130+
min: {
131+
count: 1
132+
},
133+
exclude: {
134+
users: ['userA']
135+
}
136+
}
137+
138+
const validation = await approval.processValidate(createMockContext(5, reviewList), settings)
139+
expect(validation.validations[0].description).toBe('approval count is less than "1"')
140+
})
141+
118142
test('mergeable passes if required user has approved', async () => {
119143
const approval = new Approval()
120144
const reviewList = [

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CHANGELOG
22
=====================================
3+
| October 19, 2021 : feat: Add validator approval option to exclude users `#594 <https://github.com/mergeability/mergeable/pull/594>`_
34
| October 12, 2021 : feat: Add boolean option for payload filter `#583 <https://github.com/mergeability/mergeable/pull/583>`_
45
| September 27, 2021 : fix: use node version 14.17.6 for the release action `#591 <https://github.com/mergeability/mergeable/pull/591>`_
56
| September 25, 2021 : feat: Support for objects in arrays in the payload filter `#589 <https://github.com/mergeability/mergeable/pull/589>`_

docs/validators/approval.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Approvals
2020
teams: ['org/team_slug'] # when the option is present, only the approvals from the team members will count
2121
users: ['user1', 'user2'] # when the option is present, approvals from users in this list will count
2222
owners: true # Optional boolean. When true, the file .github/CODEOWNER is read and only owners approval will count
23+
exclude:
24+
users: ['bot1', 'bot2'] # when the option is present, approvals from users in this list will NOT count
2325

2426

2527
.. note::

lib/validators/approvals.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class Approvals extends Validator {
4242
teams: 'array',
4343
users: 'array',
4444
owners: 'boolean'
45+
},
46+
exclude: {
47+
users: 'array'
4548
}
4649
}
4750
}
@@ -66,6 +69,12 @@ class Approvals extends Validator {
6669
delete validationSettings.limit
6770
}
6871

72+
let excludeOption = null
73+
if (validationSettings.exclude) {
74+
excludeOption = validationSettings.exclude
75+
delete validationSettings.exclude
76+
}
77+
6978
const reviews = await this.githubAPI.listReviews(context, this.getPayload(context).number)
7079

7180
const {
@@ -112,6 +121,10 @@ class Approvals extends Validator {
112121
}))
113122
}
114123

124+
if (excludeOption) {
125+
if (excludeOption.users) approvedReviewers = _.without(approvedReviewers, ...excludeOption.users)
126+
}
127+
115128
const optionProcessed = await this.processOptions(validationSettings, approvedReviewers)
116129
output = [...output, ...optionProcessed]
117130

0 commit comments

Comments
 (0)