-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (50 loc) · 1.69 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const core = require('@actions/core');
const github = require('@actions/github');
const main = async () => {
const owner = core.getInput('owner', { required: true });
const repo = core.getInput('repo', { required: true });
const pr_number = core.getInput('pr_number', { required: true });
const token = core.getInput('token', { required: true });
const orgName = core.getInput('jira_org', { required: true});
const ticketPrefix = core.getInput('ticket_prefixes', { required: true});
const octokit = new github.getOctokit(token);
const ticketPrefixes = []
for (let p of ticketPrefix.split(",")) {
ticketPrefixes.push(p)
}
const prTitle = github.context.payload.pull_request.title
const issueNumbers = []
for (let p of ticketPrefixes) {
match = prTitle.match(RegExp(`${p}-[0-9]+`, "g"))
if (match !== null) {
issueNumbers.push(match)
}
}
if (issueNumbers.length === 0) {
try {
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: pr_number,
body: `
No JIRA issue number found in PR title
`
});
} catch (error) {
core.setFailed(error.message);
}
}
const jiraIssue = issueNumbers[0]
try {
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: pr_number,
body: `This PR contains changes referring to ticket [${jiraIssue}](https://${orgName}.atlassian.net/browse/${jiraIssue})`
});
} catch (error) {
core.setFailed(error.message);
}
}
// Call the main function to run the action
main();