Skip to content

Commit 6e633df

Browse files
committedFeb 17, 2018
pr_summary: warn if we can't fetch author's name and email
This displays a warning if we cannot fetch user's name and email from github api, instead of displaying blank and null output in the author field (cli table). Refs: nodejs/node#18721 Fixes: nodejs/node-core-utils#180
1 parent fd05a42 commit 6e633df

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed
 

‎lib/pr_summary.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,16 @@ class PRSummary {
3434
cli.table('Title', `${title} (#${prid})`);
3535
const authorHint =
3636
this.data.authorIsNew() ? ', first-time contributor' : '';
37-
cli.table('Author',
38-
`${author.name} <${author.email}> (@${author.login}${authorHint})`);
37+
38+
if (author.name && author.email) {
39+
cli.table('Author',
40+
`${author.name} <${author.email}> (@${author.login}${authorHint})`);
41+
} else {
42+
// Unable to retrive email/name of the PR Author
43+
cli.warn('Could not retrieve the email or name ' +
44+
"of the PR author's from user's GitHub profile!");
45+
}
46+
3947
cli.table('Branch', `${branch}`);
4048
cli.table('Labels', `${labelStr}`);
4149

‎test/fixtures/data.js

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const firstTimerPrivatePR = readJSON('first_timer_pr_with_private_email.json');
5959
const semverMajorPR = readJSON('semver_major_pr.json');
6060
const fixAndRefPR = readJSON('pr_with_fixes_and_refs.json');
6161
const conflictingPR = readJSON('conflicting_pr.json');
62+
const emptyProfilePR = readJSON('empty_profile_pr.json');
6263
const closedPR = readJSON('./closed_pr.json');
6364
const mergedPR = readJSON('./merged_pr.json');
6465
const readme = readFile('./README/README.md');
@@ -90,6 +91,7 @@ module.exports = {
9091
semverMajorPR,
9192
fixAndRefPR,
9293
conflictingPR,
94+
emptyProfilePR,
9395
readme,
9496
readmeNoTsc,
9597
readmeNoTscE,

‎test/fixtures/empty_profile_pr.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"createdAt": "2017-10-24T11:13:43Z",
3+
"authorAssociation": "COLLABORATOR",
4+
"author": {
5+
"login": "pr_author",
6+
"email": "",
7+
"name": null
8+
},
9+
"url": "https://github.com/nodejs/node/pull/18721",
10+
"bodyHTML": "<p>Fix mdn links</p>",
11+
"bodyText": "Fix mdn links",
12+
"labels": {
13+
"nodes": [
14+
{
15+
"name": "doc"
16+
}
17+
]
18+
},
19+
"title": "doc: fix mdn links",
20+
"baseRefName": "master",
21+
"headRefName": "fix-links"
22+
}

‎test/unit/pr_summary.test.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const {
44
oddCommits,
55
simpleCommits,
66
firstTimerPR,
7-
semverMajorPR
7+
semverMajorPR,
8+
emptyProfilePR
89
} = require('../fixtures/data');
910
const TestCLI = require('../fixtures/test_cli');
1011
const PRSummary = require('../../lib/pr_summary');
@@ -86,4 +87,37 @@ describe('PRSummary', () => {
8687
summary.display();
8788
cli.assertCalledWith(expectedLogs);
8889
});
90+
91+
it('displays warning if pr author/email is not present', () => {
92+
const cli = new TestCLI();
93+
const prData = {
94+
pr: emptyProfilePR,
95+
commits: simpleCommits,
96+
authorIsNew() {
97+
return false;
98+
}
99+
};
100+
101+
const expectedLogs = {
102+
log: [
103+
[' - doc: some changes'],
104+
[' - Their Github Account email <pr_author@example.com>']
105+
],
106+
table: [
107+
['Title', 'doc: fix mdn links (#16348)'],
108+
['Branch', 'pr_author:fix-links -> nodejs:master'],
109+
['Labels', 'doc'],
110+
['Commits', '1'],
111+
['Committers', '1']
112+
],
113+
warn: [
114+
['Could not retrieve the email or name ' +
115+
"of the PR author's from user's GitHub profile!"]
116+
]
117+
};
118+
119+
const summary = new PRSummary(argv, cli, prData);
120+
summary.display();
121+
cli.assertCalledWith(expectedLogs);
122+
});
89123
});

0 commit comments

Comments
 (0)
Please sign in to comment.