forked from atlassian/gajira-transition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.js
69 lines (54 loc) · 2.02 KB
/
action.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
const { countReset } = require('console')
const _ = require('lodash')
const Jira = require('./common/net/Jira')
const core = require('@actions/core')
const fs = require('fs');
module.exports = class {
constructor ({ githubEvent, argv, config }) {
this.Jira = new Jira({
baseUrl: config.baseUrl,
token: config.token,
email: config.email,
})
this.config = config
this.argv = argv
this.githubEvent = githubEvent
}
async execute () {
const { argv } = this
console.log('Parsing file now')
const issueListPath = `${process.env.GITHUB_WORKSPACE}/${argv.issueList}`
const fileContents = fs.readFileSync(issueListPath, 'utf-8')
const arr = fileContents.split(/\r?\n/)
console.log(`Read array of issues: ${arr}`)
for(const issueId of arr){
if(!(/[A-Z][A-Z]+-[0-9]+/.test(issueId))){
continue
}
const { transitions } = await this.Jira.getIssueTransitions(issueId)
const transitionToApply = _.find(transitions, (t) => {
if (t.id === argv.transitionId) return true
if (t.name.toLowerCase() === argv.transition.toLowerCase()) return true
})
if (!transitionToApply) {
console.log('Please specify transition name or transition id.')
console.log('Possible transitions:')
transitions.forEach((t) => {
console.log(`{ id: ${t.id}, name: ${t.name} } transitions issue to '${t.to.name}' status.`)
})
continue
}
console.log(`Selected transition:${JSON.stringify(transitionToApply, null, 4)}`)
await this.Jira.transitionIssue(issueId, {
transition: {
id: transitionToApply.id,
},
})
const transitionedIssue = await this.Jira.getIssue(issueId)
// console.log(`transitionedIssue:${JSON.stringify(transitionedIssue, null, 4)}`)
console.log(`Changed ${issueId} status to : ${_.get(transitionedIssue, 'fields.status.name')} .`)
console.log(`Link to issue: ${this.config.baseUrl}/browse/${issueId}`)
}
return {}
}
}