mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-08-16 20:59:16 +00:00
Strip the scope in parentheses so titles like 'refactor(host): ...' resolve to the 'refactor' type instead of falling back to 'other'. Signed-off-by: Andy Lee <andy.lee@suse.com>
21 lines
702 B
JavaScript
21 lines
702 B
JavaScript
/* eslint-disable no-console */
|
|
import load from "@commitlint/load";
|
|
|
|
if (process.argv.length < 3) {
|
|
console.error('No PR title as first argument');
|
|
process.exit(1);
|
|
}
|
|
|
|
const prTitle = process.argv[2];
|
|
|
|
// Parse the conventional-commit prefix `type(scope)!:`, keeping only the type
|
|
// and dropping an optional scope and breaking-change marker.
|
|
const prefixMatch = prTitle.match(/^\s*([a-zA-Z]+)(?:\([^)]*\))?!?:/);
|
|
const prLabel = prefixMatch ? prefixMatch[1].toLowerCase() : '';
|
|
|
|
const config = await load({ extends: ["./commitlint.config.js"] });
|
|
const commitPrefix = config?.rules?.['type-enum']?.[2] || [];
|
|
const label = commitPrefix.includes(prLabel) ? prLabel : 'other';
|
|
|
|
console.log(label);
|