Passed
Pull Request — master (#2)
by André
02:38 queued 24s
created

src/check.js   A

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 40
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

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