Skip to content

Commit 0b4aae9

Browse files
authored
fix: create-jira action to set exit code (#29)
1 parent 3c5fccb commit 0b4aae9

File tree

10 files changed

+158
-123
lines changed

10 files changed

+158
-123
lines changed

.github/workflows/dependabot-update-dist.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: Commit dist
3838
run: |
3939
echo "Changes to dist files:"
40-
if git diff --exit-code verify-changed-files/dist create-jira/dist; then
40+
if git diff --exit-code --name-status -- verify-changed-files/dist create-jira/dist; then
4141
echo "No changes to dist folders"
4242
else
4343
git config --global user.name "${{ steps.app-token.outputs.user-name }}"

create-jira/__tests__/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as core from '@actions/core';
22
import * as request from 'request';
3-
import { main, JiraIssue } from '../src/index';
3+
import { main, JiraIssue } from '../src/lib';
44

55
jest.mock('@actions/core');
66
jest.mock('request');

create-jira/dist/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This file is autogenerated. Do not edit manually. Run `npm run build` to regenerate.
2+
13
import require$$0$2 from 'os';
24
import require$$0$3 from 'crypto';
35
import require$$1$1 from 'fs';
@@ -88812,7 +88814,7 @@ function requireLodash () {
8881288814

8881388815
var lodashExports = requireLodash();
8881488816

88815-
// Copyright 2024 MongoDB Inc
88817+
// Copyright 2025 MongoDB Inc
8881688818
//
8881788819
// Licensed under the Apache License, Version 2.0 (the "License");
8881888820
// you may not use this file except in compliance with the License.
@@ -88916,7 +88918,19 @@ async function main() {
8891688918
}
8891788919
}
8891888920
}
88919-
main();
8892088921

88921-
export { main };
88922+
// Copyright 2024 MongoDB Inc
88923+
//
88924+
// Licensed under the Apache License, Version 2.0 (the "License");
88925+
// you may not use this file except in compliance with the License.
88926+
// You may obtain a copy of the License at
88927+
//
88928+
// http://www.apache.org/licenses/LICENSE-2.0
88929+
//
88930+
// Unless required by applicable law or agreed to in writing, software
88931+
// distributed under the License is distributed on an "AS IS" BASIS,
88932+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
88933+
// See the License for the specific language governing permissions and
88934+
// limitations under the License.
88935+
main().finally(() => process.exit());
8892288936
//# sourceMappingURL=index.js.map

create-jira/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

create-jira/rollup.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export default {
88
output: {
99
file: 'dist/index.js',
1010
format: 'es',
11-
sourcemap: true
11+
sourcemap: true,
12+
banner: '// This file is autogenerated. Do not edit manually. Run `npm run build` to regenerate.\n'
1213
},
1314
plugins: [
1415
nodeResolve({

create-jira/src/index.ts

Lines changed: 2 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -12,117 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import * as core from '@actions/core';
16-
import request from 'request';
17-
import { merge, mergeWith, isArray } from 'lodash';
15+
import { main } from './lib.js';
1816

19-
export interface JiraIssue {
20-
fields: {
21-
project: { key: string };
22-
summary: string;
23-
description?: string;
24-
issuetype?: { name: string };
25-
assignee?: { name: string };
26-
labels?: string[];
27-
components?: { name: string }[];
28-
[key: string]: any;
29-
};
30-
}
31-
32-
function buildRequestBody(projectKey: string, summary: string, description: string, issuetype: string, labels: string[], components: string[], assignee: string, extraData?: { [key: string]: any }): JiraIssue {
33-
const body: JiraIssue = { fields: { project: { key: projectKey }, summary: summary } };
34-
if (description != "") {
35-
body.fields.description = description;
36-
}
37-
if (issuetype != "") {
38-
body.fields.issuetype = { name: issuetype };
39-
}
40-
if (assignee != "") {
41-
body.fields.assignee = { name: assignee };
42-
}
43-
if (labels.length != 0) {
44-
body.fields.labels = labels;
45-
}
46-
if (components.length != 0) {
47-
body.fields.components = components.map(value => {
48-
return { name: value };
49-
});
50-
}
51-
mergeWith(body, extraData, (dst, src) => {
52-
if (isArray(dst)) {
53-
return dst.concat(src);
54-
}
55-
});
56-
return body;
57-
}
58-
59-
async function createJiraIssue(token: string, apiBase: string, projectKey: string, summary: string, description: string, issuetype: string, labels: string[], components: string[], assignee: string, extraData?: { [key: string]: any }): Promise<{ response: request.Response, responseBody: any }> {
60-
const body = buildRequestBody(projectKey, summary, description, issuetype, labels, components, assignee, extraData);
61-
62-
return await new Promise((resolve, reject) => {
63-
request({
64-
url: `${apiBase}/rest/api/2/issue`,
65-
method: "POST",
66-
headers: {
67-
"Content-Type": "application/json",
68-
Authorization: "Bearer " + token,
69-
},
70-
body: body,
71-
json: true
72-
}, (err: any, response: request.Response, responseBody: any) => {
73-
if (err != null) {
74-
reject(err);
75-
return;
76-
}
77-
if (response.statusCode >= 400) {
78-
reject(new Error(response.statusCode + " " + response.statusMessage + "\n" + JSON.stringify(responseBody)));
79-
return;
80-
}
81-
resolve({
82-
response, responseBody
83-
});
84-
});
85-
});
86-
}
87-
88-
export async function main() {
89-
try {
90-
const token = core.getInput('token');
91-
const projectKey = core.getInput('project-key');
92-
const summary = core.getInput('summary');
93-
const description = core.getInput('description');
94-
const issuetype = core.getInput('issuetype');
95-
const labels = core.getInput('labels');
96-
const components = core.getInput('components');
97-
const assignee = core.getInput('assignee');
98-
const extraData = core.getInput('extra-data');
99-
const apiBase = core.getInput('api-base');
100-
const labelList = labels.split(",").filter(value => value != "");
101-
const componentList = components.split(",").filter(value => value != "");
102-
103-
let extraDataObject: { [key: string]: any } | undefined = undefined;
104-
if (extraData != "") {
105-
try {
106-
extraDataObject = JSON.parse(extraData);
107-
} catch (error) {
108-
throw new Error("Error parsing extra-data: " + error);
109-
}
110-
}
111-
112-
const { responseBody } = await createJiraIssue(token, apiBase, projectKey, summary, description, issuetype, labelList, componentList, assignee, extraDataObject);
113-
114-
if (!responseBody.key) {
115-
throw new Error("No issue key found in response: " + JSON.stringify(responseBody));
116-
}
117-
118-
core.setOutput("issue-key", responseBody.key);
119-
} catch (error) {
120-
if (error instanceof Error) {
121-
core.setFailed(error);
122-
} else {
123-
core.setFailed(JSON.stringify(error));
124-
}
125-
}
126-
}
127-
128-
main();
17+
main().finally(() => process.exit());

create-jira/src/lib.ts

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright 2025 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import * as core from '@actions/core';
16+
import request from 'request';
17+
import { mergeWith, isArray } from 'lodash';
18+
19+
export interface JiraIssue {
20+
fields: {
21+
project: { key: string };
22+
summary: string;
23+
description?: string;
24+
issuetype?: { name: string };
25+
assignee?: { name: string };
26+
labels?: string[];
27+
components?: { name: string }[];
28+
[key: string]: any;
29+
};
30+
}
31+
32+
function buildRequestBody(projectKey: string, summary: string, description: string, issuetype: string, labels: string[], components: string[], assignee: string, extraData?: { [key: string]: any }): JiraIssue {
33+
const body: JiraIssue = { fields: { project: { key: projectKey }, summary: summary } };
34+
if (description != "") {
35+
body.fields.description = description;
36+
}
37+
if (issuetype != "") {
38+
body.fields.issuetype = { name: issuetype };
39+
}
40+
if (assignee != "") {
41+
body.fields.assignee = { name: assignee };
42+
}
43+
if (labels.length != 0) {
44+
body.fields.labels = labels;
45+
}
46+
if (components.length != 0) {
47+
body.fields.components = components.map(value => {
48+
return { name: value };
49+
});
50+
}
51+
mergeWith(body, extraData, (dst, src) => {
52+
if (isArray(dst)) {
53+
return dst.concat(src);
54+
}
55+
});
56+
return body;
57+
}
58+
59+
async function createJiraIssue(token: string, apiBase: string, projectKey: string, summary: string, description: string, issuetype: string, labels: string[], components: string[], assignee: string, extraData?: { [key: string]: any }): Promise<{ response: request.Response, responseBody: any }> {
60+
const body = buildRequestBody(projectKey, summary, description, issuetype, labels, components, assignee, extraData);
61+
62+
return await new Promise((resolve, reject) => {
63+
request({
64+
url: `${apiBase}/rest/api/2/issue`,
65+
method: "POST",
66+
headers: {
67+
"Content-Type": "application/json",
68+
Authorization: "Bearer " + token,
69+
},
70+
body: body,
71+
json: true
72+
}, (err: any, response: request.Response, responseBody: any) => {
73+
if (err != null) {
74+
reject(err);
75+
return;
76+
}
77+
if (response.statusCode >= 400) {
78+
reject(new Error(response.statusCode + " " + response.statusMessage + "\n" + JSON.stringify(responseBody)));
79+
return;
80+
}
81+
resolve({
82+
response, responseBody
83+
});
84+
});
85+
});
86+
}
87+
88+
export async function main() {
89+
try {
90+
const token = core.getInput('token');
91+
const projectKey = core.getInput('project-key');
92+
const summary = core.getInput('summary');
93+
const description = core.getInput('description');
94+
const issuetype = core.getInput('issuetype');
95+
const labels = core.getInput('labels');
96+
const components = core.getInput('components');
97+
const assignee = core.getInput('assignee');
98+
const extraData = core.getInput('extra-data');
99+
const apiBase = core.getInput('api-base');
100+
const labelList = labels.split(",").filter(value => value != "");
101+
const componentList = components.split(",").filter(value => value != "");
102+
103+
let extraDataObject: { [key: string]: any } | undefined = undefined;
104+
if (extraData != "") {
105+
try {
106+
extraDataObject = JSON.parse(extraData);
107+
} catch (error) {
108+
throw new Error("Error parsing extra-data: " + error);
109+
}
110+
}
111+
112+
const { responseBody } = await createJiraIssue(token, apiBase, projectKey, summary, description, issuetype, labelList, componentList, assignee, extraDataObject);
113+
114+
if (!responseBody.key) {
115+
throw new Error("No issue key found in response: " + JSON.stringify(responseBody));
116+
}
117+
118+
core.setOutput("issue-key", responseBody.key);
119+
} catch (error) {
120+
if (error instanceof Error) {
121+
core.setFailed(error);
122+
} else {
123+
core.setFailed(JSON.stringify(error));
124+
}
125+
}
126+
}

verify-changed-files/dist/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This file is autogenerated. Do not edit manually. Run `npm run build` to regenerate.
12
/******/ (() => { // webpackBootstrap
23
/******/ var __webpack_modules__ = ({
34

@@ -25769,7 +25770,9 @@ async function run() {
2576925770
}
2577025771
// Only call run() if executed directly
2577125772
if (require.main === require.cache[eval('__filename')]) {
25772-
run();
25773+
run().finally(() => {
25774+
process.exit();
25775+
});
2577325776
}
2577425777

2577525778

verify-changed-files/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "GitHub Action to check if files have changed and output the results",
66
"main": "dist/index.js",
77
"scripts": {
8-
"build": "ncc build src/index.ts -o dist",
8+
"build": "ncc build src/index.ts -o dist && echo '// This file is autogenerated. Do not edit manually. Run `npm run build` to regenerate.' | cat - dist/index.js > temp && mv temp dist/index.js",
99
"test": "jest",
1010
"test:watch": "jest --watch",
1111
"format": "prettier --write **/*.ts",

verify-changed-files/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,7 @@ export async function run(): Promise<void> {
9393

9494
// Only call run() if executed directly
9595
if (require.main === module) {
96-
run();
96+
run().finally(() => {
97+
process.exit();
98+
});
9799
}

0 commit comments

Comments
 (0)