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

src/check.js   A

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 42
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A check.js ➔ ??? 0 40 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
			console.log(topic)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
24
			client.subscribe(topic, (errorConnection) => {
25
				if ( !errorConnection ) {
26
					client.on('message', (topic, message) => {
27
						version = message.toString()
28
						client.end()
29
					})
30
				} else {
31
					error = errorConnection
32
				}
33
			})
34
		})
35
36
		output = [
37
			{'ref': version}
38
		]
39
	}
40
41
	callback(error, output)
42
}
43