@ondrejbelza/semantic-release-jira 1.3.4 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_VERSION_TEMPLATE = "v${version}";
2
+ export declare const DEFAULT_RELEASE_DESCRIPTION_TEMPLATE = "Automated release with semantic-release-jira-releases https://git.io/JvAbj";
package/dist/consts.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_RELEASE_DESCRIPTION_TEMPLATE = exports.DEFAULT_VERSION_TEMPLATE = void 0;
4
+ exports.DEFAULT_VERSION_TEMPLATE = "v${version}";
5
+ exports.DEFAULT_RELEASE_DESCRIPTION_TEMPLATE = "Automated release with semantic-release-jira-releases https://git.io/JvAbj";
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { verifyConditions } from "./verify_condition";
2
- export { verifyConditions };
2
+ import { success } from "./success";
3
+ export { verifyConditions, success };
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyConditions = void 0;
3
+ exports.success = exports.verifyConditions = void 0;
4
4
  const verify_condition_1 = require("./verify_condition");
5
5
  Object.defineProperty(exports, "verifyConditions", { enumerable: true, get: function () { return verify_condition_1.verifyConditions; } });
6
+ const success_1 = require("./success");
7
+ Object.defineProperty(exports, "success", { enumerable: true, get: function () { return success_1.success; } });
@@ -0,0 +1,3 @@
1
+ import { PluginConfig } from "./types";
2
+ import { SuccessContext } from "semantic-release";
3
+ export declare function success(config: PluginConfig, context: SuccessContext): Promise<void>;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.success = success;
40
+ const utils_1 = require("./utils");
41
+ const _ = __importStar(require("lodash"));
42
+ const consts_1 = require("./consts");
43
+ const jira_client_1 = require("./jira-client");
44
+ const p_limit_1 = __importDefault(require("p-limit"));
45
+ const error_1 = __importDefault(require("@semantic-release/error"));
46
+ function getMentionedTickets(ticketPrefix, commits, logger) {
47
+ const tickets = new Set();
48
+ const pattern = new RegExp(`\\b${(0, utils_1.escapeRegExp)(ticketPrefix)}-(\\d+)\\b`, "giu");
49
+ for (const commit of commits) {
50
+ const matches = commit.message.match(pattern);
51
+ if (matches) {
52
+ for (const match of matches) {
53
+ tickets.add(match);
54
+ logger.info(`Found matching ticket it commit ${match} in ${commit.commit.short}`);
55
+ }
56
+ }
57
+ }
58
+ return [...tickets];
59
+ }
60
+ async function findOrCreateVersion(c, projectKey, newVersionName, newVersionDescription, logger) {
61
+ const versions = await c.projectVersions.getProjectVersions({
62
+ projectIdOrKey: projectKey,
63
+ });
64
+ for (const v of versions) {
65
+ if (v.name === newVersionName) {
66
+ logger.info(`Found existing jira release with id: ${v.id}`);
67
+ return v;
68
+ }
69
+ }
70
+ return c.projectVersions.createVersion({
71
+ name: newVersionName,
72
+ description: newVersionDescription,
73
+ projectId: projectKey,
74
+ released: true,
75
+ releaseDate: new Date().toISOString(),
76
+ });
77
+ }
78
+ async function editIssueFixVersions(c, ticket, versionId, logger) {
79
+ logger.info(`Adding issue '${ticket}' to a release '${versionId}'`);
80
+ c.issues
81
+ .editIssue({
82
+ issueIdOrKey: ticket,
83
+ update: {
84
+ fixVersions: [
85
+ {
86
+ add: { id: versionId },
87
+ },
88
+ ],
89
+ },
90
+ })
91
+ .catch((err) => {
92
+ const allowedStatusCodes = [400, 404];
93
+ let { statusCode } = err;
94
+ if (typeof err === "string") {
95
+ try {
96
+ err = JSON.parse(err);
97
+ statusCode = statusCode || err.statusCode;
98
+ }
99
+ catch {
100
+ // ignore
101
+ }
102
+ }
103
+ if (allowedStatusCodes.indexOf(statusCode) === -1) {
104
+ logger.error(`Issue '${ticket}' was not added to a release.`, err);
105
+ if (err.response) {
106
+ throw new error_1.default(err.Response);
107
+ }
108
+ throw new error_1.default(err);
109
+ }
110
+ })
111
+ .then(() => {
112
+ logger.complete(`Issue '${ticket}' was successfully added to a release.`);
113
+ });
114
+ }
115
+ async function success(config, context) {
116
+ const { env, logger, commits, nextRelease } = context;
117
+ const { jiraHost, project: projectKey, ticketPrefix, versionTemplate: definedVersionTemplate, } = config;
118
+ const tickets = getMentionedTickets(ticketPrefix, commits, logger);
119
+ const versionTemplate = _.template(definedVersionTemplate || consts_1.DEFAULT_VERSION_TEMPLATE);
120
+ const newVersionName = versionTemplate({ version: nextRelease.version });
121
+ const newVersionDescription = consts_1.DEFAULT_RELEASE_DESCRIPTION_TEMPLATE;
122
+ logger.info(`Using jira release '${newVersionName}'`);
123
+ logger.info(`using jira description '${consts_1.DEFAULT_RELEASE_DESCRIPTION_TEMPLATE}'`);
124
+ const c = (0, jira_client_1.CreateJiraClient)(logger, jiraHost, env.JIRA_EMAIL, env.JIRA_TOKEN);
125
+ const project = await c.projects.getProject({ projectIdOrKey: projectKey });
126
+ const version = await findOrCreateVersion(c, projectKey, newVersionName, newVersionDescription, logger);
127
+ const concurrentLimit = (0, p_limit_1.default)(10);
128
+ const edits = [];
129
+ for (const ticket of tickets) {
130
+ edits.push(concurrentLimit(() => editIssueFixVersions(c, ticket, version.id || "", logger)));
131
+ }
132
+ await Promise.all(edits);
133
+ }
package/dist/types.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export interface PluginConfig {
2
2
  jiraHost: string;
3
3
  project: string;
4
+ ticketPrefix: string;
5
+ versionTemplate: string;
4
6
  }
@@ -0,0 +1 @@
1
+ export declare function escapeRegExp(strIn: string): string;
package/dist/utils.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.escapeRegExp = escapeRegExp;
4
+ function escapeRegExp(strIn) {
5
+ return strIn.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
6
+ }
@@ -12,8 +12,8 @@ const jira_client_1 = require("./jira-client");
12
12
  */
13
13
  async function verifyConditions(pluginConfig, context) {
14
14
  const { logger, env } = context;
15
+ const { jiraHost: host, project } = pluginConfig;
15
16
  logger.log("Checking conditions for my custom plugin...");
16
- const host = pluginConfig.jiraHost;
17
17
  logger.log("jira host configure to:" + host);
18
18
  if (host == "") {
19
19
  throw new error_1.default("jira host configuration variable is missing.");
@@ -26,7 +26,7 @@ async function verifyConditions(pluginConfig, context) {
26
26
  }
27
27
  const c = (0, jira_client_1.CreateJiraClient)(logger, host, env.JIRA_EMAIL, env.JIRA_TOKEN);
28
28
  const p = await c.projects.getProject({
29
- projectIdOrKey: pluginConfig.project,
29
+ projectIdOrKey: project,
30
30
  });
31
31
  logger.log("project was found and will be used:" + p.id);
32
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ondrejbelza/semantic-release-jira",
3
- "version": "1.3.4",
3
+ "version": "1.4.0",
4
4
  "description": "semantic release jira releases plugin",
5
5
  "homepage": "https://github.com/mailstepcz/semantic-release-jira#readme",
6
6
  "bugs": {
@@ -29,6 +29,8 @@
29
29
  "dependencies": {
30
30
  "@semantic-release/error": "^4.0.0",
31
31
  "jira.js": "^5.2.2",
32
+ "lodash": "^4.17.21",
33
+ "p-limit": "^7.2.0",
32
34
  "semantic-release": "^25.0.2"
33
35
  },
34
36
  "devDependencies": {
@@ -37,6 +39,7 @@
37
39
  "@semantic-release/git": "^10.0.1",
38
40
  "@semantic-release/github": "^12.0.2",
39
41
  "@semantic-release/npm": "^13.1.3",
42
+ "@types/lodash": "^4.17.21",
40
43
  "@types/node": "^25.0.3",
41
44
  "@types/semantic-release__error": "^3.0.3",
42
45
  "@types/signale": "^1.4.7",