diff --git a/lib/checkWipDraftPR.js b/lib/checkWipDraftPR.js index 5ad69005..cebef2ba 100644 --- a/lib/checkWipDraftPR.js +++ b/lib/checkWipDraftPR.js @@ -63,6 +63,10 @@ module.exports.checkWIP = async (context) => { if (isDraftPr(pullRequest) || isWIPPr(pullRequest)) { const hasSkipCIMessage = await isSkipCICommit(context); if (!hasSkipCIMessage) { + // Assign PR author. + var assigneeParams = context.issue({ assignees: [prAuthor] }); + await context.github.issues.addAssignees(assigneeParams); + const link = 'here'.link( 'https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia' + '#wip--draft-pull-requests'); @@ -77,13 +81,6 @@ module.exports.checkWIP = async (context) => { body: commentBody, }); await context.github.issues.createComment(commentParams); - - // Close Pull Request. - const closePRParams = context.repo({ - issue_number: pullRequest.number, - state: 'closed', - }); - await context.github.issues.update(closePRParams); } } }; diff --git a/spec/checkWipDraftPRSpec.js b/spec/checkWipDraftPRSpec.js index 3b00eb32..0dcd277d 100644 --- a/spec/checkWipDraftPRSpec.js +++ b/spec/checkWipDraftPRSpec.js @@ -50,7 +50,7 @@ describe('Oppiabot\'s', () => { github = { issues: { createComment: jasmine.createSpy('createComment').and.resolveTo({}), - update: jasmine.createSpy('update').and.resolveTo({}) + addAssignees: jasmine.createSpy('addAssignees').and.resolveTo({}), } }; @@ -98,6 +98,17 @@ describe('Oppiabot\'s', () => { }); }); + it('assigns PR author', () => { + expect(github.issues.addAssignees).toHaveBeenCalled(); + const params = { + repo: pullRequestEditedPayload.payload.repository.name, + owner: pullRequestEditedPayload.payload.repository.owner.login, + number: pullRequestEditedPayload.payload.pull_request.number, + assignees: ['testuser7777'], + }; + expect(github.issues.addAssignees).toHaveBeenCalledWith(params); + }); + it('creates comment for WIP PRs', () => { expect(github.issues.createComment).toHaveBeenCalled(); expect(github.issues.createComment).toHaveBeenCalledTimes(1); @@ -120,18 +131,6 @@ describe('Oppiabot\'s', () => { body: commentBody }); }); - - it('closes WIP PRs', () => { - expect(github.issues.update).toHaveBeenCalled(); - expect(github.issues.update).toHaveBeenCalledTimes(1); - - expect(github.issues.update).toHaveBeenCalledWith({ - issue_number: pullRequestEditedPayload.payload.pull_request.number, - owner: pullRequestEditedPayload.payload.repository.owner.login, - repo: pullRequestEditedPayload.payload.repository.name, - state: 'closed' - }); - }); }); describe('WIP PRs with skip prefix', () => { @@ -166,12 +165,12 @@ describe('Oppiabot\'s', () => { }); }); - it('does not create comment for WIP PRs', () => { - expect(github.issues.createComment).not.toHaveBeenCalled(); + it('does not assign PR author', () => { + expect(github.issues.addAssignees).not.toHaveBeenCalled(); }); - it('does not close WIP PRs', () => { - expect(github.issues.update).not.toHaveBeenCalled(); + it('does not create comment for WIP PRs', () => { + expect(github.issues.createComment).not.toHaveBeenCalled(); }); }); @@ -191,10 +190,10 @@ describe('Oppiabot\'s', () => { expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalled(); expect(github.git.getCommit).toHaveBeenCalled(); + expect(github.issues.addAssignees).toHaveBeenCalled(); + expect(github.issues.addAssignees).toHaveBeenCalledTimes(1); expect(github.issues.createComment).toHaveBeenCalled(); expect(github.issues.createComment).toHaveBeenCalledTimes(1); - expect(github.issues.update).toHaveBeenCalled(); - expect(github.issues.update).toHaveBeenCalledTimes(1); }); it('should check when PR is reopnend', async() => { @@ -212,10 +211,10 @@ describe('Oppiabot\'s', () => { expect(checkWipDraftPRModule.checkWIP).toHaveBeenCalled(); expect(github.git.getCommit).toHaveBeenCalled(); + expect(github.issues.addAssignees).toHaveBeenCalled(); + expect(github.issues.addAssignees).toHaveBeenCalledTimes(1); expect(github.issues.createComment).toHaveBeenCalled(); expect(github.issues.createComment).toHaveBeenCalledTimes(1); - expect(github.issues.update).toHaveBeenCalled(); - expect(github.issues.update).toHaveBeenCalledTimes(1); }); }); @@ -260,6 +259,18 @@ describe('Oppiabot\'s', () => { expect(args.payload.pull_request.title).toBe('Testing Draft'); }); + + it('assigns PR author', () => { + expect(github.issues.addAssignees).toHaveBeenCalled(); + const params = { + repo: pullRequestEditedPayload.payload.repository.name, + owner: pullRequestEditedPayload.payload.repository.owner.login, + number: pullRequestEditedPayload.payload.pull_request.number, + assignees: ['testuser7777'], + }; + expect(github.issues.addAssignees).toHaveBeenCalledWith(params); + }); + it('creates comment for draft PRs', () => { expect(github.issues.createComment).toHaveBeenCalled(); expect(github.issues.createComment).toHaveBeenCalledTimes(1); @@ -281,18 +292,6 @@ describe('Oppiabot\'s', () => { body: commentBody }); }); - - it('closes draft PRs', () => { - expect(github.issues.update).toHaveBeenCalled(); - expect(github.issues.update).toHaveBeenCalledTimes(1); - - expect(github.issues.update).toHaveBeenCalledWith({ - issue_number: pullRequestEditedPayload.payload.pull_request.number, - owner: pullRequestEditedPayload.payload.repository.owner.login, - repo: pullRequestEditedPayload.payload.repository.name, - state: 'closed' - }); - }); }); describe('Draft PRs with skip prefix', () => { @@ -336,12 +335,12 @@ describe('Oppiabot\'s', () => { expect(args.payload.pull_request.title).toBe('Testing Draft'); }); - it('does not create comment for draft PRs', () => { - expect(github.issues.createComment).not.toHaveBeenCalled(); + it('does not assign PR author', () => { + expect(github.issues.addAssignees).not.toHaveBeenCalled(); }); - it('does not close draft PRs', () => { - expect(github.issues.update).not.toHaveBeenCalled(); + it('does not create comment for draft PRs', () => { + expect(github.issues.createComment).not.toHaveBeenCalled(); }); }); @@ -370,12 +369,12 @@ describe('Oppiabot\'s', () => { expect(github.git.getCommit).not.toHaveBeenCalled(); }); - it('does not create a comment', () => { - expect(github.issues.createComment).not.toHaveBeenCalled(); + it('does not assign PR author', () => { + expect(github.issues.addAssignees).not.toHaveBeenCalled(); }); - it('does not close the PR', ()=> { - expect(github.issues.update).not.toHaveBeenCalled(); + it('does not create a comment', () => { + expect(github.issues.createComment).not.toHaveBeenCalled(); }); }); });