harvester-ui-extension/scripts/extract-release-label.mjs
Andy Lee 87baf75301
fix(ci): support scoped commit prefixes in PR label extraction (#1032)
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>
2026-07-20 15:23:26 +08:00

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);