Skip to content

Commit a9e99c0

Browse files
authored
feat: Add ignore_drafts option to ignore drafts in stale validator (#567)
* Add `ignore_drafts` option to ignore drafts in stale validator * Update changelog
1 parent 6971dfa commit a9e99c0

File tree

4 files changed

+25
-63
lines changed

4 files changed

+25
-63
lines changed

__tests__/unit/validators/stale.test.js

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,17 @@ describe('metadata queries', () => {
5555

5656
})
5757

58-
test('will set milestones correctly', async () => {
59-
const settings = { do: 'stale', days: 10, ignore_milestones: true }
58+
test.each([
59+
{ draft: true, milestones: true, projects: true },
60+
{ draft: false, milestones: true, projects: true },
61+
{ draft: true, milestones: false, projects: true },
62+
{ draft: true, milestones: true, projects: false },
63+
{ draft: false, milestones: false, projects: true },
64+
{ draft: true, milestones: false, projects: false },
65+
{ draft: false, milestones: true, projects: false },
66+
{ draft: false, milestones: false, projects: false }
67+
])('will set %s correctly', async ({ draft, milestones, projects }) => {
68+
const settings = { do: 'stale', days: 10, ignore_drafts: draft, ignore_milestones: milestones, ignore_projects: projects }
6069

6170
const stale = new Stale()
6271
const context = createMockContext([
@@ -68,64 +77,7 @@ describe('metadata queries', () => {
6877
// no types specified so we assume both types. Hence none passed to search API.
6978
expect(isParamsNoType(context)).toBe(true)
7079
expect(isParamsNoLabel(context)).toBe(true)
71-
expect(isMetadataIncluded(context, false, true)).toBe(true)
72-
expect(results.schedule.issues.length).toBe(1)
73-
expect(results.schedule.pulls.length).toBe(1)
74-
expect(results.status).toBe('pass')
75-
})
76-
77-
test('will set projects correctly', async () => {
78-
const settings = { do: 'stale', days: 10, ignore_projects: true }
79-
80-
const stale = new Stale()
81-
const context = createMockContext([
82-
{ number: 1 },
83-
{ number: 2, pull_request: {} }
84-
])
85-
86-
const results = await stale.processValidate(context, settings)
87-
// no types specified so we assume both types. Hence none passed to search API.
88-
expect(isParamsNoType(context)).toBe(true)
89-
expect(isParamsNoLabel(context)).toBe(true)
90-
expect(isMetadataIncluded(context, true, false)).toBe(true)
91-
expect(results.schedule.issues.length).toBe(1)
92-
expect(results.schedule.pulls.length).toBe(1)
93-
expect(results.status).toBe('pass')
94-
})
95-
96-
test('will not set milestones and projects if not specified', async () => {
97-
const settings = { do: 'stale', days: 10 }
98-
99-
const stale = new Stale()
100-
const context = createMockContext([
101-
{ number: 1 },
102-
{ number: 2, pull_request: {} }
103-
])
104-
105-
const results = await stale.processValidate(context, settings)
106-
// no types specified so we assume both types. Hence none passed to search API.
107-
expect(isParamsNoType(context)).toBe(true)
108-
expect(isParamsNoLabel(context)).toBe(true)
109-
expect(isMetadataIncluded(context, false, false)).toBe(true)
110-
expect(results.schedule.issues.length).toBe(1)
111-
expect(results.schedule.pulls.length).toBe(1)
112-
expect(results.status).toBe('pass')
113-
})
114-
115-
test('will set projects and milestones correctly', async () => {
116-
const settings = { do: 'stale', days: 10, ignore_projects: true, ignore_milestones: true }
117-
118-
const stale = new Stale()
119-
const context = createMockContext([
120-
{ number: 1 },
121-
{ number: 2, pull_request: {} }
122-
])
123-
124-
const results = await stale.processValidate(context, settings)
125-
// no types specified so we assume both types. Hence none passed to search API.
126-
expect(isParamsNoType(context)).toBe(true)
127-
expect(isParamsNoLabel(context)).toBe(true)
128-
expect(isMetadataIncluded(context, true, true)).toBe(true)
80+
expect(isMetadataIncluded(context, draft, milestones, projects)).toBe(true)
12981
expect(results.schedule.issues.length).toBe(1)
13082
expect(results.schedule.pulls.length).toBe(1)
13183
expect(results.status).toBe('pass')
@@ -396,10 +348,14 @@ const isParamsNoLabel = (context) => {
396348
).length === 0
397349
}
398350

399-
const isMetadataIncluded = (context, project, milestone) => {
351+
const isMetadataIncluded = (context, draft, milestone, project) => {
400352
return context.octokit.search.issuesAndPullRequests.mock.calls
401353
.filter(
402-
param => (milestone === param[0].q.includes('no:milestone')) && (project === param[0].q.includes('no:project'))
354+
param =>
355+
(draft === param[0].q.includes('-is:draft')) &&
356+
(project === param[0].q.includes('no:project')) &&
357+
(milestone === param[0].q.includes('no:milestone')) &&
358+
true
403359
).length !== 0
404360
}
405361

docs/changelog.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CHANGELOG
22
=====================================
3-
| July 12, 2921 : feat: Filter specific status of files in changeset `#550 <https://github.com/mergeability/mergeable/issues/550>`_
3+
| July 19, 2021 : feat: Add ignore_drafts option to ignore drafts in stale validator `#565 <https://github.com/mergeability/mergeable/issues/565>`_
4+
| July 12, 2021 : feat: Filter specific status of files in changeset `#550 <https://github.com/mergeability/mergeable/issues/550>`_
45
| June 26, 2021 : feat: Add `payload` filter `#398 <https://github.com/mergeability/mergeable/issues/398>`_
56
| March 31, 2021 : feat: add chart support to prometheus servicemonitor `#535 <https://github.com/mergeability/mergeable/pull/535>`_
67
| March 30, 2021 : fix: codeowners team

docs/validators/stale.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Stale
66
- do: stale
77
days: 20 # number of days ago.
88
type: pull_request, issues # what items to search for.
9+
ignore_drafts: true # if set to true, the stale check will ignore draft items
910
ignore_milestones: true # if set to true, the stale check will ignore items that have an associated milestone
1011
ignore_projects: true # if set to true, the stale check will ignore items that have an associated project
1112
label: # optional property to filter the items that are actioned upon

lib/validators/stale.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Stale extends Validator {
2727
match: 'array',
2828
ignore: 'array'
2929
},
30+
ignore_drafts: 'boolean',
3031
ignore_milestones: 'boolean',
3132
ignore_projects: 'boolean',
3233
time_constraint: {
@@ -70,6 +71,9 @@ class Stale extends Validator {
7071
const labelMatchQuery = (label.match || []).map(label => `label:"${label}"`)
7172
const labelIgnoreQuery = (label.ignore || []).map(label => `-label:"${label}"`)
7273
let ignoreQuery = ''
74+
if (validationSettings.ignore_drafts) {
75+
ignoreQuery += '-is:draft '
76+
}
7377
if (validationSettings.ignore_milestones) {
7478
ignoreQuery += 'no:milestone '
7579
}

0 commit comments

Comments
 (0)