Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 305581e

Browse files
committedJun 20, 2024·
feat: Add options 'one_of' and 'none_of' for filters and validators
1 parent 196099e commit 305581e

File tree

21 files changed

+789
-46
lines changed

21 files changed

+789
-46
lines changed
 

‎__fixtures__/unit/helper.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ module.exports = {
6565
login: 'creator'
6666
},
6767
number: (options.number) ? options.number : 1
68-
}
68+
},
69+
comment: options.issueComment
6970
},
7071
log: {
7172
child: (s) => {

‎__tests__/unit/filters/author.test.js

+139-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ test('should fail with unexpected author', async () => {
1717
expect(filter.status).toBe('fail')
1818
})
1919

20+
test('should fail with unexpected author one_of author', async () => {
21+
const author = new Author()
22+
const settings = {
23+
do: 'author',
24+
one_of: [otherAuthorName]
25+
}
26+
const filter = await author.processFilter(createMockContext(authorName), settings)
27+
expect(filter.status).toBe('fail')
28+
})
29+
2030
test('should pass with expected author', async () => {
2131
const author = new Author()
2232
const settings = {
@@ -29,6 +39,16 @@ test('should pass with expected author', async () => {
2939
expect(filter.status).toBe('pass')
3040
})
3141

42+
test('should pass with one_of author', async () => {
43+
const author = new Author()
44+
const settings = {
45+
do: 'author',
46+
one_of: [authorName]
47+
}
48+
const filter = await author.processFilter(createMockContext(authorName), settings)
49+
expect(filter.status).toBe('pass')
50+
})
51+
3252
test('should fail with excluded author', async () => {
3353
const author = new Author()
3454
const settings = {
@@ -41,13 +61,21 @@ test('should fail with excluded author', async () => {
4161
expect(filter.status).toBe('fail')
4262
})
4363

44-
test('should pass with excluded author', async () => {
64+
test('should fail with none_of author', async () => {
4565
const author = new Author()
4666
const settings = {
4767
do: 'author',
48-
must_exclude: {
49-
regex: otherAuthorName
50-
}
68+
none_of: [authorName]
69+
}
70+
const filter = await author.processFilter(createMockContext(authorName), settings)
71+
expect(filter.status).toBe('fail')
72+
})
73+
74+
test('should pass with none_of author', async () => {
75+
const author = new Author()
76+
const settings = {
77+
do: 'author',
78+
none_of: [otherAuthorName]
5179
}
5280
const filter = await author.processFilter(createMockContext(authorName), settings)
5381
expect(filter.status).toBe('pass')
@@ -67,6 +95,20 @@ test('should pass with expected author from correct team', async () => {
6795
expect(filter.status).toBe('pass')
6896
})
6997

98+
test('should pass with one_of author from correct team', async () => {
99+
const author = new Author()
100+
const settings = {
101+
do: 'author',
102+
must_include: {
103+
regex: authorName
104+
},
105+
one_of: ['@org/team-slug']
106+
}
107+
Teams.extractTeamMembers = jest.fn().mockReturnValue([authorName])
108+
const filter = await author.processFilter(createMockContext(authorName), settings)
109+
expect(filter.status).toBe('pass')
110+
})
111+
70112
test('should fail with expected author from incorrect team', async () => {
71113
const author = new Author()
72114
const settings = {
@@ -81,6 +123,20 @@ test('should fail with expected author from incorrect team', async () => {
81123
expect(filter.status).toBe('fail')
82124
})
83125

126+
test('should fail with one_of author from incorrect team', async () => {
127+
const author = new Author()
128+
const settings = {
129+
do: 'author',
130+
must_include: {
131+
regex: authorName
132+
},
133+
one_of: ['@org/team-slug']
134+
}
135+
Teams.extractTeamMembers = jest.fn().mockReturnValue([])
136+
const filter = await author.processFilter(createMockContext(authorName), settings)
137+
expect(filter.status).toBe('fail')
138+
})
139+
84140
test('should fail with unexpected author from correct team', async () => {
85141
const author = new Author()
86142
const settings = {
@@ -95,6 +151,20 @@ test('should fail with unexpected author from correct team', async () => {
95151
expect(filter.status).toBe('fail')
96152
})
97153

154+
test('should fail with one_of author from correct team', async () => {
155+
const author = new Author()
156+
const settings = {
157+
do: 'author',
158+
must_include: {
159+
regex: otherAuthorName
160+
},
161+
one_of: ['@org/team-slug']
162+
}
163+
Teams.extractTeamMembers = jest.fn().mockReturnValue([authorName])
164+
const filter = await author.processFilter(createMockContext(authorName), settings)
165+
expect(filter.status).toBe('fail')
166+
})
167+
98168
test('should pass when the author is a member of the team', async () => {
99169
const author = new Author()
100170
const settings = {
@@ -106,6 +176,17 @@ test('should pass when the author is a member of the team', async () => {
106176
expect(filter.status).toBe('pass')
107177
})
108178

179+
test('should pass when the author is one_of the members of the team', async () => {
180+
const author = new Author()
181+
const settings = {
182+
do: 'author',
183+
one_of: ['@org/team-slug']
184+
}
185+
Teams.extractTeamMembers = jest.fn().mockReturnValue([authorName])
186+
const filter = await author.processFilter(createMockContext(authorName), settings)
187+
expect(filter.status).toBe('pass')
188+
})
189+
109190
test('should fail when the author is not a member of the team', async () => {
110191
const author = new Author()
111192
const authorName = 'mergeable'
@@ -118,6 +199,60 @@ test('should fail when the author is not a member of the team', async () => {
118199
expect(filter.status).toBe('fail')
119200
})
120201

202+
test('should fail when the author is not one_of the members of the team', async () => {
203+
const author = new Author()
204+
const authorName = 'mergeable'
205+
const settings = {
206+
do: 'author',
207+
one_of: ['@org/team-slug']
208+
}
209+
Teams.extractTeamMembers = jest.fn().mockReturnValue([otherAuthorName])
210+
const filter = await author.processFilter(createMockContext(authorName), settings)
211+
expect(filter.status).toBe('fail')
212+
})
213+
214+
test('should pass when the author is not member of the none_of team', async () => {
215+
const author = new Author()
216+
const settings = {
217+
do: 'author',
218+
none_of: ['@org/team-slug']
219+
}
220+
Teams.extractTeamMembers = jest.fn().mockReturnValue([otherAuthorName])
221+
const filter = await author.processFilter(createMockContext(authorName), settings)
222+
expect(filter.status).toBe('pass')
223+
})
224+
225+
test('should fail when the author is member of the none_of team', async () => {
226+
const author = new Author()
227+
const settings = {
228+
do: 'author',
229+
none_of: ['@org/team-slug']
230+
}
231+
Teams.extractTeamMembers = jest.fn().mockReturnValue([authorName])
232+
const filter = await author.processFilter(createMockContext(authorName), settings)
233+
expect(filter.status).toBe('fail')
234+
})
235+
236+
test('should pass when the author is one_of @author', async () => {
237+
const author = new Author()
238+
const settings = {
239+
do: 'author',
240+
one_of: ['@author']
241+
}
242+
const filter = await author.processFilter(createMockContext(authorName), settings)
243+
expect(filter.status).toBe('pass')
244+
})
245+
246+
test('should fail when the author is none_of @author', async () => {
247+
const author = new Author()
248+
const settings = {
249+
do: 'author',
250+
none_of: ['@author']
251+
}
252+
const filter = await author.processFilter(createMockContext(authorName), settings)
253+
expect(filter.status).toBe('fail')
254+
})
255+
121256
const createMockContext = (author) => {
122257
return Helper.mockContext({ author })
123258
}

0 commit comments

Comments
 (0)
Please sign in to comment.