-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.js
56 lines (43 loc) · 1.56 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
const _ = require('lodash')
const Jira = require('./common/net/Jira')
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
const issueId = argv.issue
const { transitions } = await this.Jira.getIssueTransitions(issueId)
const transitionName = argv._.join(' ')
const transitionToApply = _.find(transitions, (t) => {
if (t.id === argv.id) return true
if (transitionName.toLowerCase() === t.name.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.`)
})
return
}
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 {}
}
}