Skip to content

Commit 7a47c72

Browse files
encXpdujtipiya
and
pdujtipiya
authored
Add silent mode (#157)
Co-authored-by: pdujtipiya <[email protected]>
1 parent 0057082 commit 7a47c72

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

src/Config/@types/configArgument.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export type ConfigArgument = {
1616
failOnWarnings: boolean;
1717
suppressRules: string[];
1818
dryRun: boolean;
19+
silent: boolean;
1920
};

src/Config/Config.ts

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ and <cwd> is build root directory (optional (Will use current context as cwd)).
121121
type: 'boolean',
122122
default: false,
123123
})
124+
.option('silent', {
125+
describe: 'Disable the comment but still report job status to the VCS',
126+
type: 'boolean',
127+
default: false,
128+
})
124129
.check((options) => {
125130
if (options.dryRun) return true;
126131
if (typeof options.vcs === 'undefined') throw 'VCS type is required';
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface VCSEngineConfig {
22
removeOldComment: boolean;
33
failOnWarnings: boolean;
4+
silent: boolean;
45
}

src/Provider/CommonVCS/VCSEngine.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Comment } from '../../AnalyzerBot/@types/CommentTypes';
88
const config: VCSEngineConfig = {
99
removeOldComment: false,
1010
failOnWarnings: false,
11+
silent: false,
1112
};
1213

1314
function createMockAdapter(): VCSAdapter {
@@ -124,5 +125,15 @@ describe('VCSEngine', () => {
124125
await vcs.report([]);
125126
expect(adapter.wrapUp).toBeCalledWith(analyzer);
126127
});
128+
129+
it('should not call adapter to add comments when silent mode is on', async () => {
130+
const { adapter, analyzer, vcs } = setup({ ...config, silent: true });
131+
analyzer.shouldGenerateOverview = jest.fn().mockReturnValue(true);
132+
analyzer.comments = [comment1, comment2];
133+
134+
await vcs.report([]);
135+
expect(adapter.createReviewComment).not.toBeCalled();
136+
expect(adapter.createComment).not.toBeCalled();
137+
});
127138
});
128139
});

src/Provider/CommonVCS/VCSEngine.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ export class VCSEngine implements VCS {
2222
await this.adapter.removeExistingComments();
2323
}
2424

25-
await Promise.all(
26-
this.analyzerBot.comments.map((c) => this.createReviewComment(c)),
27-
);
28-
await this.createSummaryComment();
25+
if (!this.config.silent) {
26+
await Promise.all(
27+
this.analyzerBot.comments.map((c) => this.createReviewComment(c)),
28+
);
29+
await this.createSummaryComment();
2930

30-
Log.info('Report commit status completed');
31+
Log.info('Report commit status completed');
32+
} else {
33+
Log.info('Silent mode is on. No inline comment nor summary will be produced.');
34+
}
3135
} catch (err) {
3236
Log.error(`${this.adapter.getName()} report failed`, err);
3337
throw err;

0 commit comments

Comments
 (0)