build: Add GitHub scripts for rebasing PRs (#18359)

PR Close #18359
This commit is contained in:
Miško Hevery
2017-08-28 18:44:39 -05:00
committed by Miško Hevery
parent 2e714f9f2a
commit d1764fc3dd
10 changed files with 706 additions and 2 deletions
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env node
var msg = '';
if (require.main === module) {
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
const chunk = process.stdin.read();
if (chunk !== null) {
msg += chunk;
}
});
process.stdin.on('end', () => {
var argv = process.argv.slice(2);
console.log(rewriteMsg(msg, argv[0]));
});
}
function rewriteMsg(msg, prNo) {
var lines = msg.split(/\n/);
lines[0] += ' (#' + prNo +')';
lines.push('PR Close #' + prNo);
return lines.join('\n');
}
exports.rewriteMsg = rewriteMsg;
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env node
var json = '';
if (require.main === module) {
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
const chunk = process.stdin.read();
if (chunk !== null) {
json += chunk;
}
});
process.stdin.on('end', () => {
var obj = JSON.parse(json);
var argv = process.argv.slice(2);
extractPaths(obj, argv).forEach(function(line) {
console.log(line);
})
});
}
function extractPaths(obj, paths) {
var lines = [];
paths.forEach(function(exp) {
var objs = obj instanceof Array ? [].concat(obj) : [obj];
exp.split('.').forEach(function(name) {
for(var i = 0; i < objs.length; i++) {
var o = objs[i];
if (o instanceof Array) {
// Expand and do over
objs = objs.slice(0, i).concat(o).concat(objs.slice(i+1, objs.length));
i--;
} else {
name.split("=").forEach(function(name, index) {
if (index == 0) {
objs[i] = o = o[name];
} else if (name.charAt(0) == '^') {
if (o.indexOf(name.substr(1)) !== 0) {
objs.splice(i, 1);
i--;
}
}
});
}
}
});
lines.push(objs.join("|"));
});
return lines;
}
exports.extractPaths = extractPaths;
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env node
var assert = require("assert");
var extractPaths = require('./json_extract').extractPaths;
var SAMPLE_LABELS = [
{
"id": 149476251,
"url": "https://api.github.com/repos/angular/angular/labels/cla:%20yes",
"name": "cla: yes",
"color": "009800",
"default": false
},
{
"id": 533874619,
"url": "https://api.github.com/repos/angular/angular/labels/comp:%20aio",
"name": "comp: aio",
"color": "c7def8",
"default": false
},
{
"id": 133556520,
"url": "https://api.github.com/repos/angular/angular/labels/PR%20action:%20merge",
"name": "PR action: merge",
"color": "99ff66",
"default": false
},
{
"id": 655699838,
"url": "https://api.github.com/repos/angular/angular/labels/PR%20target:%20master%20&%20patch",
"name": "PR target: master & patch",
"color": "5319e7",
"default": false
}
];
assert.deepEqual(extractPaths({head: {label: 'value1'}}, ['head.label']), ['value1']);
assert.deepEqual(extractPaths(SAMPLE_LABELS, ['name']), ['cla: yes|comp: aio|PR action: merge|PR target: master & patch']);
assert.deepEqual(extractPaths(SAMPLE_LABELS, ['name=^PR target:']), ['PR target: master & patch']);
+30
View File
@@ -0,0 +1,30 @@
[
{
"id": 149476251,
"url": "https://api.github.com/repos/angular/angular/labels/cla:%20yes",
"name": "cla: yes",
"color": "009800",
"default": false
},
{
"id": 533874619,
"url": "https://api.github.com/repos/angular/angular/labels/comp:%20aio",
"name": "comp: aio",
"color": "c7def8",
"default": false
},
{
"id": 133556520,
"url": "https://api.github.com/repos/angular/angular/labels/PR%20action:%20merge",
"name": "PR action: merge",
"color": "99ff66",
"default": false
},
{
"id": 655699838,
"url": "https://api.github.com/repos/angular/angular/labels/PR%20target:%20master%20&%20patch",
"name": "PR target: master & patch",
"color": "5319e7",
"default": false
}
]
File diff suppressed because it is too large Load Diff