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

added runOnDraft config #45

Merged
merged 7 commits into from
Jun 19, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
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