forked from macklinu/danger-plugin-jira-issue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## [1.0.1](v1.0.0...v1.0.1) (2023-04-14) ### Bug Fixes * simplify tsconfig ([c4a450d](c4a450d))
- Loading branch information
1 parent
c4a450d
commit fd7e249
Showing
3 changed files
with
55 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,62 @@ | ||
"use strict"; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const url_1 = require("url"); | ||
var url_1 = require("url"); | ||
/** | ||
* Danger plugin to integrate your pull request with JIRA | ||
*/ | ||
function jiraIntegration({ key, url, format = defaultFormat, caseSensitive = false }) { | ||
function jiraIntegration(_a) { | ||
var key = _a.key, url = _a.url, _b = _a.format, format = _b === void 0 ? defaultFormat : _b, _c = _a.caseSensitive, caseSensitive = _c === void 0 ? false : _c; | ||
if (!url) { | ||
throw Error(`'url' missing - must supply JIRA installation URL`); | ||
throw Error("'url' missing - must supply JIRA installation URL"); | ||
} | ||
// Support multiple JIRA projects. | ||
const keys = key ? (Array.isArray(key) ? `(${key.join('|')})` : key) : '[A-Za-z]{2,4}'; | ||
const jiraKeyRegex = new RegExp(`(${keys}-[0-9]+)`, `g${caseSensitive ? '' : 'i'}`); | ||
var keys = key ? (Array.isArray(key) ? "(".concat(key.join('|'), ")") : key) : '[A-Za-z]{2,4}'; | ||
var jiraKeyRegex = new RegExp("(".concat(keys, "-[0-9]+)"), "g".concat(caseSensitive ? '' : 'i')); | ||
function findMatches(property) { | ||
const issues = []; | ||
let match = jiraKeyRegex.exec(property); | ||
var issues = []; | ||
var match = jiraKeyRegex.exec(property); | ||
while (match !== null) { | ||
issues.push(match[0].toLowerCase()); | ||
match = jiraKeyRegex.exec(property); | ||
} | ||
return issues; | ||
} | ||
const allIssues = new Set([ | ||
...findMatches(danger.github.pr.title), | ||
...findMatches(danger.github.pr.head ? danger.github.pr.head.ref : ''), | ||
...findMatches(danger.github.pr.body), | ||
]); | ||
var allIssues = new Set(__spreadArray(__spreadArray(__spreadArray([], findMatches(danger.github.pr.title), true), findMatches(danger.github.pr.head ? danger.github.pr.head.ref : ''), true), findMatches(danger.github.pr.body), true)); | ||
if (allIssues.size > 0) { | ||
// URL must end with a slash before attempting to fully resolve the JIRA URL. | ||
url = ensureUrlEndsWithSlash(url); | ||
const jiraUrls = Array.from(allIssues).map((issue) => { | ||
const formattedIssue = issue.toUpperCase(); | ||
const resolvedUrl = (0, url_1.resolve)(url, formattedIssue); | ||
var jiraUrls = Array.from(allIssues).map(function (issue) { | ||
var formattedIssue = issue.toUpperCase(); | ||
var resolvedUrl = (0, url_1.resolve)(url, formattedIssue); | ||
return link(resolvedUrl, formattedIssue); | ||
}); | ||
message(format(jiraUrls)); | ||
} | ||
else { | ||
let warningKeys; | ||
var warningKeys = void 0; | ||
if (key) { | ||
warningKeys = Array.isArray(key) ? key.map((k) => `${k}-123`).join(', ') : key + '-123'; | ||
warningKeys = Array.isArray(key) ? key.map(function (k) { return "".concat(k, "-123"); }).join(', ') : key + '-123'; | ||
} | ||
else { | ||
warningKeys = 'ABC-123'; | ||
} | ||
warn(`No JIRA keys found in the PR title, branch name, or commit messages (e.g. ${warningKeys}).`); | ||
warn("No JIRA keys found in the PR title, branch name, or commit messages (e.g. ".concat(warningKeys, ").")); | ||
} | ||
} | ||
exports.default = jiraIntegration; | ||
function link(href, text) { | ||
return `<a href="${href}">${text}</a>`; | ||
return "<a href=\"".concat(href, "\">").concat(text, "</a>"); | ||
} | ||
function ensureUrlEndsWithSlash(url) { | ||
return url.endsWith('/') ? url : url.concat('/'); | ||
} | ||
const defaultFormat = (urls) => `:link: ${urls.join(', ')}`; | ||
var defaultFormat = function (urls) { return ":link: ".concat(urls.join(', ')); }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters