Skip to content

Commit 1a58bcb

Browse files
jcabrerizoiuliana
authored andcommitted
add skip hooks parameter
1 parent 8b47346 commit 1a58bcb

File tree

6 files changed

+35
-25
lines changed

6 files changed

+35
-25
lines changed

src/commands/create-issue.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import fs from "node:fs";
33
import CreateIssueOpt from "../commandOpts/create-issue.js";
44
import {SleekCommand} from "../sleek-command.js";
55
import CreateIssueService from "../services/create-issue.js";
6-
import {IssueData} from "../types/issue.js";
6+
import {ChartAutoCorrection, IssueData} from "../types/issue.js";
77
import SchemaValidationService from "../services/schemaValidation.js";
88
import ChartValidatorService from "../services/validate.js";
99
import {execSync} from "child_process";
10+
import {ValidateOptions} from "../types/validate.js";
1011

1112

1213
export class CreateIssue extends SleekCommand {
@@ -36,7 +37,10 @@ export class CreateIssue extends SleekCommand {
3637
const chartTag = addonData.helmChartUrl.lastIndexOf(':') ? `${addonData.helmChartUrl.substring(addonData.helmChartUrl.lastIndexOf(':')+1)}` : ''
3738
const charPath=await this.pullHelmChart(addonData.name, chartTag, repo)
3839
const validatorService = new ChartValidatorService(this, charPath);
39-
const validatorServiceResp = await validatorService.validate();
40+
const validateOps: ValidateOptions ={
41+
skipHooksValidation: inputDataParsed.chartAutoCorrection.includes(ChartAutoCorrection.hooks)
42+
}
43+
const validatorServiceResp = await validatorService.validate(validateOps);
4044
// todo: if validatorService exits when errors, not need to handle here !success
4145
if(!validatorServiceResp.success){
4246
this.error(validatorServiceResp.error?.input!, validatorServiceResp.error?.options )

src/commands/validate.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default class Validate extends SleekCommand {
4747
protocol: Flags.string({description: "Protocol of the helm hosting to use", exclusive: ['file', 'helmUrl'], char:'p'}),
4848
version: Flags.string({description: "Version of the addon to validate", exclusive: ['file'], char:'v'}),
4949
addonName: Flags.string({description: "Name of the addon"}),
50+
skipHooks: Flags.boolean({description: "Skip helm hooks validation", default:false}),
5051
extended: Flags.boolean({description: "Run extended validation", hidden: true, char:'e'}), // triggers security and extended checks. NEEDS THE CONTAINER IMAGE FOR THE ADDON
5152
}
5253

@@ -67,6 +68,7 @@ export default class Validate extends SleekCommand {
6768
if (flags.addonName) {
6869
addonName = flags.addonName;
6970
}
71+
const skipHooksValidation = flags.skipHooks;
7072
if (args.helmUrl || flags.helmUrl) {
7173
// JD decompose url, pull and validate
7274
const repoUrlInput = args.helmUrl || flags.helmUrl;
@@ -103,7 +105,7 @@ export default class Validate extends SleekCommand {
103105
const chartPath = await helmManager.pullAndUnzipChart(repoUrl!, repoProtocol!, versionTag!, addonName);
104106

105107
const validatorService = new ChartValidatorService(this, chartPath);
106-
const validatorServiceResp = await validatorService.validate();
108+
const validatorServiceResp = await validatorService.validate({ skipHooksValidation });
107109

108110
this.log(validatorServiceResp.body);
109111

src/services/validate.ts

+18-22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import {spawnSync} from "child_process";
77
import {BaseService} from "./base-service.js";
88
import {ServiceResponse} from "../types/service.js";
99
import {SleekCommand} from "../sleek-command.js";
10+
import {ValidateOptions} from "../types/validate.js";
11+
12+
export const SuccessResponse:ServiceResponse<string> = {
13+
success: true,
14+
};
15+
16+
export const ValidationSkipped:ServiceResponse<string> = {
17+
success: true,
18+
body:'validation skipped'
19+
};
1020

1121
export default class ChartValidatorService extends BaseService {
1222
// this will always be a local filepath
@@ -21,9 +31,9 @@ export default class ChartValidatorService extends BaseService {
2131

2232
}
2333

24-
public async validate(): Promise<ServiceResponse<any>> {
34+
public async validate(ops: ValidateOptions): Promise<ServiceResponse<any>> {
2535
const capabilities = await this.findCapabilities();
26-
const hooks = await this.findHooks();
36+
const hooks = ops.skipHooksValidation ? ValidationSkipped : await this.findHooks();
2737
const dependencies = await this.findDependencies();
2838

2939
let response: ServiceResponse<string> = {
@@ -82,14 +92,10 @@ export default class ChartValidatorService extends BaseService {
8292
encoding: "utf-8"
8393
});
8494

85-
let response: ServiceResponse<string>;
86-
8795
if (capabilities.stdout === "") {
88-
response = {
89-
success: true,
90-
}
96+
return SuccessResponse
9197
} else {
92-
response = {
98+
return {
9399
success: false,
94100
body: "Unsupported system Capabilities are used in chart.",
95101
error: {
@@ -101,20 +107,16 @@ export default class ChartValidatorService extends BaseService {
101107
}
102108
}
103109
}
104-
105-
return response;
106110
}
107111

108112
private async findHooks(): Promise<ServiceResponse<string>> {
109113
const hooks = spawnSync('grep', ['-Rile', '".Hooks"', this.toValidate], {shell: true, encoding: "utf-8"});
110114

111115
let response: ServiceResponse<string>;
112116
if (hooks.stdout === "") {
113-
response = {
114-
success: true,
115-
}
117+
return SuccessResponse
116118
} else {
117-
response = {
119+
return {
118120
success: false,
119121
body: "Unsupported system Hooks are used in chart.",
120122
error: {
@@ -126,8 +128,6 @@ export default class ChartValidatorService extends BaseService {
126128
}
127129
}
128130
}
129-
130-
return response;
131131
}
132132

133133
private async findDependencies(): Promise<ServiceResponse<string>> {
@@ -150,11 +150,9 @@ export default class ChartValidatorService extends BaseService {
150150
const allDepsFiles = dependencies.every(dep => dep.includes('file://'));
151151

152152
if (allDepsFiles) {
153-
response = {
154-
success: true,
155-
}
153+
return SuccessResponse
156154
} else {
157-
response = {
155+
return {
158156
success: false,
159157
body: "Not all dependencies reside in the main chart.",
160158
error: {
@@ -166,7 +164,5 @@ export default class ChartValidatorService extends BaseService {
166164
}
167165
}
168166
}
169-
170-
return response;
171167
}
172168
}

src/types/issue.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ export type AddonData = {
55
helmChartUrlProtocol: string,
66
containerImagesUrls: string[],
77
};
8+
export enum ChartAutoCorrection {
9+
hooks = 'hooks',
10+
releaseService = 'releaseService',
11+
}
812

913
export type IssueData = {
1014
addon: AddonData;
1115
sellerMarketPlaceAlias: string,
16+
chartAutoCorrection: ChartAutoCorrection[]
1217
};

src/types/validate.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type ValidateOptions = {
2+
skipHooksValidation:boolean
3+
}

0 commit comments

Comments
 (0)