Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyskoedijk committed Dec 3, 2024
1 parent fbcba56 commit bc17f83
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions extension/tasks/dependabotV2/utils/dependabot-cli/DependabotCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class DependabotCli {
this.toolImage = cliToolImage;
this.outputProcessor = outputProcessor;
this.outputLogStream = new Writable();
this.outputLogStream._write = this.logOutput;
this.outputLogStream._write = (chunk, encoding, callback) => logComponentOutput(debug, chunk, encoding, callback);
this.debug = debug;
this.ensureJobsPathExists();
}
Expand Down Expand Up @@ -200,31 +200,6 @@ export class DependabotCli {
}
}

// Log output from Dependabot based on the sub-component it originates from
private logOutput(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
chunk
.toString()
.split('\n')
.map((line: string) => line.trim())
.filter((line: string) => line)
.forEach((line: string) => {
const component = line.split('|')?.[0]?.trim();
switch (component) {
// Don't log highly verbose components that are not useful to the user unless debugging
case 'collector':
case 'proxy':
debug(line);
break;

// Log output from all other components
default:
console.log(line);
break;
}
});
callback();
}

// Clean up the jobs directory and its contents
public cleanup(): void {
if (fs.existsSync(this.jobsPath)) {
Expand Down Expand Up @@ -263,3 +238,35 @@ function readJobScenarioOutputFile(path: string): any[] {

return scenario['output'] || [];
}

// Log output from Dependabot based on the sub-component it originates from
function logComponentOutput(
verbose: boolean,
chunk: any,
encoding: BufferEncoding,
callback: (error?: Error | null) => void,
): void {
chunk
.toString()
.split('\n')
.map((line: string) => line.trim())
.filter((line: string) => line)
.forEach((line: string) => {
const component = line.split('|')?.[0]?.trim();
switch (component) {
// Don't log highly verbose components that are not useful to the user, unless debugging
case 'collector':
case 'proxy':
if (verbose) {
debug(line);
}
break;

// Log output from all other components
default:
console.log(line);
break;
}
});
callback();
}

0 comments on commit bc17f83

Please sign in to comment.