gaia-project/scripts/check-commit-msg.js
2021-05-18 23:42:49 +02:00

90 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const path = require("path");
const fs = require("fs");
const assert = require("assert");
const msg = fs
.readFileSync(path.join(__dirname, "../.git/COMMIT_EDITMSG"))
.toString("utf-8")
.replace(/^fixup! /, "");
const gitmojis = [
"🎨",
"⚡️",
"🔥",
"🐛",
"🚑",
"✨",
"📝",
"🚀",
"💄",
"🎉",
"✅",
"🔒",
"🔖",
"🚨",
"🚧",
"💚",
"⬇️",
"⬆️",
"📌",
"👷",
"📈",
"♻️",
"➕",
"➖",
"🔧",
"🔨",
"🌐",
"✏️",
"💩",
"⏪",
"🔀",
"📦",
"👽",
"🚚",
"📄",
"💥",
"🍱",
"♿️",
"💡",
"🍻",
"💬",
"🗃",
"🔊",
"🔇",
"👥",
"🚸",
"🏗",
"📱",
"🤡",
"🥚",
"🙈",
"📸",
"⚗",
"🔍",
"🏷️",
"🌱",
"🚩",
"🥅",
"💫",
"🗑",
"🛂",
"🩹",
"🧐",
"⚰️",
];
try {
const gitmoji = gitmojis.find((gm) => msg.startsWith(gm));
assert(gitmoji, "Commit message should start with gitmoji");
assert(msg[gitmoji.length] === " ", "Space should follow gitmoji");
assert(/^[^ ]* \((all|viewer|engine|old-ui)\)/.test(msg), "Commit scope should be 'all', 'engine' or 'viewer'");
assert(
/^[^ ]* \((all|viewer|engine|old-ui)\) [A-Z]/.test(msg),
"Commit subject should start with a space and an uppercase letter"
);
} catch (err) {
console.error("Expected commit format: <gitmoji> (all|viewer|engine) Subject");
console.error(err.message);
process.exit(1);
}