Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add silent mode #157

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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