Skip to content

Commit 7b4f3ea

Browse files
zpaogaearon
authored andcommitted
[rrm] Use git helper for all git commands
1 parent 0fbe927 commit 7b4f3ea

File tree

5 files changed

+54
-26
lines changed

5 files changed

+54
-26
lines changed

scripts/release-manager/cli.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,6 @@ function execInRepo(command) {
7070
}).trim();
7171
}
7272

73-
/**
74-
* Cherry picks a single sha to the given branch. Very crude, but establishes
75-
* some API. We don't know if the sha is a merge or a squashed commit so just
76-
* try both.
77-
*
78-
* Assume we're already on the right branch.
79-
*/
80-
function gitCherryPickMerge(sha) {
81-
// console.log(`cherry picking ${sha}`)
82-
// git cherry-pick -x sha || git cherry-pick -x -m1 sha
83-
try {
84-
execInRepo(`git cherry-pick -x ${sha}`);
85-
} catch (e) {
86-
// Assume for now this just means it was actually a merge.
87-
// TODO: gracefully handle other cases, like possibility the commit was
88-
// already cherry-picked and should be skipped.
89-
90-
execInRepo(`git cherry-pick -x -m1 ${sha}`);
91-
}
92-
}
9373

9474
function getReactVersion() {
9575
return (JSON.parse(fs.readFileSync(path.join(PATH_TO_REPO, 'package.json'), 'utf8'))).version;
@@ -133,7 +113,6 @@ const app = {
133113
// HELPERS
134114
this.writeTo = writeTo;
135115
this.execInRepo = execInRepo;
136-
this.gitCherryPickMerge = gitCherryPickMerge;
137116
this.getReactVersion = getReactVersion;
138117

139118
// Register commands

scripts/release-manager/commands/docs-prs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const chalk = require('chalk');
4+
const git = require('./utils/git');
45

56
const DOCS_LABEL = 'Documentation: needs merge to stable';
67

@@ -78,7 +79,7 @@ module.exports = function(vorpal, app) {
7879
}, (res) => {
7980
if (res.merge) {
8081
richPulls.forEach((pr) => {
81-
app.gitCherryPickMerge(pr.merge_commit_sha);
82+
git.cherryPickMerge(app, pr.merge_commit_sha);
8283
});
8384

8485
this.prompt({
@@ -87,7 +88,7 @@ module.exports = function(vorpal, app) {
8788
message: 'Push these commits upstream?',
8889
}, (res) => {
8990
if (res.push) {
90-
app.execInRepo('git push');
91+
git.push(app);
9192
this.log(`Pushed upstream! Removing "${DOCS_LABEL}" label from pull requests.`);
9293
}
9394

scripts/release-manager/commands/stable-prs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
const chalk = require('chalk');
44

5+
const git = require('./utils/git');
6+
57
// currently 15-next
68
// IDEA: maybe just always use this milestone across major releases too?
79
const MILESTONE_NUMBER = 25;
@@ -152,7 +154,7 @@ function promptForPRs(app, prs, start) {
152154
let pr = prs[i];
153155
this.log(chalk.grey.italic(`Cherry-picking ${pr.number}`));
154156
try {
155-
app.gitCherryPickMerge(pr.merge_commit_sha);
157+
git.cherryPickMerge(app, pr.merge_commit_sha);
156158
} catch (e) {
157159

158160
// TODO: add ability to mark a PR as skipped

scripts/release-manager/commands/utils/git.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,57 @@ function merge(app, ref, ff, msg) {
3737
return app.execInRepo(`git merge ${opts.join(' ')} ${ref}`);
3838
}
3939

40+
function tag(app, tag, ref) {
41+
ref = ref || '';
42+
return app.execInRepo(`git tag ${tag} ${ref}`);
43+
}
44+
45+
function commit(app, msg, all) {
46+
return app.execInRepo(`git commit -m '${msg}' ${all ? '-a' : ''}`);
47+
}
48+
49+
function push(app, remote, refspec, tags) {
50+
let opts = [
51+
remote,
52+
refspec,
53+
tags ? '--tags' : '',
54+
];
55+
return app.execInRepo(`git push ${opts.join(' ')}`);
56+
}
57+
58+
/**
59+
* Cherry picks a single sha to the given branch. Very crude, but establishes
60+
* some API. We don't know if the sha is a merge or a squashed commit so just
61+
* try both.
62+
*
63+
* Assume we're already on the right branch.
64+
*/
65+
function cherryPickMerge(app, ref) {
66+
// console.log(`cherry picking ${sha}`)
67+
// git cherry-pick -x sha || git cherry-pick -x -m1 sha
68+
try {
69+
app.execInRepo(`git cherry-pick -x ${ref}`);
70+
} catch (e) {
71+
// Assume for now this just means it was actually a merge.
72+
// TODO: gracefully handle other cases, like possibility the commit was
73+
// already cherry-picked and should be skipped.
74+
75+
app.execInRepo(`git cherry-pick -x -m1 ${ref}`);
76+
}
77+
}
78+
4079
module.exports = {
4180
getBranch,
4281
getStatus,
4382
isClean,
4483

84+
commit,
4585
checkout,
4686
fetch,
4787
pull,
88+
push,
4889
merge,
90+
tag,
91+
92+
cherryPickMerge,
4993
};

scripts/release-manager/commands/version.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const semver = require('semver');
66

77
const chalk = require('chalk');
88

9+
const git = require('./utils/git');
10+
911

1012
// Overview
1113
// 1. Display current version
@@ -147,10 +149,10 @@ module.exports = function(vorpal, app) {
147149
},
148150
]).then((res) => {
149151
if (res.commit) {
150-
app.execInRepo(`git commit -a -m "${newVersion}"`);
152+
git.commit(app, newVersion, true);
151153
}
152154
if (res.tag) {
153-
app.execInRepo(`git tag v${newVersion}`);
155+
git.tag(app, `v${newVersion}`);
154156
}
155157
actionCB();
156158
});

0 commit comments

Comments
 (0)