|
|
@ -8,11 +8,20 @@ const exec = promisify(childProcess.exec);
|
|
|
|
const readFile = promisify(fs.readFile);
|
|
|
|
const readFile = promisify(fs.readFile);
|
|
|
|
const writeFile = promisify(fs.writeFile);
|
|
|
|
const writeFile = promisify(fs.writeFile);
|
|
|
|
|
|
|
|
|
|
|
|
const [, , commitMsg, comitSrc, sha1] = process.argv;
|
|
|
|
const [, , message, mode] = process.argv;
|
|
|
|
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
async function main() {
|
|
|
|
const file = await readFile(commitMsg, { encoding: "utf8" });
|
|
|
|
const file = await readFile(message, { encoding: "utf8" });
|
|
|
|
const result = await exec("git symbolic-ref --short HEAD");
|
|
|
|
let result;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
result = await exec("git rev-parse --abbrev-ref HEAD");
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message.match(/^#/)) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const tags = result.stdout
|
|
|
|
const tags = result.stdout
|
|
|
|
.split("\n")
|
|
|
|
.split("\n")
|
|
|
@ -27,8 +36,12 @@ async function main() {
|
|
|
|
if (tags.find(tag => file.includes(tag))) {
|
|
|
|
if (tags.find(tag => file.includes(tag))) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const newFile = "\n\n# " + tags.join(" ") + "\n" + file;
|
|
|
|
|
|
|
|
await writeFile(commitMsg, newFile);
|
|
|
|
const newFile = mode === 'message'
|
|
|
|
|
|
|
|
? file + '\n\n' + tags.join(" ")
|
|
|
|
|
|
|
|
: `\n\n# ` + tags.join(" ") + "\n" + file;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await writeFile(message, newFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main().catch(err => {
|
|
|
|
main().catch(err => {
|
|
|
|