|
1 | 1 | var debug = require('debug')('strider-github-status'); |
2 | 2 | var setStatus = require('./lib/handler'); |
3 | 3 |
|
4 | | -function jobStatus(job) { |
5 | | - if (job.errored) return 'error'; |
6 | | - return job.test_exitcode === 0 ? 'success' : 'failure'; |
7 | | -} |
8 | | - |
9 | 4 | // TODO: give information here as to why it errored/failed? |
10 | | -function jobDescription(job) { |
11 | | - if (job.errored) return 'Strider tests errored'; |
12 | | - return 'Strider tests ' + (job.test_exitcode === 0 ? 'succeeded' : 'failed'); |
| 5 | +function jobInfo(job, config) { |
| 6 | + var info = {}; |
| 7 | + |
| 8 | + if (job.errored) info.status = 'error'; |
| 9 | + else if (job.test_exitcode === 0) info.status = 'success'; |
| 10 | + else info.status = 'failure'; |
| 11 | + |
| 12 | + info.description = config.messages[info.status]; |
| 13 | + info.context = config.context; |
| 14 | + |
| 15 | + return info; |
13 | 16 | } |
14 | 17 |
|
15 | 18 | module.exports = { |
| 19 | + config: { |
| 20 | + messages: { |
| 21 | + pending: {type: String, default: 'Strider test in progress'}, |
| 22 | + success: {type: String, default: 'Strider tests succeeded'}, |
| 23 | + failure: {type: String, default: 'Strider tests failed'}, |
| 24 | + error: {type: String, default: 'Strider tests errored'}, |
| 25 | + }, |
| 26 | + context: {type: String, default: 'ci/strider'}, |
| 27 | + }, |
16 | 28 | // global events |
17 | 29 | listen: function (io, context) { |
18 | | - io.on('plugin.github-status.started', function (jobId, projectName, token, data) { |
| 30 | + io.on('plugin.github-status.started', function (jobId, projectName, token, data, config) { |
19 | 31 | debug('got', jobId, projectName, token, data); |
20 | 32 | var url = context.config.server_name + '/' + projectName + '/job/' + jobId; |
21 | | - setStatus(token, url, data, 'pending', 'Strider test in progress'); |
| 33 | + setStatus(token, url, data, 'pending', config.messages.pending, config.context); |
22 | 34 | }); |
23 | 35 |
|
24 | | - io.on('plugin.github-status.done', function (jobId, projectName, token, data) { |
| 36 | + io.on('plugin.github-status.done', function (jobId, projectName, token, data, config) { |
25 | 37 | function onDoneAndSaved(job) { |
26 | 38 | if (job._id.toString() !== jobId.toString()) return; |
27 | 39 | debug('plugin done', jobId, projectName, token, data); |
28 | 40 |
|
29 | 41 | io.removeListener('job.doneAndSaved', onDoneAndSaved); |
30 | 42 | var url = context.config.server_name + '/' + projectName + '/job/' + jobId |
31 | | - , status = jobStatus(job) |
32 | | - , description = jobDescription(job); |
33 | | - setStatus(token, url, data, status, description); |
| 43 | + , info = jobInfo(job, config); |
| 44 | + setStatus(token, url, data, info.status, info.description, info.context); |
34 | 45 | } |
35 | 46 | io.on('job.doneAndSaved', onDoneAndSaved); |
36 | 47 | }); |
|
0 commit comments