forked from cybervoid/gajira-get-issue
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (42 loc) · 1.35 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
const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs');
const inputText = core.getInput('input-text');
try {
const issue = findIssue(inputText);
if (issue) {
issueFound(issue);
} else {
console.log("Issue not found on provided input: " + inputText);
//try to search in github object
const commitMessages = github.context.payload.commits;
if (commitMessages) {
let res = commitMessages.some(function (element) {
const issue = findIssue(element.message);
if (issue) {
issueFound(issue);
return true;
} else {
core.setOutput("issue", '');
}
});
}
}
} catch (error) {
core.setFailed(error.message);
}
function findIssue(text) {
return (/APF-\d*/gim.exec(text)||[''])[0];
}
function issueFound(issue) {
console.log("Issue found, Jira number: " + issue);
core.setOutput("issue", issue);
const filePath = require('os').homedir() + '/jira/';
const fileName = 'config.yml';
try {
fs.mkdirSync(filePath, {recursive: true});
fs.appendFileSync(filePath + fileName, 'issue: ' + issue + '\r\n')
} catch (e) {
core.setFailed('Error trying to create the file ' + fileName);
}
}