Skip to content

Commit 22df1ee

Browse files
committed
feat: add jira ticket on pr creation for release
KBDEV-1393
1 parent f928463 commit 22df1ee

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
const https = require('https');
3+
4+
function createJiraTicket() {
5+
const options = {
6+
method: 'POST',
7+
host: process.env.JIRA_BASE_URL,
8+
port: process.env.JIRA_PORT,
9+
path: '/jira/rest/api/2/issue/',
10+
headers: {
11+
Authorization: `Bearer ${process.env.JIRA_API_TOKEN}`,
12+
Accept: 'application/json',
13+
'Content-Type': 'application/json',
14+
},
15+
};
16+
const formattedTitle = `GraphKB Client ${process.env.PR_TITLE}`;
17+
let formattedDesc = '';
18+
19+
const body = process.env.PR_DESCRIPTION;
20+
const lines = body.split('\n').map((l) => l.trim()).filter(Boolean);
21+
22+
let section = '';
23+
const tables = {};
24+
25+
for (let line of lines) {
26+
if (line.startsWith('###')) {
27+
line = '';
28+
} else if (line.startsWith('**')) {
29+
section = line.replace(/\*\*/g, '').trim();
30+
tables[section] = [];
31+
} else if (line.startsWith('[[')) {
32+
const match = line.match(/\[\[(?<title>[A-Z]+-\d+)\]\([^)]+\)\]\s*-\s*(?<description>.+)/);
33+
34+
if (match?.groups) {
35+
const { title, description } = match.groups;
36+
tables[section].push({ title, description });
37+
}
38+
}
39+
}
40+
41+
for (const [sectionName, items] of Object.entries(tables)) {
42+
formattedDesc += `| *${sectionName}* | *Need Review* | *Status* | *Reviewer* | *Description* |\n`;
43+
44+
for (const { title, description } of items) {
45+
formattedDesc += `| ${title} | | | | ${description} |\n`;
46+
}
47+
}
48+
49+
const issueData = JSON.stringify({
50+
fields: {
51+
project: {
52+
key: process.env.JIRA_PROJECT_NAME,
53+
},
54+
summary: formattedTitle,
55+
description: formattedDesc,
56+
issuetype: {
57+
name: process.env.JIRA_ISSUE_TYPE,
58+
},
59+
},
60+
});
61+
62+
console.log('Writing issue: \n', issueData);
63+
64+
const req = https.request(options, (res) => {
65+
res.setEncoding('utf8');
66+
res.on('data', (body) => {
67+
console.log('Body:', body);
68+
});
69+
});
70+
71+
req.on('error', (e) => {
72+
console.error('problem with request:', e.message);
73+
});
74+
75+
req.write(issueData);
76+
req.end();
77+
}
78+
79+
createJiraTicket();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Create JIRA ticket on release PR creation
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
branches:
7+
- master
8+
9+
jobs:
10+
create_ticket:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Check out code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Node.js
18+
uses: actions/setup-node@v3
19+
with:
20+
node-version: 20
21+
22+
- name: Run script
23+
run: node .github/scripts/create-jira-ticket.js
24+
env:
25+
JIRA_PROJECT_NAME: ${{ vars.JIRA_PROJECT_NAME }}
26+
JIRA_ISSUE_TYPE: ${{ vars.JIRA_ISSUE_TYPE }}
27+
JIRA_BASE_URL: ${{ vars.JIRA_BASE_URL }}
28+
JIRA_PORT: ${{ vars.JIRA_PORT }}
29+
JIRA_API_TOKEN: ${{ secrets.JACLI_JIRA_TOKEN }}
30+
PR_TITLE: ${{ github.event.pull_request.title }}
31+
PR_DESCRIPTION: ${{ github.event.pull_request.body }}

0 commit comments

Comments
 (0)