Passed
Branch qa (4c4729)
by André
02:10
created

T_CONST ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 1
rs 10
c 2
b 0
f 0
cc 1
nc 1
nop 3
1
const _ = require('lodash')
2
const async = require('async')
3
const debug = require('debug')('jira-resource')
4
const request = require('request')
5
6
const debugResponse = require('./debugResponse.js')
7
8
module.exports = (issue, source, params, callback) => {
9
    if ( !issue ) {
10
        return callback(null)
11
    }
12
13
    if ( !params.transitions ) {
14
        return callback(null, issue)
15
    }
16
17
    const transitionUrl = source.url + '/rest/api/2/issue/' + issue.id + '/transitions/'
18
19
    async.eachSeries(params.transitions, (nextTransition, next) => {
20
        processTransition(transitionUrl, nextTransition, () => {
21
            next()
22
        })
23
    }, () => {
24
        callback(null, issue)
25
    })
26
27
    function processTransition (transitionUrl, transitionName, done) {
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
Bug introduced by
The function processTransition is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var processTransition = function() { /* ... */ }; instead.
Loading history...
28
        async.waterfall([
29
            (next) => {
30
                debug('Searching for available transitions...')
31
32
                request({
33
                    method: 'GET',
34
                    uri:    transitionUrl,
35
                    auth:   {
36
                        username: source.username,
37
                        password: source.password
38
                    },
39
                    json:   true
40
                }, (error, response, body) => {
41
                    debugResponse(response)
42
43
                    let transitionId = _.filter(body.transitions, (transition) => {
44
                        return transition.name.toLowerCase() == transitionName.toLowerCase()
45
                    })[0].id
46
47
                    next(error, transitionId)
48
                })
49
            },
50
            (transitionId, done) => {
51
                debug('Performing transition: %s (%s)', transitionName, transitionId)
52
53
                request({
54
                    method: 'POST',
55
                    uri:    transitionUrl,
56
                    auth:   {
57
                        username: source.username,
58
                        password: source.password
59
                    },
60
                    json:   {
61
                        transition: {
62
                            id: transitionId
63
                        }
64
                    }
65
                }, (error, response) => {
66
                    debugResponse(response)
67
                    done(error)
68
                })
69
            }
70
        ], done)
71
    }
72
}
73