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.
54 lines
1.1 KiB
Cheetah
54 lines
1.1 KiB
Cheetah
2 years ago
|
{{ if and .hellotech (lookPath "node") -}}
|
||
4 years ago
|
#!/usr/bin/env node
|
||
2 years ago
|
// vim: ft=javascript
|
||
4 years ago
|
|
||
|
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);
|
||
|
|
||
3 years ago
|
const [, , message, mode] = process.argv;
|
||
4 years ago
|
|
||
|
async function main() {
|
||
3 years ago
|
const file = await readFile(message, { encoding: "utf8" });
|
||
|
let result;
|
||
|
try {
|
||
|
result = await exec("git rev-parse --abbrev-ref HEAD");
|
||
|
} catch (err) {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if (message.match(/^#/)) {
|
||
|
return
|
||
|
}
|
||
4 years ago
|
|
||
|
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;
|
||
|
}
|
||
3 years ago
|
|
||
|
const newFile = mode === 'message'
|
||
|
? file + '\n\n' + tags.join(" ")
|
||
|
: `\n\n# ` + tags.join(" ") + "\n" + file;
|
||
|
|
||
|
await writeFile(message, newFile);
|
||
4 years ago
|
}
|
||
|
|
||
|
main().catch(err => {
|
||
|
console.error(err);
|
||
|
process.exit(1);
|
||
|
});
|
||
2 years ago
|
{{- end }}
|