Skip to content

Commit

Permalink
adding rule id to a VCS message
Browse files Browse the repository at this point in the history
  • Loading branch information
mvedernikov committed Oct 18, 2023
1 parent ccb5cd6 commit 9f775d1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"homepage": "https://github.com/codeleague/codecoach",
"license": "MIT",
"scripts": {
"lint": "eslint 'src/**/*.{js,ts}' --quiet --fix",
"lint-ci": "eslint 'src/**/*.{js,ts}'",
"format": "prettier --write 'src/**/*.{js,ts}'",
"lint": "eslint \"src/**/*.{js,ts}\" --quiet --fix",
"lint-ci": "eslint \"src/**/*.{js,ts}\"",
"format": "prettier --write \"src/**/*.{js,ts}\"",
"test": "jest",
"build": "tsc --project tsconfig.build.json",
"dev": "nodemon --inspect=5858 --config ./nodemon.json -- --config=\"config-test.json\"",
Expand Down
2 changes: 2 additions & 0 deletions src/AnalyzerBot/utils/commentUtil.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe('groupComments', () => {
':rotating_light: msg1' +
' \n' +
':warning: (SUPPRESSED) additional warning' +
' \n(rule: UNIMPORTANT_RULE2)' +
' \n',
},
{
Expand Down Expand Up @@ -139,6 +140,7 @@ describe('groupComments', () => {
':rotating_light: msg1' +
' \n' +
':warning: (SUPPRESSED) additional warning' +
' \n(rule: UNIMPORTANT_RULE/RULE2)' +
' \n',
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/AnalyzerBot/utils/commentUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function buildText(
const { severity, msg } = item;
const { text: currentText } = currentComment;
const msgWithSuppression = isSuppressed ? `(SUPPRESSED) ${msg}` : msg;
const text = MessageUtil.createMessageWithEmoji(msgWithSuppression, severity);
const msgWithRuleId = MessageUtil.addRuleIdToMessage(msgWithSuppression, item.ruleId);
const text = MessageUtil.createMessageWithEmoji(msgWithRuleId, severity);
return `${currentText}${text} \n`;
}

Expand Down
17 changes: 17 additions & 0 deletions src/AnalyzerBot/utils/message.util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,20 @@ describe('generateCommitDescription', () => {
expect(MessageUtil.generateCommitDescription(99)).toBe('CodeCoach report 99 errors');
});
});

describe('addRuleIdToMessage', () => {
it('should add ruleId to message', () => {
const msg = 'test';
const ruleId = 'id';

expect(MessageUtil.addRuleIdToMessage(msg, ruleId)).toBe(
`${msg} \n(rule: ${ruleId})`,
);
});
it('should not add ruleId to message if ruleId is empty', () => {
const msg = 'test';
const ruleId = '';

expect(MessageUtil.addRuleIdToMessage(msg, ruleId)).toBe(msg);
});
});
4 changes: 4 additions & 0 deletions src/AnalyzerBot/utils/message.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ ${warningMsg}`;
? `CodeCoach report ${nOfErrors} errors`
: 'CodeCoach report no critical issue, good job!';
}

static addRuleIdToMessage(msg: string, ruleId: string): string {
return `${msg}` + (ruleId ? ` \n(rule: ${ruleId})` : '');
}
}

0 comments on commit 9f775d1

Please sign in to comment.