diff --git a/spec/api-review-state.spec.ts b/spec/api-review-state.spec.ts index c3e0273..04ad2eb 100644 --- a/spec/api-review-state.spec.ts +++ b/spec/api-review-state.spec.ts @@ -170,7 +170,7 @@ describe('api review', () => { data: [ { user: { id: 1, login: 'ckerr' }, - body: 'Fix this please!', + body: 'API CHANGES REQUESTED', state: 'CHANGES_REQUESTED', }, { @@ -188,6 +188,11 @@ describe('api review', () => { body: 'API DECLINED', state: 'COMMENTED', }, + { + user: { id: 5, login: 'itsananderson' }, + body: 'API CHANGES REQUESTED', + state: 'COMMENTED', + }, ], }); @@ -197,6 +202,7 @@ describe('api review', () => { { login: 'jkleinsc' }, { login: 'nornagon' }, { login: 'ckerr' }, + { login: 'itsananderson' }, ], }); @@ -212,6 +218,7 @@ describe('api review', () => { #### Requested Changes * @ckerr +* @itsananderson #### Declined * @jkleinsc @@ -226,7 +233,7 @@ describe('api review', () => { expect(users).toEqual({ approved: ['codebytere', 'nornagon'], declined: ['jkleinsc'], - requestedChanges: ['ckerr'], + requestedChanges: ['ckerr', 'itsananderson'], }); }); @@ -250,8 +257,8 @@ describe('api review', () => { }, { user: { id: 2, login: 'jkleinsc' }, - body: 'This test is failing!!', - state: 'CHANGES_REQUESTED', + body: 'API CHANGES REQUESTED', + state: 'COMMENTED', submitted_at: '2020-12-10T01:24:55Z', }, ], @@ -269,6 +276,40 @@ describe('api review', () => { }); }); + it('should correctly parse user approvals when a reviewer requests changes and then approves', async () => { + const { pull_request } = loadFixture( + 'api-review-state/pull_request.requested_review_label.json', + ); + + moctokit.pulls.listReviews.mockReturnValue({ + data: [ + { + user: { id: 2, login: 'marshallofsound' }, + body: 'API CHANGES REQUESTED', + state: 'COMMENTED', + submitted_at: '2020-12-09T01:24:55Z', + }, + { + user: { id: 2, login: 'marshallofsound' }, + body: 'API LGTM', + state: 'COMMENTED', + submitted_at: '2020-12-10T01:24:55Z', + }, + ], + }); + + moctokit.teams.listMembersInOrg.mockReturnValue({ + data: [{ login: 'marshallofsound' }], + }); + + const users = await addOrUpdateAPIReviewCheck(moctokit, pull_request); + expect(users).toEqual({ + approved: ['marshallofsound'], + declined: [], + requestedChanges: [], + }); + }); + it(`should correctly update api review check for ${REVIEW_LABELS.APPROVED} label`, async () => { const { pull_request } = loadFixture( 'api-review-state/pull_request.approved_review_label.json', diff --git a/src/api-review-state.ts b/src/api-review-state.ts index 8fb55e2..cc0e052 100644 --- a/src/api-review-state.ts +++ b/src/api-review-state.ts @@ -159,14 +159,15 @@ export async function addOrUpdateAPIReviewCheck(octokit: Context['octokit'], pr: const lgtm = /API LGTM/i; const decline = /API DECLINED/i; + const changesRequested = /API CHANGES REQUESTED/i; // Combine reviews/comments and filter by recency. const filtered = ([...comments, ...reviews] as CommentOrReview[]).reduce((items, item) => { if (!item?.body || !item.user) return items; - const changeRequest = item.state === REVIEW_STATUS.CHANGES_REQUESTED; - const reviewComment = lgtm.test(item.body) || decline.test(item.body); - if (!reviewComment && !changeRequest) return items; + const reviewComment = + lgtm.test(item.body) || decline.test(item.body) || changesRequested.test(item.body); + if (!reviewComment) return items; const prev = items[item.user.id]; if (!prev) { @@ -209,13 +210,13 @@ export async function addOrUpdateAPIReviewCheck(octokit: Context['octokit'], pr: const approved = allReviews.filter((r) => r.body?.match(lgtm)).map((r) => r.user?.login); const declined = allReviews.filter((r) => r.body?.match(decline)).map((r) => r.user?.login); const requestedChanges = allReviews - .filter((r) => r.state === REVIEW_STATUS.CHANGES_REQUESTED) + .filter((r) => r.body?.match(changesRequested)) .map((r) => r.user?.login); log( 'addOrUpdateAPIReviewCheck', LogLevel.INFO, - `PR ${pr.number} has ${approved.length} API LGTMs, ${declined.length} API DECLINEDs, and ${requestedChanges.length} change requests`, + `PR ${pr.number} has ${approved.length} API LGTMs, ${declined.length} API DECLINEDs, and ${requestedChanges.length} API CHANGES REQUESTED`, ); const users = { approved, declined, requestedChanges };