[rrm] Use git helper for all git commands
Paul O’Shannessy committed
Sep 8, 2016 at 16:48 UTC
7b4f3ea2e31d5e1fcd315fdcf81fab2395f9bf18
5 files changed
+54
-26
scripts/release-manager/cli.js
-21
@@ -70,26 +70,6 @@ function execInRepo(command) {
70
}).trim();
71
}
72
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
-}
73
74
function getReactVersion() {
75
return (JSON.parse(fs.readFileSync(path.join(PATH_TO_REPO, 'package.json'), 'utf8'))).version;
@@ -133,7 +113,6 @@ const app = {
113
// HELPERS
114
this.writeTo = writeTo;
115
this.execInRepo = execInRepo;
136
- this.gitCherryPickMerge = gitCherryPickMerge;
116
this.getReactVersion = getReactVersion;
117
118
// Register commands
scripts/release-manager/commands/docs-prs.js
+3
-2
@@ -1,6 +1,7 @@
1
'use strict';
2
3
const chalk = require('chalk');
4
+const git = require('./utils/git');
5
6
const DOCS_LABEL = 'Documentation: needs merge to stable';
7
@@ -78,7 +79,7 @@ module.exports = function(vorpal, app) {
79
}, (res) => {
80
if (res.merge) {
81
richPulls.forEach((pr) => {
81
- app.gitCherryPickMerge(pr.merge_commit_sha);
82
+ git.cherryPickMerge(app, pr.merge_commit_sha);
83
});
84
85
this.prompt({
@@ -87,7 +88,7 @@ module.exports = function(vorpal, app) {
88
message: 'Push these commits upstream?',
89
}, (res) => {
90
if (res.push) {
90
- app.execInRepo('git push');
91
+ git.push(app);
92
this.log(`Pushed upstream! Removing "${DOCS_LABEL}" label from pull requests.`);
93
}
94
scripts/release-manager/commands/stable-prs.js
+3
-1
@@ -2,6 +2,8 @@
2
3
const chalk = require('chalk');
4
5
+const git = require('./utils/git');
6
+
7
// currently 15-next
8
// IDEA: maybe just always use this milestone across major releases too?
9
const MILESTONE_NUMBER = 25;
@@ -152,7 +154,7 @@ function promptForPRs(app, prs, start) {
154
let pr = prs[i];
155
this.log(chalk.grey.italic(`Cherry-picking ${pr.number}`));
156
try {
155
- app.gitCherryPickMerge(pr.merge_commit_sha);
157
+ git.cherryPickMerge(app, pr.merge_commit_sha);
158
} catch (e) {
159
160
// TODO: add ability to mark a PR as skipped
scripts/release-manager/commands/utils/git.js
+44
@@ -37,13 +37,57 @@ function merge(app, ref, ff, msg) {
37
return app.execInRepo(`git merge ${opts.join(' ')} ${ref}`);
38
}
39
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
+
79
module.exports = {
80
getBranch,
81
getStatus,
82
isClean,
83
84
+ commit,
85
checkout,
86
fetch,
87
pull,
88
+ push,
89
merge,
90
+ tag,
91
+
92
+ cherryPickMerge,
93
};
scripts/release-manager/commands/version.js
+4
-2
@@ -6,6 +6,8 @@ const semver = require('semver');
6
7
const chalk = require('chalk');
8
9
+const git = require('./utils/git');
10
+
11
12
// Overview
13
// 1. Display current version
@@ -147,10 +149,10 @@ module.exports = function(vorpal, app) {
149
},
150
]).then((res) => {
151
if (res.commit) {
150
- app.execInRepo(`git commit -a -m "${newVersion}"`);
152
+ git.commit(app, newVersion, true);
153
}
154
if (res.tag) {
153
- app.execInRepo(`git tag v${newVersion}`);
155
+ git.tag(app, `v${newVersion}`);
156
}
157
actionCB();
158
});