-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Cosmetic commit badge * Add style: or lint: to cosmetic commit badge
- Loading branch information
1 parent
813a2b1
commit ebb0866
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { BadgePresenter, Present } from '../../badges.js' | ||
import { Commit } from '../../collect/types.js' | ||
|
||
export default new (class implements BadgePresenter { | ||
url = new URL(import.meta.url) | ||
badges = ['cosmetic-commit'] as const | ||
present: Present = (data, grant) => { | ||
const commits: Commit[] = [] | ||
|
||
for (const repo of data.repos) { | ||
for (const commit of repo.commits) { | ||
if ( | ||
/cosmetic/i.test(commit.message) || | ||
/^(style|lint)\b/.test(commit.message) | ||
) { | ||
commits.push(commit) | ||
} | ||
} | ||
} | ||
|
||
if (commits.length > 0) { | ||
grant('cosmetic-commit', 'I made cosmetic commit.').evidenceCommits( | ||
...commits.sort(latest).slice(0, 6), | ||
) | ||
} | ||
} | ||
})() | ||
|
||
function latest(a: Commit, b: Commit) { | ||
return ( | ||
new Date(b.committedDate).getTime() - new Date(a.committedDate).getTime() | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters