|
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | 4 | var optionsValidation = Joi.object({ |
5 | | - endpoint: Joi.string().min(1).optional().example('https://codacy.com/coverage/:token/:commitId') |
6 | | - }), |
7 | | - tokenValidation = Joi.string().required().min(1).example('1234567890'),//TODO: Revisit this validation to see if we can better validate the values |
8 | | - commitIdValidation = Joi.string().required().min(1).example('1234567890'), //TODO: Revisit this validation to see if we can better validate the values |
9 | | - coverageDataValidation = Joi.object({ |
| 5 | + endpoint: Joi.string().min(1).optional().example('https://codacy.com/coverage/:token/:commitId') |
| 6 | + }); |
| 7 | + var tokenValidation = Joi.string().required().min(1).example('1234567890');//TODO: Revisit this validation to see if we can better validate the values |
| 8 | + var commitIdValidation = Joi.string().required().min(1).example('1234567890'); //TODO: Revisit this validation to see if we can better validate the values |
| 9 | + var coverageDataValidation = Joi.object({ |
| 10 | + total: Joi.number().integer().required().min(0).max(100), |
| 11 | + fileReports: Joi.array().required().items(Joi.object({ |
| 12 | + filename: Joi.string().required().min(1), |
10 | 13 | total: Joi.number().integer().required().min(0).max(100), |
11 | | - fileReports: Joi.array().required().items(Joi.object({ |
12 | | - filename: Joi.string().required().min(1), |
13 | | - total: Joi.number().integer().required().min(0).max(100), |
14 | | - coverage: Joi.object().pattern(/\d/, Joi.number().integer().min(1)) |
15 | | - }).required()) |
16 | | - }).example({total: 50, fileReports: [{filename: 'filename', total: 10, coverage: {1: 1, 2: 3}}]}); |
| 14 | + coverage: Joi.object().pattern(/\d/, Joi.number().integer().min(1)) |
| 15 | + }).required()) |
| 16 | + }).example({total: 50, fileReports: [{filename: 'filename', total: 10, coverage: {1: 1, 2: 3}}]}); |
17 | 17 |
|
18 | 18 | module.exports = function (options) { |
19 | 19 | logger.trace(util.format('Creating reporter for %j', options)); |
|
33 | 33 | sendCoverage: function sendCoverage(token, commitId, data) { |
34 | 34 | return new Promise(function (resolve, reject) { |
35 | 35 | logger.trace(util.format('Sending Coverage for token [%s] and commitId [%s]', token, commitId)); |
36 | | - var tokenValid = Joi.validate(token, tokenValidation), |
37 | | - commitIdValid = Joi.validate(commitId, commitIdValidation), |
38 | | - dataValid = Joi.validate(data, coverageDataValidation, { |
39 | | - stripUnknown: true |
40 | | - }), |
41 | | - validationErr = tokenValid.error || commitIdValid.error || dataValid.error; |
| 36 | + var tokenValid = Joi.validate(token, tokenValidation); |
| 37 | + var commitIdValid = Joi.validate(commitId, commitIdValidation); |
| 38 | + var dataValid = Joi.validate(data, coverageDataValidation, { |
| 39 | + stripUnknown: true |
| 40 | + }); |
| 41 | + var validationErr = tokenValid.error || commitIdValid.error || dataValid.error; |
42 | 42 |
|
43 | 43 | if (validationErr) { |
44 | 44 | logger.error(validationErr); |
|
0 commit comments