UNPKG

@auto-it/jira

Version:
81 lines 3.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseJira = void 0; const tslib_1 = require("tslib"); const url_join_1 = tslib_1.__importDefault(require("url-join")); const enquirer_1 = require("enquirer"); const t = tslib_1.__importStar(require("io-ts")); const core_1 = require("@auto-it/core"); const pluginOptions = t.interface({ /** Url to a hosted JIRA instance */ url: t.string, }); const jira = /\[?([\w]{1,}-\d+)\]?:?\s?[-\s]*([\S ]+)?/; /** Get the jira number from a commit message. */ function parseJira(commit) { // Support 'JIRA-XXX:' and '[JIRA-XXX]' and '[JIRA-XXX] - ' const matches = []; let currentMatch = commit.subject.match(jira); while (currentMatch) { matches.push(currentMatch); const rest = currentMatch[2]; if (!rest) { break; } currentMatch = rest.match(jira); } if (!matches.length) { return commit; } return Object.assign(Object.assign({}, commit), { jira: { number: matches.map((match) => match[1]), } }); } exports.parseJira = parseJira; /** Convert shorthand options to noraml shape */ const normalizeOptions = (options) => typeof options === "string" ? { url: options } : options; /** Include Jira story information in your changelogs */ class JiraPlugin { /** Initialize the plugin with it's options */ constructor(options) { /** The name of the plugin */ this.name = "jira"; this.options = normalizeOptions(options); } /** Custom initialization for this plugin */ init(initializer) { initializer.hooks.configurePlugin.tapPromise(this.name, async (name) => { if (name === "jira") { const url = await enquirer_1.prompt({ type: "input", name: "value", message: "What is the root url of your Jira instance?", required: true, }); return ["jira", url.value]; } }); } /** Tap into auto plugin points. */ apply(auto) { auto.hooks.validateConfig.tapPromise(this.name, async (name, options) => { if (name === this.name || name === `@auto-it/${this.name}`) { return core_1.validatePluginConfiguration(this.name, pluginOptions, normalizeOptions(options)); } }); auto.hooks.onCreateChangelog.tap(this.name, (changelog) => { changelog.hooks.renderChangelogLine.tap(this.name, (currentRender, commit) => { let line = currentRender; const jiraCommit = parseJira(commit); if (jiraCommit.jira && this.options.url) { const link = url_join_1.default(this.options.url, ...jiraCommit.jira.number); const [, , rest] = commit.subject.match(jira) || []; line = line.replace(jira, `[${jiraCommit.jira.number}](${link})${rest ? ":" : ""} $2`); } return line; }); }); } } exports.default = JiraPlugin; //# sourceMappingURL=index.js.map