Passed
Push — master ( 2fc875...74c3e1 )
by André
45s
created

src/out.js   A

Size

Lines of Code 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 1
rs 10
noi 0
1
'use strict'
2
3
const async = require('async')
4
const debug = require('debug')('jira-resource')
5
6
const addWatchers = require('./addWatchers.js')
7
const createOrUpdateIssue = require('./createOrUpdateIssue.js')
8
const processTransitions = require('./processTransitions')
9
const searchBySummary = require('./searchBySummary.js')
10
11
module.exports = (input, baseFileDir, callback) => {
12
    const source = input.source
13
    const params = input.params
14
15
    debug('Searching for issue: %s', input.params.summary)
16
17
    async.waterfall([
18
        (next) => {
19
            searchBySummary(baseFileDir, source, params, next)
20
        },
21
        (issue, next) => {
22
            createOrUpdateIssue(baseFileDir, issue, source, params, next)
23
        },
24
        (issue, next) => {
25
            addWatchers(issue, source, params, next)
26
        },
27
        (issue, next) => {
28
            processTransitions(issue, source, params, next)
29
        }
30
    ], (error, issue) => {
31
        let output = null
32
33
        if ( issue ) {
34
            output = {
35
                version: {
36
                    ref: issue.key
37
                }
38
            }
39
        } else if ( !error ) {
40
            error = new Error('Could not create issue.')
41
        }
42
43
        callback(error, output)
44
    })
45
}
46