Passed
Pull Request — master (#2)
by André
01:31
created

src/check.js   A

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 41
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 7
eloc 26
c 1
b 0
f 0
nc 1
mnd 2
bc 8
fnc 5
dl 0
loc 41
rs 10
bpm 1.6
cpm 1.4
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A check.js ➔ ??? 0 39 2
1
'use strict'
2
3
module.exports = (input, callback) => {
4
	const mqtt = require('mqtt')
5
	const validate = require('./validate')
6
	const configuration = require('./configuration')
7
	let error = null
8
	let output = null
9
10
	validate.sourceConfiguration(input, (validatedInput, thrownError) => {
11
		input = validatedInput
12
		error = thrownError
13
	})
14
15
	// Send MQTT
16
	if ( !error ) {
17
		let configurationMqtt = configuration.mqtt(input)
18
		let client = mqtt.connect(input.source.url, configurationMqtt)
19
		let version = null
20
21
		client.on('connect', () => {
22
			let topic = input.source.prefix + '/' + process.env.BUILD_TEAM_NAME + '/' + process.env.BUILD_PIPELINE_NAME
23
			client.subscribe(topic, (errorConnection) => {
24
				if ( !errorConnection ) {
25
					client.on('message', (topic, message) => {
26
						version = message.toString()
27
						client.end()
28
					})
29
				} else {
30
					error = errorConnection
31
				}
32
			})
33
		})
34
35
		output = [
36
			{'ref': version}
37
		]
38
	}
39
40
	callback(error, output)
41
}
42