Skip to content

Commit

Permalink
Add silent mode (#157)
Browse files Browse the repository at this point in the history
Co-authored-by: pdujtipiya <[email protected]>
  • Loading branch information
encX and pdujtipiya authored Nov 7, 2023
1 parent 0057082 commit 7a47c72
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Config/@types/configArgument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export type ConfigArgument = {
failOnWarnings: boolean;
suppressRules: string[];
dryRun: boolean;
silent: boolean;
};
5 changes: 5 additions & 0 deletions src/Config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ and <cwd> is build root directory (optional (Will use current context as cwd)).
type: 'boolean',
default: false,
})
.option('silent', {
describe: 'Disable the comment but still report job status to the VCS',
type: 'boolean',
default: false,
})
.check((options) => {
if (options.dryRun) return true;
if (typeof options.vcs === 'undefined') throw 'VCS type is required';
Expand Down
1 change: 1 addition & 0 deletions src/Provider/@interfaces/VCSEngineConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface VCSEngineConfig {
removeOldComment: boolean;
failOnWarnings: boolean;
silent: boolean;
}
11 changes: 11 additions & 0 deletions src/Provider/CommonVCS/VCSEngine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Comment } from '../../AnalyzerBot/@types/CommentTypes';
const config: VCSEngineConfig = {
removeOldComment: false,
failOnWarnings: false,
silent: false,
};

function createMockAdapter(): VCSAdapter {
Expand Down Expand Up @@ -124,5 +125,15 @@ describe('VCSEngine', () => {
await vcs.report([]);
expect(adapter.wrapUp).toBeCalledWith(analyzer);
});

it('should not call adapter to add comments when silent mode is on', async () => {
const { adapter, analyzer, vcs } = setup({ ...config, silent: true });
analyzer.shouldGenerateOverview = jest.fn().mockReturnValue(true);
analyzer.comments = [comment1, comment2];

await vcs.report([]);
expect(adapter.createReviewComment).not.toBeCalled();
expect(adapter.createComment).not.toBeCalled();
});
});
});
14 changes: 9 additions & 5 deletions src/Provider/CommonVCS/VCSEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ export class VCSEngine implements VCS {
await this.adapter.removeExistingComments();
}

await Promise.all(
this.analyzerBot.comments.map((c) => this.createReviewComment(c)),
);
await this.createSummaryComment();
if (!this.config.silent) {
await Promise.all(
this.analyzerBot.comments.map((c) => this.createReviewComment(c)),
);
await this.createSummaryComment();

Log.info('Report commit status completed');
Log.info('Report commit status completed');
} else {
Log.info('Silent mode is on. No inline comment nor summary will be produced.');
}
} catch (err) {
Log.error(`${this.adapter.getName()} report failed`, err);
throw err;
Expand Down

0 comments on commit 7a47c72

Please sign in to comment.