@ondrejbelza/semantic-release-jira 1.4.5 → 1.5.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.
package/dist/consts.d.ts CHANGED
@@ -1,2 +1,2 @@
1
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";
2
+ export declare const DEFAULT_RELEASE_DESCRIPTION_TEMPLATE = "# Release notes - {{version}}\n## Issues\n{{#each issues}}\n - [{{type}}] [{{ key }}]({{ link }}) {{ title }}\n \n Short description: {{ description }}\n \n Assigned to: {{ assignee }}\n{{/each}}\n\nRelease notes were automatically generated";
package/dist/consts.js CHANGED
@@ -2,4 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_RELEASE_DESCRIPTION_TEMPLATE = exports.DEFAULT_VERSION_TEMPLATE = void 0;
4
4
  exports.DEFAULT_VERSION_TEMPLATE = "v${version}";
5
- exports.DEFAULT_RELEASE_DESCRIPTION_TEMPLATE = "Automated release with semantic-release-jira-releases https://git.io/JvAbj";
5
+ exports.DEFAULT_RELEASE_DESCRIPTION_TEMPLATE = `# Release notes - {{version}}
6
+ ## Issues
7
+ {{#each issues}}
8
+ - [{{type}}] [{{ key }}]({{ link }}) {{ title }}
9
+
10
+ Short description: {{ description }}
11
+
12
+ Assigned to: {{ assignee }}
13
+ {{/each}}
14
+
15
+ Release notes were automatically generated`;
package/dist/success.js CHANGED
@@ -39,19 +39,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.success = success;
40
40
  const utils_1 = require("./utils");
41
41
  const _ = __importStar(require("lodash"));
42
+ const handlebars_1 = __importDefault(require("handlebars"));
42
43
  const consts_1 = require("./consts");
43
44
  const jira_client_1 = require("./jira-client");
44
45
  const p_limit_1 = __importDefault(require("p-limit"));
45
46
  const error_1 = __importDefault(require("@semantic-release/error"));
46
- function getMentionedTickets(ticketPrefix, commits, logger) {
47
+ async function getIssueMetadata(c, issueKey, jiraHost, logger) {
48
+ logger.info(`Loading info for issue ${issueKey}`);
49
+ const issue = await c.issues.getIssue({ issueIdOrKey: issueKey });
50
+ return {
51
+ title: issue.fields.summary,
52
+ assignee: issue.fields.assignee.displayName || "unassigned",
53
+ description: _.truncate(issue.fields.description?.content?.[0]?.content?.[0].text, {
54
+ length: 100,
55
+ }),
56
+ key: issue.key,
57
+ link: `${jiraHost}/browse/${issue.key}`,
58
+ type: issue.fields.issuetype?.name || "unknown",
59
+ };
60
+ }
61
+ async function getMentionedTickets(c, ticketPrefix, jiraHost, commits, logger) {
47
62
  const tickets = new Set();
48
63
  const pattern = new RegExp(`\\b${(0, utils_1.escapeRegExp)(ticketPrefix)}-(\\d+)\\b`, "giu");
49
64
  for (const commit of commits) {
50
65
  const matches = commit.message.match(pattern);
51
66
  if (matches) {
52
67
  for (const match of matches) {
53
- tickets.add(match);
54
68
  logger.info(`Found matching ticket it commit ${match} in ${commit.commit.short}`);
69
+ const issue = await getIssueMetadata(c, match, jiraHost, logger);
70
+ tickets.add(issue);
55
71
  }
56
72
  }
57
73
  }
@@ -69,6 +85,9 @@ async function findOrCreateVersion(c, projectIdOrKey, newVersionName, newVersion
69
85
  }
70
86
  try {
71
87
  logger.info(`Creating new version in jira projectId: ${projectIdOrKey}, versionName: ${newVersionName}`);
88
+ logger.info(`Getting driver info`);
89
+ const driver = await c.myself.getCurrentUser();
90
+ logger.success(`Caller info acquired '${driver.name} / ${driver.emailAddress}'`);
72
91
  const version = await c.projectVersions.createVersion({
73
92
  name: newVersionName,
74
93
  description: newVersionDescription,
@@ -76,6 +95,7 @@ async function findOrCreateVersion(c, projectIdOrKey, newVersionName, newVersion
76
95
  released: true,
77
96
  releaseDate: new Date().toISOString(),
78
97
  archived: false,
98
+ driver: driver.accountId,
79
99
  });
80
100
  logger.success(`Created new jira version ${version.id}`);
81
101
  return version;
@@ -90,7 +110,7 @@ async function editIssueFixVersions(c, ticket, versionId, logger) {
90
110
  logger.info(`Adding issue '${ticket}' to a release '${versionId}'`);
91
111
  c.issues
92
112
  .editIssue({
93
- issueIdOrKey: ticket,
113
+ issueIdOrKey: ticket.key,
94
114
  update: {
95
115
  fixVersions: [
96
116
  {
@@ -126,13 +146,17 @@ async function editIssueFixVersions(c, ticket, versionId, logger) {
126
146
  async function success(config, context) {
127
147
  const { env, logger, commits, nextRelease } = context;
128
148
  const { jiraHost, project: projectKey, ticketPrefix, versionTemplate: definedVersionTemplate, } = config;
129
- const tickets = getMentionedTickets(ticketPrefix, commits, logger);
149
+ const c = (0, jira_client_1.CreateJiraClient)(logger, jiraHost, env.JIRA_EMAIL, env.JIRA_TOKEN);
150
+ const tickets = await getMentionedTickets(c, ticketPrefix, jiraHost, commits, logger);
130
151
  const versionTemplate = _.template(definedVersionTemplate || consts_1.DEFAULT_VERSION_TEMPLATE);
152
+ const descriptionTemplate = handlebars_1.default.compile(consts_1.DEFAULT_RELEASE_DESCRIPTION_TEMPLATE);
131
153
  const newVersionName = versionTemplate({ version: nextRelease.version });
132
- const newVersionDescription = consts_1.DEFAULT_RELEASE_DESCRIPTION_TEMPLATE;
154
+ const newVersionDescription = descriptionTemplate({
155
+ version: newVersionName,
156
+ issues: tickets,
157
+ });
133
158
  logger.info(`Using jira release '${newVersionName}'`);
134
159
  logger.info(`using jira description '${consts_1.DEFAULT_RELEASE_DESCRIPTION_TEMPLATE}'`);
135
- const c = (0, jira_client_1.CreateJiraClient)(logger, jiraHost, env.JIRA_EMAIL, env.JIRA_TOKEN);
136
160
  const project = await c.projects.getProject({ projectIdOrKey: projectKey });
137
161
  if (!project.id) {
138
162
  throw new error_1.default("Missing project id!");
package/dist/types.d.ts CHANGED
@@ -4,3 +4,11 @@ export interface PluginConfig {
4
4
  ticketPrefix: string;
5
5
  versionTemplate: string;
6
6
  }
7
+ export interface JiraIssue {
8
+ title: string;
9
+ key: string;
10
+ assignee: string;
11
+ type: string;
12
+ description: string;
13
+ link: string;
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ondrejbelza/semantic-release-jira",
3
- "version": "1.4.5",
3
+ "version": "1.5.0",
4
4
  "description": "semantic release jira releases plugin",
5
5
  "homepage": "https://github.com/mailstepcz/semantic-release-jira#readme",
6
6
  "bugs": {
@@ -28,6 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@semantic-release/error": "^4.0.0",
31
+ "handlebars": "^4.7.8",
31
32
  "jira.js": "^5.2.2",
32
33
  "lodash": "^4.17.21",
33
34
  "p-limit": "^7.2.0",