From 4765176d9b303407db9ac4a810b1266488643a56 Mon Sep 17 00:00:00 2001 From: Davide Violante Date: Tue, 19 Jan 2021 16:08:34 +0100 Subject: [PATCH] Add support for requested_teams in reviews (#13) * Add support for requested_teams in reviews * Fix tests for requested_teams * Run build * Add pr.title to teams too * Add support for teams as reviewers --- README.md | 2 +- dist/index.js | 9 +++++++- functions.js | 9 +++++++- package-lock.json | 2 +- package.json | 2 +- test/test.js | 54 +++++++++++++++++++++++++++++++++++++++++------ 6 files changed, 67 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 88eee97..c81d12f 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ jobs: pr-reviews-reminder: runs-on: ubuntu-latest steps: - - uses: davideviolante/pr-reviews-reminder-action@v1.4.2 + - uses: davideviolante/pr-reviews-reminder-action@v1.5.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: diff --git a/dist/index.js b/dist/index.js index 3771ec1..01314e7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -445,7 +445,7 @@ module.exports = __webpack_require__(352); /***/ (function(module) { function getPullRequestsWithRequestedReviewers(pullRequests) { - return pullRequests.filter(pr => pr.requested_reviewers.length); + return pullRequests.filter(pr => pr.requested_reviewers.length || pr.requested_teams.length); } function createPr2UserArray(pullRequestsWithRequestedReview) { @@ -458,6 +458,13 @@ function createPr2UserArray(pullRequestsWithRequestedReview) { login: user.login }); } + for (const team of pr.requested_teams) { + pr2user.push({ + url: pr.html_url, + title: pr.title, + login: team.slug + }); + } } return pr2user; } diff --git a/functions.js b/functions.js index 560096e..7805a53 100644 --- a/functions.js +++ b/functions.js @@ -1,5 +1,5 @@ function getPullRequestsWithRequestedReviewers(pullRequests) { - return pullRequests.filter(pr => pr.requested_reviewers.length); + return pullRequests.filter(pr => pr.requested_reviewers.length || pr.requested_teams.length); } function createPr2UserArray(pullRequestsWithRequestedReview) { @@ -12,6 +12,13 @@ function createPr2UserArray(pullRequestsWithRequestedReview) { login: user.login }); } + for (const team of pr.requested_teams) { + pr2user.push({ + url: pr.html_url, + title: pr.title, + login: team.slug + }); + } } return pr2user; } diff --git a/package-lock.json b/package-lock.json index 46453ad..2e07325 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "pr-reviews-reminder-action", - "version": "1.4.2", + "version": "1.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2270b99..b3b3553 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pr-reviews-reminder-action", - "version": "1.4.2", + "version": "1.5.0", "description": "Reminder for Pull Request pending reviews", "scripts": { "build": "ncc build index.js", diff --git a/test/test.js b/test/test.js index 497c088..3d266a1 100644 --- a/test/test.js +++ b/test/test.js @@ -12,6 +12,7 @@ const provider = 'slack'; const mockPullRequests = [ { number: 1, + title: 'Title1', html_url: 'https://example.com/1', requested_reviewers: [ { @@ -20,31 +21,66 @@ const mockPullRequests = [ { login: 'User2' } - ] + ], + requested_teams: [] }, { number: 2, + title: 'Title2', html_url: 'https://example.com/2', - requested_reviewers: [] + requested_reviewers: [], + requested_teams: [] }, { number: 3, + title: 'Title3', html_url: 'https://example.com/3', requested_reviewers: [ { login: 'User3' } + ], + requested_teams: [] + }, + { + number: 4, + title: 'Title4', + html_url: 'https://example.com/4', + requested_reviewers: [], + requested_teams: [ + { + slug: 'Team1' + } + ] + }, + { + number: 5, + title: 'Title5', + html_url: 'https://example.com/5', + requested_reviewers: [ + { + login: 'User3' + } + ], + requested_teams: [ + { + slug: 'Team1' + } ] } ]; const mockPullRequestsNoReviewers = [ { number: 1, - requested_reviewers: [] + title: 'Title1', + requested_reviewers: [], + requested_teams: [] }, { number: 2, - requested_reviewers: [] + title: 'Title2', + requested_reviewers: [], + requested_teams: [] } ]; const mockPullRequestsNoData = []; @@ -84,7 +120,7 @@ describe('Pull Request Reviews Reminder Action tests', () => { it('Should get pull requests with requested reviewers (some reviewers)', () => { const pullRequests = getPullRequestsWithRequestedReviewers(mockPullRequests); - assert.strictEqual(pullRequests.length, 2); + assert.strictEqual(pullRequests.length, 4); }); it('Should get pull requests with requested reviewers (no reviewers)', () => { @@ -99,13 +135,19 @@ describe('Pull Request Reviews Reminder Action tests', () => { it('Should create the array with pr and users (some reviewers)', () => { const array = createPr2UserArray(mockPullRequests); - assert.strictEqual(array.length, 3); + assert.strictEqual(array.length, 6); assert.strictEqual(array[0].login, 'User1'); assert.strictEqual(array[0].url, 'https://example.com/1'); assert.strictEqual(array[1].login, 'User2'); assert.strictEqual(array[1].url, 'https://example.com/1'); assert.strictEqual(array[2].login, 'User3'); assert.strictEqual(array[2].url, 'https://example.com/3'); + assert.strictEqual(array[3].login, 'Team1'); + assert.strictEqual(array[3].url, 'https://example.com/4'); + assert.strictEqual(array[4].login, 'User3'); + assert.strictEqual(array[4].url, 'https://example.com/5'); + assert.strictEqual(array[5].login, 'Team1'); + assert.strictEqual(array[5].url, 'https://example.com/5'); }); it('Should create the array with pr and users (no reviewers)', () => {