Skip to content

Commit

Permalink
chore(release): 1.0.1 [skip ci]
Browse files Browse the repository at this point in the history
## [1.0.1](v1.0.0...v1.0.1) (2023-04-14)

### Bug Fixes

* simplify tsconfig ([c4a450d](c4a450d))
  • Loading branch information
semantic-release-bot committed Apr 14, 2023
1 parent c4a450d commit fd7e249
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 49 deletions.
46 changes: 26 additions & 20 deletions dist/index.js
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(', ')); };
56 changes: 28 additions & 28 deletions dist/index.test.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("./index");
describe('jiraIntegration()', () => {
beforeEach(() => {
var index_1 = require("./index");
describe('jiraIntegration()', function () {
beforeEach(function () {
global.warn = jest.fn();
global.message = jest.fn();
});
afterEach(() => {
afterEach(function () {
global.danger = undefined;
global.warn = undefined;
global.message = undefined;
});
it('throws when supplied invalid configuration', () => {
const anyJira = index_1.default;
expect(() => anyJira()).toThrow();
expect(() => (0, index_1.default)({})).toThrow();
expect(() => (0, index_1.default)({ key: 'ABC' })).toThrow();
it('throws when supplied invalid configuration', function () {
var anyJira = index_1.default;
expect(function () { return anyJira(); }).toThrow();
expect(function () { return (0, index_1.default)({}); }).toThrow();
expect(function () { return (0, index_1.default)({ key: 'ABC' }); }).toThrow();
});
it('warns when PR title is missing JIRA issue key', () => {
it('warns when PR title is missing JIRA issue key', function () {
global.danger = { github: { pr: { title: 'Change some things' } } };
(0, index_1.default)({
key: 'ABC',
url: 'https://jira.net/browse',
});
expect(global.warn).toHaveBeenCalledWith(`No JIRA keys found in the PR title, branch name, or commit messages (e.g. ABC-123).`);
expect(global.warn).toHaveBeenCalledWith("No JIRA keys found in the PR title, branch name, or commit messages (e.g. ABC-123).");
});
it('warns when PR title is missing all of the multiple JIRA issue keys', () => {
it('warns when PR title is missing all of the multiple JIRA issue keys', function () {
global.danger = { github: { pr: { title: 'Change some things' } } };
(0, index_1.default)({
key: ['ABC', 'DEF'],
url: 'https://jira.net/browse',
});
expect(global.warn).toHaveBeenCalledWith('No JIRA keys found in the PR title, branch name, or commit messages (e.g. ABC-123, DEF-123).');
});
it('adds the JIRA issue link from PR title to the messages table', () => {
it('adds the JIRA issue link from PR title to the messages table', function () {
global.danger = {
github: { pr: { title: '[ABC-808] Change some things' } },
};
Expand All @@ -43,7 +43,7 @@ describe('jiraIntegration()', () => {
});
expect(global.message).toHaveBeenCalledWith(':link: <a href="https://jira.net/browse/ABC-808">ABC-808</a>');
});
it('properly concatenates URL parts (trailing slash in url)', () => {
it('properly concatenates URL parts (trailing slash in url)', function () {
global.danger = {
github: { pr: { title: '[ABC-808] Change some things' } },
};
Expand All @@ -53,22 +53,22 @@ describe('jiraIntegration()', () => {
});
expect(global.message).toHaveBeenCalledWith(':link: <a href="https://jira.net/browse/ABC-808">ABC-808</a>');
});
it('matches JIRA issue anywhere in title', () => {
it('matches JIRA issue anywhere in title', function () {
global.danger = { github: { pr: { title: 'My changes - ABC-123' } } };
(0, index_1.default)({
key: 'ABC',
url: 'https://jira.net/browse',
});
expect(global.message).toHaveBeenCalledWith(':link: <a href="https://jira.net/browse/ABC-123">ABC-123</a>');
});
it('matches JIRA issue anywhere in title when no configuration key', () => {
it('matches JIRA issue anywhere in title when no configuration key', function () {
global.danger = { github: { pr: { title: 'My changes - ABC-123' } } };
(0, index_1.default)({
url: 'https://jira.net/browse',
});
expect(global.message).toHaveBeenCalledWith(':link: <a href="https://jira.net/browse/ABC-123">ABC-123</a>');
});
it('matches lowercase JIRA key in the git branch', () => {
it('matches lowercase JIRA key in the git branch', function () {
global.danger = {
github: { pr: { head: { ref: 'abc-808/some-things' } } },
};
Expand All @@ -78,7 +78,7 @@ describe('jiraIntegration()', () => {
});
expect(global.message).toHaveBeenCalledWith(':link: <a href="https://jira.net/browse/ABC-808">ABC-808</a>');
});
it('matches lowercase JIRA key in PR title', () => {
it('matches lowercase JIRA key in PR title', function () {
global.danger = {
github: { pr: { title: '[abc-808] Change some things' } },
};
Expand All @@ -88,7 +88,7 @@ describe('jiraIntegration()', () => {
});
expect(global.message).toHaveBeenCalledWith(':link: <a href="https://jira.net/browse/ABC-808">ABC-808</a>');
});
it('does not match lowercase JIRA key in PR title when case-sensitive', () => {
it('does not match lowercase JIRA key in PR title when case-sensitive', function () {
global.danger = {
github: { pr: { title: '[abc-808] Change some things' } },
};
Expand All @@ -99,7 +99,7 @@ describe('jiraIntegration()', () => {
});
expect(global.warn).toHaveBeenCalled();
});
it('supports multiple JIRA keys in PR title', () => {
it('supports multiple JIRA keys in PR title', function () {
global.danger = {
github: { pr: { title: '[ABC-123][ABC-456] Change some things' } },
};
Expand All @@ -109,7 +109,7 @@ describe('jiraIntegration()', () => {
});
expect(global.message).toHaveBeenCalledWith(':link: <a href="https://jira.net/browse/ABC-123">ABC-123</a>, <a href="https://jira.net/browse/ABC-456">ABC-456</a>');
});
it('supports multiple JIRA boards in PR title', () => {
it('supports multiple JIRA boards in PR title', function () {
global.danger = {
github: { pr: { title: '[ABC-123][DEF-456] Change some things' } },
};
Expand All @@ -119,20 +119,20 @@ describe('jiraIntegration()', () => {
});
expect(global.message).toHaveBeenCalledWith(':link: <a href="https://jira.net/browse/ABC-123">ABC-123</a>, <a href="https://jira.net/browse/DEF-456">DEF-456</a>');
});
it('supports a custom format function', () => {
it('supports a custom format function', function () {
global.danger = {
github: { pr: { title: '[ABC-123][DEF-456] Change some things' } },
};
(0, index_1.default)({
format: (jiraUrls) => {
return `JIRA Tickets: ${jiraUrls.join(', ')}`;
format: function (jiraUrls) {
return "JIRA Tickets: ".concat(jiraUrls.join(', '));
},
key: ['ABC', 'DEF'],
url: 'https://jira.net/browse',
});
expect(global.message).toHaveBeenCalledWith('JIRA Tickets: <a href="https://jira.net/browse/ABC-123">ABC-123</a>, <a href="https://jira.net/browse/DEF-456">DEF-456</a>');
});
it('supports JIRA key in the git branch', () => {
it('supports JIRA key in the git branch', function () {
global.danger = {
github: { pr: { head: { ref: 'ABC-808/some-things' } } },
};
Expand All @@ -142,7 +142,7 @@ describe('jiraIntegration()', () => {
});
expect(global.message).toHaveBeenCalledWith(':link: <a href="https://jira.net/browse/ABC-808">ABC-808</a>');
});
it('supports JIRA key in the git branch when no configuration key', () => {
it('supports JIRA key in the git branch when no configuration key', function () {
global.danger = {
github: { pr: { head: { ref: 'ABC-808/some-things' } } },
};
Expand All @@ -151,15 +151,15 @@ describe('jiraIntegration()', () => {
});
expect(global.message).toHaveBeenCalledWith(':link: <a href="https://jira.net/browse/ABC-808">ABC-808</a>');
});
it('supports JIRA key in the PR body', () => {
it('supports JIRA key in the PR body', function () {
global.danger = { github: { pr: { body: '[ABC-808] Change some things' } } };
(0, index_1.default)({
key: 'ABC',
url: 'https://jira.net/browse',
});
expect(global.message).toHaveBeenCalledWith(':link: <a href="https://jira.net/browse/ABC-808">ABC-808</a>');
});
it('supports JIRA key in the PR body when no configuration key', () => {
it('supports JIRA key in the PR body when no configuration key', function () {
global.danger = { github: { pr: { body: '[ABC-808] Change some things' } } };
(0, index_1.default)({
url: 'https://jira.net/browse',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"danger-plugin",
"jira"
],
"version": "1.0.0",
"version": "1.0.1",
"main": "dist/index.js",
"types": "types/index.d.ts",
"scripts": {
Expand Down

0 comments on commit fd7e249

Please sign in to comment.