diff --git a/src/Config/@types/configArgument.ts b/src/Config/@types/configArgument.ts index 86e6bbf..2b3e450 100644 --- a/src/Config/@types/configArgument.ts +++ b/src/Config/@types/configArgument.ts @@ -16,4 +16,5 @@ export type ConfigArgument = { failOnWarnings: boolean; suppressRules: string[]; dryRun: boolean; + silent: boolean; }; diff --git a/src/Config/Config.ts b/src/Config/Config.ts index fc3e0a3..6fffec3 100644 --- a/src/Config/Config.ts +++ b/src/Config/Config.ts @@ -121,6 +121,11 @@ and 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'; diff --git a/src/Provider/@interfaces/VCSEngineConfig.ts b/src/Provider/@interfaces/VCSEngineConfig.ts index 2a2bd3d..b489339 100644 --- a/src/Provider/@interfaces/VCSEngineConfig.ts +++ b/src/Provider/@interfaces/VCSEngineConfig.ts @@ -1,4 +1,5 @@ export interface VCSEngineConfig { removeOldComment: boolean; failOnWarnings: boolean; + silent: boolean; } diff --git a/src/Provider/CommonVCS/VCSEngine.spec.ts b/src/Provider/CommonVCS/VCSEngine.spec.ts index b8fcf30..1290326 100644 --- a/src/Provider/CommonVCS/VCSEngine.spec.ts +++ b/src/Provider/CommonVCS/VCSEngine.spec.ts @@ -8,6 +8,7 @@ import { Comment } from '../../AnalyzerBot/@types/CommentTypes'; const config: VCSEngineConfig = { removeOldComment: false, failOnWarnings: false, + silent: false, }; function createMockAdapter(): VCSAdapter { @@ -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(); + }); }); }); diff --git a/src/Provider/CommonVCS/VCSEngine.ts b/src/Provider/CommonVCS/VCSEngine.ts index dac70c2..ecb6d70 100644 --- a/src/Provider/CommonVCS/VCSEngine.ts +++ b/src/Provider/CommonVCS/VCSEngine.ts @@ -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;