forked from Broadshield/gajira-find-issue-key
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·90 lines (72 loc) · 2.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const fs = require('fs')
const YAML = require('yaml')
const core = require('@actions/core')
const cliConfigPath = `${process.env.HOME}/.jira.d/config.yml`
const configPath = `${process.env.HOME}/jira/config.yml`
core.debug('Requiring Action')
const Action = require('./action')
core.debug('Requiring Github Event Path')
const githubEvent = process.env.GITHUB_EVENT_PATH ? require(process.env.GITHUB_EVENT_PATH) : []
const config = YAML.parse(fs.readFileSync(configPath, 'utf8'))
async function writeKey(result) {
if (!result) {
return
}
core.debug(`Detected issueKey: ${result.get('key')}`)
core.debug(`Saving ${result.get('key')} to ${cliConfigPath}`)
core.debug(`Saving ${result.get('key')} to ${configPath}`)
// Expose created issue's key as an output
const yamledResult = YAML.stringify(result)
const extendedConfig = { ...config, ...result }
fs.writeFileSync(configPath, YAML.stringify(extendedConfig))
return fs.appendFileSync(cliConfigPath, yamledResult)
}
async function exec() {
try {
const result = await new Action({
githubEvent,
argv: parseArgs(),
config,
}).execute()
if (result) {
core.debug(`Result was returned.`)
if (Array.isArray(result)) {
core.debug('Result is an array')
const outputIssues = []
for (const item of result) {
await writeKey(item)
outputIssues.push(item.get('key'))
}
core.setOutput('issues', outputIssues.join(','))
return
}
core.debug('Result is not an array')
core.setOutput('issue', result.get('key'))
return await writeKey(result)
}
core.debug('No issueKeys found.')
core.setNeutral()
} catch (error) {
core.setFailed(error.toString())
}
}
function parseArgs() {
const fromList = ['commits', 'pull_request', 'branch']
return {
event: core.getInput('event') || config.event,
string: core.getInput('string') || config.string,
from: fromList.includes(core.getInput('from')) ? core.getInput('from') : 'commits',
githubToken: core.getInput('github-token'),
headRef: core.getInput('head-ref'),
baseRef: core.getInput('base-ref'),
includeMergeMessages: core.getInput('include-merge-messages') === 'true',
returns: core.getInput('returns') || 'first',
updatePRTitle: core.getInput('standardize-pr-title') === 'true',
transitionChain: core.getInput('jira-transition-chain'),
transitionOnNewBranch: core.getInput('jira-transition-on-new-branch'),
transitionOnPrOpen: core.getInput('jira-transition-on-pr-open'),
transitionOnPrApproval: core.getInput('jira-transition-on-pr-approval'),
transitionOnPrMerge: core.getInput('jira-transition-on-pr-merge'),
}
}
exec()