Skip to content

Commit

Permalink
Add support for requested_teams in reviews (#13)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
DavideViolante authored Jan 19, 2021
1 parent 82755fe commit 4765176
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
9 changes: 8 additions & 1 deletion functions.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
54 changes: 48 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const provider = 'slack';
const mockPullRequests = [
{
number: 1,
title: 'Title1',
html_url: 'https://example.com/1',
requested_reviewers: [
{
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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)', () => {
Expand All @@ -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)', () => {
Expand Down

0 comments on commit 4765176

Please sign in to comment.