Skip to content

Commit

Permalink
Add: Cosmetic commit badge (#60)
Browse files Browse the repository at this point in the history
* Cosmetic commit badge

* Add style: or lint: to cosmetic commit badge
  • Loading branch information
andrewjswan committed Mar 25, 2024
1 parent 813a2b1 commit ebb0866
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions src/all-badges/cosmetic-commit/cosmetic-commit.ts
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()
)
}
1 change: 1 addition & 0 deletions src/all-badges/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export const allBadges = [
await import('./polite-coder/polite-coder.js'),
await import('./emoji-only-commit/emoji-only-commit.js'),
await import('./spooky-commit/spooky-commit.js'),
await import('./cosmetic-commit/cosmetic-commit.js'),
] as const

0 comments on commit ebb0866

Please sign in to comment.