Skip to content

Commit

Permalink
feat: add title-prefixes property
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizencc committed Sep 14, 2022
1 parent 66e236c commit b21715d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 26 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/tester.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ jobs:
permissions:
pull-requests: write
steps:
# - uses: kaizencc/github-merit-badger@main
# id: badger
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# badges: '[first,second,third]'
# thresholds: '[0,1,2]'
# badge-descriptions: '[you are first!,you are second!,you are third!]'
# badge-type: 'achievement'
# ignore-usernames: '[Tianyi-W]'
- uses: kaizencc/github-merit-badger@main
id: contributor-badge-hotlist
id: badger
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
badges: '[1 :trophy:,top 3 :fire:,top 5 :sunglasses:]'
thresholds: '[1,2,3]'
badge-type: 'leaderboard'
badges: '[first,second,third]'
thresholds: '[0,1,2]'
prefixes: '[chore, feat]'
badge-type: 'achievement'
ignore-usernames: '[Tianyi-W]'
# - uses: kaizencc/github-merit-badger@main
# id: contributor-badge-hotlist
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# badges: '[1 :trophy:,top 3 :fire:,top 5 :sunglasses:]'
# thresholds: '[1,2,3]'
# badge-type: 'leaderboard'
4 changes: 4 additions & 0 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const project = new GitHubActionTypeScriptProject({
description: 'filter for pull requests merged in the last X number of days',
required: false,
},
'title-prefixes': {
description: 'filter for pull requests with titles that start with these prefixes',
required: false,
},
'ignore-usernames': {
description: 'ignore pull requests from these authors',
required: false,
Expand Down
3 changes: 3 additions & 0 deletions action.yml

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

23 changes: 16 additions & 7 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.

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

interface BadgeInfo {
Expand All @@ -25,6 +26,8 @@ export abstract class Badger {
private timestampDate?: Date;
private ignoreUsernames?: string[];
private doWriteComment: boolean;
private prefixes?: string[];

public badges: BadgeInfo[] = [];

constructor(props: BadgerProps) {
Expand All @@ -41,6 +44,7 @@ export abstract class Badger {
this.timestampDate = props.days ? daysToDate(props.days) : undefined;
this.ignoreUsernames = props.ignoreUsernames;
this.doWriteComment = props.badgeDescriptions ? true : false;
this.prefixes = props.prefixes;

for (let i = 0; i < props.badges.length; i++) {
this.badges.push({
Expand Down Expand Up @@ -113,11 +117,17 @@ export abstract class Badger {
return [];
}

console.log(JSON.stringify(issues));

return issues.filter((isMerged) => {
const mergedAt = isMerged.pull_request?.merged_at;
return issues.filter((issue) => {
// filter out issues that are not pull requests and not merged
const mergedAt = issue.pull_request?.merged_at;
if (!mergedAt) { return false; }

// filter out pull requests that do not start with the given list of prefixes
if (this.prefixes && !this.prefixes?.some((prefix) => issue.title.startsWith(prefix))) {
return false;
}

// filter out pull requests that are merged before a timestamp
if (!this.timestampDate) { return true; }
return this.timestampDate < new Date(mergedAt);
});
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ async function run() {
const badgeType: string = core.getInput('badge-type');
const ignoreUsernames: string[] = renderListInput(core.getInput('ignore-usernames'));
const days = Number(core.getInput('days'));
const prefixes = renderListInput(core.getInput('title-prefixes'));

console.log(badges, badgeDescriptions, thresholds, badgeType, ignoreUsernames, days);
console.log(badges, badgeDescriptions, thresholds, badgeType, ignoreUsernames, days, prefixes);

if (badges.length === 0) {
core.setFailed('must have at least one badge in the input');
Expand All @@ -34,6 +35,7 @@ async function run() {
badgeDescriptions: badgeDescriptions.length === 0 ? undefined : badgeDescriptions,
ignoreUsernames,
days,
prefixes,
});
} else {
badger = new AchievementBadger({
Expand All @@ -43,6 +45,7 @@ async function run() {
badgeDescriptions: badgeDescriptions.length === 0 ? undefined : badgeDescriptions,
ignoreUsernames,
days,
prefixes,
});
}

Expand Down

0 comments on commit b21715d

Please sign in to comment.