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

src/addWatchers.js   A

Size

Lines of Code 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
rs 10
noi 2
c 0
b 0
f 0
1
'use strict'
2
3 1
const _ = require('lodash')
4 1
const async = require('async')
5 1
const debug = require('debug')('jira-resource')
6 1
const request = require('request')
7
8 1
const debugResponse = require('./debugResponse.js')
9
10 1
module.exports = (issue, source, params, callback) => {
11 2
    if ( !issue ) {
12
        return callback(null)
13
    }
14
15 2
    if ( !params.watchers ) {
16
        return callback(null, issue)
17
    }
18
19
    const watchersUrl = source.url + '/rest/api/2/issue/' + issue.id + '/watchers/'
20
21
    debug('Adding watchers...')
22
23
    async.each(params.watchers,
24
        (watcher, next) => {
25
            debug('Adding: %s', watcher)
26
27
            request({
28
                method: 'POST',
29
                uri:    watchersUrl,
30
                auth:   {
31
                    username: source.username,
32
                    password: source.password
33
                },
34
                json:   watcher
35
            }, (error, response) => {
36
                debugResponse(response)
37
                next(error)
38
            })
39
        },
40
        (error) => {
41
            callback(error, issue)
42
        }
43
    )
44
}
45