Skip to content

Commit 868e6b9

Browse files
SAAS-5972 print errors in eslint style for pipeline validation (#412)
* SAAS-5972 As a user I want to see errors and warnings in eslint style when I validate pipeline from cli * SAAS-5972 As a user I want to see errors and warnings in eslint style when I validate pipeline from cli * SAAS-5972 As a user I want to see errors and warnings in eslint style when I validate pipeline from cli * SAAS-5972 As a user I want to see errors and warnings in eslint style when I validate pipeline from cli
1 parent e02febc commit 868e6b9

File tree

5 files changed

+52
-18
lines changed

5 files changed

+52
-18
lines changed

lib/interface/cli/commands/root/validate.cmd.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@ const Style = require('../../../../output/Style');
44
const path = require('path');
55
const { validatePipelineYaml } = require('../../helpers/validation');
66
const { pathExists, watchFile } = require('../../helpers/general');
7+
const { PipelineValidationError } = require('../../../../logic/cli-config/errors');
78

89
const VALID_MESSAGE = Style.green('Yaml is valid!');
910

1011
function _getResultMessage(result = {}) {
11-
if (result.warning) {
12-
return result.valid
13-
? `${Style.yellow(result.warning)}`
14-
: `${Style.red(result.message)}\n${Style.yellow(result.warning)}\n`;
12+
if (result.summarize) {
13+
if (result.valid && !result.warning) {
14+
return VALID_MESSAGE;
15+
}
16+
let message = '';
17+
if (result.warning) {
18+
message += `${result.warning}\n`;
19+
}
20+
if (result.message) {
21+
message += `${result.message}\n`;
22+
}
23+
message += `${result.summarize}\n${result.documentationLinks}`;
24+
return message;
1525
}
1626
return result.valid
1727
? VALID_MESSAGE
@@ -26,7 +36,7 @@ function _handleResult(result = {}, attach) {
2636
if (result.valid || attach) {
2737
return printResult(result);
2838
}
29-
throw Error(_getResultMessage(result));
39+
throw new PipelineValidationError(_getResultMessage(result));
3040
}
3141

3242
const validateCmd = new Command({

lib/interface/cli/helpers/validation.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,41 @@ async function validatePipelineSpec(data) {
3737
yamlObj.stages = stages;
3838
}
3939
const validatedYaml = yaml.safeDump(yamlObj);
40-
const result = await sdk.pipelines.validateYaml({ yaml: validatedYaml });
40+
const result = await sdk.pipelines.validateYaml({ yaml: validatedYaml, outputFormat: 'lint' });
4141
let message;
42-
let warning;
42+
if (result.summarize) {
43+
return {
44+
valid: !!result.valid,
45+
message: result.message,
46+
warning: result.warningMessage,
47+
summarize: result.summarize,
48+
documentationLinks: result.documentationLinks,
49+
};
50+
}
4351
if (!result.valid) {
4452
message = _buildFinalMessage('Provided spec is not valid', result.details);
4553
}
46-
if (!_.isEmpty(result.warningDetails)) {
47-
warning = _buildFinalMessage('Yaml has warnings', result.warningDetails);
48-
}
49-
return { valid: !!result.valid, message, warning };
54+
return { valid: !!result.valid, message };
5055
}
5156

5257
async function validatePipelineYaml(filename, fileContent) {
5358
const yamlContent = fileContent || await readFile(filename, 'UTF-8');
5459
const name = _getPipelineName(filename);
55-
const result = await sdk.pipelines.validateYaml({ yaml: yamlContent, name });
60+
const result = await sdk.pipelines.validateYaml({ yaml: yamlContent, name, outputFormat: 'lint' });
5661
let message;
57-
let warning;
62+
if (result.summarize) {
63+
return {
64+
valid: !!result.valid,
65+
message: result.message,
66+
warning: result.warningMessage,
67+
summarize: result.summarize,
68+
documentationLinks: result.documentationLinks,
69+
};
70+
}
5871
if (!result.valid) {
5972
message = _buildFinalMessage('Yaml not valid', result.details);
6073
}
61-
if (!_.isEmpty(result.warningDetails)) {
62-
warning = _buildFinalMessage('Yaml has warnings', result.warningDetails);
63-
}
64-
return { valid: !!result.valid, message, warning };
74+
return { valid: !!result.valid, message };
6575
}
6676

6777
async function checkOrProjectExists(projectName) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class PipelineValidationError extends Error {
2+
constructor(message) {
3+
super();
4+
this.message = message;
5+
}
6+
7+
toString() {
8+
return this.message;
9+
}
10+
}
11+
12+
module.exports = PipelineValidationError;

lib/logic/cli-config/errors/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ const NoPropertyError = require('./NoPropertyError');
22
const MultiplePropertiesError = require('./MultiplePropertiesError');
33
const NotFullPropertyError = require('./NotFullPropertyError');
44
const SchemaValidationError = require('./SchemaValidationError');
5+
const PipelineValidationError = require('./PipelineValidationError');
56

67
module.exports = {
78
NoPropertyError,
89
MultiplePropertiesError,
910
NotFullPropertyError,
1011
SchemaValidationError,
12+
PipelineValidationError,
1113
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.43.5",
3+
"version": "0.43.6",
44

55
"description": "Codefresh command line utility",
66
"main": "index.js",

0 commit comments

Comments
 (0)