Skip to content

Commit

Permalink
Updated the build
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterclaerhout committed Sep 21, 2023
1 parent b9a8f31 commit f072ada
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,12 @@ class JiraKey {
}
exports.JiraKey = JiraKey;
class JiraIssue {
constructor(key, link, title, type) {
constructor(key, link, title, type, fixVersions) {
this.key = key;
this.link = link;
this.title = title;
this.type = type;
this.fixVersions = fixVersions;
}
toString() {
return `${this.key} | ${this.type} | ${this.title}`;
Expand Down Expand Up @@ -266,20 +267,26 @@ class JiraClient {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const res = yield this.client.get(this.getRestApiUrl(`issue/${key}?fields=issuetype,summary`));
const res = yield this.client.get(this.getRestApiUrl(`issue/${key}?fields=issuetype,summary,fixVersions`));
const body = yield res.readBody();
const obj = JSON.parse(body);
var issuetype = undefined;
var title = undefined;
var fixVersions = undefined;
for (let field in obj.fields) {
if (field === "issuetype") {
issuetype = (_a = obj.fields[field].name) === null || _a === void 0 ? void 0 : _a.toLowerCase();
}
else if (field === "summary") {
title = obj.fields[field];
}
else if (field === "fixVersions") {
fixVersions = obj.fields[field]
.map(({ name }) => name)
.filter(Boolean);
}
}
return new JiraIssue(key, `${this.baseUrl}/browse/${key}`, title, issuetype);
return new JiraIssue(key, `${this.baseUrl}/browse/${key}`, title, issuetype, fixVersions);
}
catch (error) {
if (error.response) {
Expand Down Expand Up @@ -346,6 +353,22 @@ class Updater {
}
return `${body}\n\n[**${this.jiraIssue.key}** | ${this.jiraIssue.title}](${this.jiraIssue.link})`.trim();
}
addFixVersionsToBody(body) {
const { fixVersions } = this.jiraIssue;
if (!(fixVersions === null || fixVersions === void 0 ? void 0 : fixVersions.length)) {
return body;
}
if (!body) {
body = "";
}
if (body.includes("**Fix versions**:")) {
body = body.replace(/\*\*Fix versions\*\*:.*$/, `**Fix versions**: ${fixVersions.join(",")}`);
}
else {
body = `${body}\n\n**Fix versions**: ${fixVersions.join(",")}`.trim();
}
return body;
}
}
exports.Updater = Updater;

Expand Down Expand Up @@ -412,6 +435,7 @@ function run() {
const issueTypeLabelDescription = core.getInput("issue-type-label-description") || "Jira Issue Type";
const addJiraKeyToTitle = core.getBooleanInput("add-jira-key-to-title");
const addJiraKeyToBody = core.getBooleanInput("add-jira-key-to-body");
const addJiraFixVersionsToBody = core.getBooleanInput("add-jira-fix-versions-to-body");
const githubClient = new github_client_1.GithubClient(githubToken);
const jiraClient = new jira_client_1.JiraClient(jiraBaseUrl, jiraUsername, jiraToken, jiraProjectKey);
const pullRequest = yield githubClient.getPullRequest();
Expand Down Expand Up @@ -464,6 +488,9 @@ function run() {
core.info(` Updating pull request body`);
pullRequest.body = updater.body(pullRequest.body);
}
if (addJiraFixVersionsToBody) {
pullRequest.body = updater.addFixVersionsToBody(pullRequest.body);
}
core.info(` Updating pull request`);
yield githubClient.updatePullRequest(pullRequest);
}
Expand Down

0 comments on commit f072ada

Please sign in to comment.