Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
feat: no comment if badgeDescription not set
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizencc authored and kellertk committed Sep 27, 2022
1 parent 860dd89 commit ae6e505
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
1 change: 0 additions & 1 deletion .github/workflows/tester.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
badges: '[1 :trophy:,top 3 :fire:,top 5 :sunglasses:]'
thresholds: '[1,2,3]'
badge-descriptions: '[You''re top 2 and you''re not number 2!,You are on the podium!,You have broken into the top 5!]'
badge-type: 'leaderboard'
2 changes: 1 addition & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const project = new GitHubActionTypeScriptProject({
},
'badge-descriptions': {
description: 'badge descriptions corresponding 1-1 with badges',
required: true,
required: false,
},
'thresholds': {
description: 'thresholds corresponding 1-1 with badges',
Expand Down
2 changes: 1 addition & 1 deletion action.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/badger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ export interface BadgerProps {
readonly days?: number;
readonly token: string;
readonly badges: string[];
readonly badgeDescriptions: string[];
readonly badgeDescriptions?: string[];
readonly thresholds: number[];
readonly ignoreUsernames: string[];
}

interface BadgeInfo {
readonly name: string;
readonly description: string;
readonly description?: string;
readonly threshold: number;
}

Expand All @@ -24,6 +24,7 @@ export abstract class Badger {
private pullRequestNumber: number;
private timestampDate?: Date;
private ignoreUsernames?: string[];
private doWriteComment: boolean;
public badges: BadgeInfo[] = [];

constructor(props: BadgerProps) {
Expand All @@ -39,11 +40,12 @@ export abstract class Badger {

this.timestampDate = props.days ? daysToDate(props.days) : undefined;
this.ignoreUsernames = props.ignoreUsernames;
this.doWriteComment = props.badgeDescriptions ? true : false;

for (let i = 0; i < props.badges.length; i++) {
this.badges.push({
name: props.badges[i],
description: props.badgeDescriptions[i],
description: props.badgeDescriptions ? props.badgeDescriptions[i] : undefined,
threshold: props.thresholds[i],
});
}
Expand Down Expand Up @@ -131,6 +133,8 @@ export abstract class Badger {
}

protected async writeComment(badgeIndex: number, username: string, additionalInfo?: string) {
if (!this.doWriteComment) { return; }

const badge = this.badges[badgeIndex];
const comment = [
`${BADGER_METADATA}\n`,
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function run() {
return;
}

if (badgeDescriptions.length !== badges.length || badges.length !== thresholds.length) {
if (badges.length !== thresholds.length || (badgeDescriptions.length > 0 && badgeDescriptions.length !== badges.length)) {
core.setFailed('badge, badgeDescriptions, and thresholds must be lists with the same number of elements');
return;
}
Expand All @@ -31,7 +31,7 @@ async function run() {
token,
badges,
thresholds,
badgeDescriptions,
badgeDescriptions: badgeDescriptions.length === 0 ? undefined : badgeDescriptions,
ignoreUsernames,
days,
});
Expand All @@ -40,7 +40,7 @@ async function run() {
token,
badges,
thresholds,
badgeDescriptions,
badgeDescriptions: badgeDescriptions.length === 0 ? undefined : badgeDescriptions,
ignoreUsernames,
days,
});
Expand Down

0 comments on commit ae6e505

Please sign in to comment.