Skip to content

Commit

Permalink
added runOnDraft config (#45)
Browse files Browse the repository at this point in the history
* added runOnDraft config

* remove idea

* remove package lock

* Revert "remove package lock"

This reverts commit 5c7f903

* roll back changes

* remove idea

* added tests
  • Loading branch information
eranelbaz authored Jun 19, 2021
1 parent 3e7fd25 commit 7ba173c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
lib/
coverage/
coverage/
.idea/
18 changes: 13 additions & 5 deletions __tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ describe('handlePullRequest', () => {
)
})

test('skips drafts', async () => {
test.each`
runOnDraft
${true}
${false}
`('skips drafts', async ({ runOnDraft }) => {
const spy = jest.spyOn(core, 'info')

context.payload.pull_request.draft = true
Expand All @@ -97,13 +101,17 @@ describe('handlePullRequest', () => {
numberOfReviewers: 0,
reviewers: ['reviewer1', 'reviewer2', 'reviewer3'],
skipKeywords: ['wip'],
runOnDraft,
} as any

await handler.handlePullRequest(client, context, config)

expect(spy.mock.calls[0][0]).toEqual(
'Skips the process to add reviewers/assignees since PR type is draft'
)
runOnDraft
? expect(spy.mock.calls[0][0]).not.toEqual(
'Skips the process to add reviewers/assignees since PR type is draft'
)
: expect(spy.mock.calls[0][0]).toEqual(
'Skips the process to add reviewers/assignees since PR type is draft'
)
})

test('adds reviewers to pull requests if the configuration is enabled, but no assignees', async () => {
Expand Down
4 changes: 3 additions & 1 deletion src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Config {
useAssigneeGroups: boolean
reviewGroups: { [key: string]: string[] }
assigneeGroups: { [key: string]: string[] }
runOnDraft?: boolean
}

export async function handlePullRequest(
Expand All @@ -41,6 +42,7 @@ export async function handlePullRequest(
addReviewers,
addAssignees,
filterLabels,
runOnDraft,
} = config

if (skipKeywords && utils.includesSkipKeywords(title, skipKeywords)) {
Expand All @@ -49,7 +51,7 @@ export async function handlePullRequest(
)
return
}
if (draft) {
if (!runOnDraft && draft) {
core.info(
'Skips the process to add reviewers/assignees since PR type is draft'
)
Expand Down

0 comments on commit 7ba173c

Please sign in to comment.