Commit ebb0866

Andrew J.Swan <ajs.blackhole@gmail.com>
2024-03-25 23:15:48
Add: Cosmetic commit badge (#60)
* Cosmetic commit badge * Add style: or lint: to cosmetic commit badge
1 parent 813a2b1
Changed files (3)
src/all-badges/cosmetic-commit/cosmetic-commit.png
Binary file
src/all-badges/cosmetic-commit/cosmetic-commit.ts
@@ -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()
+  )
+}
src/all-badges/index.ts
@@ -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