| Total Complexity | 7 |
| Complexity/F | 1.4 |
| Lines of Code | 40 |
| Function Count | 5 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 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 |