-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
38 lines (31 loc) · 1.1 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
const core = require('@actions/core')
const { setupJiraClient } = require('./helpers/jira')
const jiraClient = setupJiraClient()
const filterCustomIssueFields = (issues) => {
return issues.map(issue => {
issue.fields = Object.keys(issue.fields)
.filter(key => !key.startsWith('customfield'))
.reduce((obj, key) => {
obj[key] = issue.fields[key]
return obj
}, {})
delete issue.expand
return issue
})
}
const fieldsInput = core.getInput('fields')
const fields = fieldsInput ? fieldsInput.split(',') : []
const maxResultsInput = parseInt(core.getInput('maxResults'), 10)
const options = {
maxResults: !isNaN(maxResultsInput) ? maxResultsInput : 50
}
if (fields.length) {
options.fields = fields
}
jiraClient.searchJira(core.getInput('jql'), options).then(response => {
const issues = !fields.length ? filterCustomIssueFields(response.issues) : response.issues
core.setOutput('issueData', JSON.stringify({ issues, quantity: issues.length }))
console.log('Completed search')
}).catch(err => {
core.setFailed(`An error occurred getting data from JIRA: ${err}`)
})