forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview-pr
executable file
·60 lines (47 loc) · 1.88 KB
/
review-pr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
const shell = require('shelljs');
shell.config.fatal = true;
const util = require('./utils/git_util');
if (require.main === module) {
main(process.argv.splice(2)).then(
(v) => process.exitCode = v,
(e) => console.error(process.exitCode = 1, e)
);
}
async function main(args) {
let prNumber = 0;
args.forEach((arg) => {
if (prNumber == 0 && arg > 0) {
prNumber = arg;
} else {
shell.echo('Unexpected argument: ', arg);
}
});
if (prNumber === 0) {
shell.echo('Bring github pull request onto your local repo for review and edit');
shell.echo('');
shell.echo(`${process.argv[1]} PR_NUMBER`);
shell.echo('');
return 1;
}
if (util.gitHasLocalModifications()) {
shell.echo('Local modification detected. exiting...');
return 1;
}
let prShaCount = (await util.githubPrInfo(prNumber)).commits;
shell.exec(`git checkout master`);
if (util.execNoFatal(`git rev-parse --verify --quiet pr/${prNumber}`).code == 0) {
shell.exec(`git branch -D pr/${prNumber}`);
}
shell.echo(`Fetching pull request #${prNumber} with ${prNumber} SHA(s) into branch range: pr/${prNumber}_base..pr/${prNumber}_top`);
shell.exec(`git fetch -f [email protected]:angular/angular.git pull/${prNumber}/head:pr/${prNumber}_top`);
shell.exec(`git branch -f pr/${prNumber}_base pr/${prNumber}_top~${prShaCount}`);
shell.echo(`======================================================================================`);
shell.exec(`git log --oneline --color pr/${prNumber}_base..pr/${prNumber}_top`);
shell.echo(`======================================================================================`);
// Reset the HEAD so that we can see changed files for review
shell.exec(`git checkout --force -b pr/${prNumber} pr/${prNumber}_top`);
shell.exec(`git reset pr/${prNumber}_base`);
shell.exec(`git status`);
return 0;
}