You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
953 B
Plaintext
38 lines
953 B
Plaintext
4 years ago
|
#!/usr/bin/env node
|
||
|
|
||
|
const fs = require("fs");
|
||
|
const childProcess = require("child_process");
|
||
|
const { promisify } = require("util");
|
||
|
|
||
|
const exec = promisify(childProcess.exec);
|
||
|
const readFile = promisify(fs.readFile);
|
||
|
const writeFile = promisify(fs.writeFile);
|
||
|
|
||
|
const [, , commitMsg, comitSrc, sha1] = process.argv;
|
||
|
|
||
|
async function main() {
|
||
|
const file = await readFile(commitMsg, { encoding: "utf8" });
|
||
|
const result = await exec("git symbolic-ref --short HEAD");
|
||
|
|
||
|
const tags = result.stdout
|
||
|
.split("\n")
|
||
|
.map(branch => branch.match(/[A-Z]+-\d+/g))
|
||
|
.filter(x => !!x)
|
||
|
.reduce((allIDs, matchedIDs) => [...allIDs, ...matchedIDs], [])
|
||
|
.map(id => `[${id}]`);
|
||
|
|
||
|
if (tags.length === 0) {
|
||
|
return;
|
||
|
}
|
||
|
if (tags.find(tag => file.includes(tag))) {
|
||
|
return;
|
||
|
}
|
||
|
const newFile = "\n\n# " + tags.join(" ") + "\n" + file;
|
||
|
await writeFile(commitMsg, newFile);
|
||
|
}
|
||
|
|
||
|
main().catch(err => {
|
||
|
console.error(err);
|
||
|
process.exit(1);
|
||
|
});
|