Commit 29785aa

Azecko <30987143+Azecko@users.noreply.github.com>
2024-07-05 22:10:08
Add cafe badge (#65)
1 parent c0c67de
Changed files (3)
src/all-badges/cafe-commit/cafe-commit.png
Binary file
src/all-badges/cafe-commit/cafe-commit.ts
@@ -0,0 +1,32 @@
+import { BadgePresenter, Present } from '../../badges.js'
+import { Commit, Repo } from '../../collect/types.js'
+
+export default new (class implements BadgePresenter {
+  url = new URL(import.meta.url)
+  badges = ['cafe-commit'] as const
+  present: Present = (data, grant) => {
+    const commits: { repo: Repo; commit: Commit }[] = []
+
+    for (const repo of data.repos) {
+      for (const commit of repo.commits) {
+        if (commit.sha.includes('cafe')) {
+          commits.push({ repo, commit })
+        }
+      }
+    }
+
+    const text = commits
+      .map(({ repo, commit }) => {
+        const sha = commit.sha.replace(/cafe/, '<strong>cafe</strong>')
+        return `- <a href="https://github.com/${repo.owner.login}/${repo.name}/commit/${commit.sha}">${sha}</a>`
+      })
+      .join('\n')
+
+    if (commits.length >= 1) {
+      grant(
+        'cafe-commit',
+        `I pushed a commit with "cafe" ${commits.length} times.`,
+      ).evidence(text)
+    }
+  }
+})()
src/all-badges/index.ts
@@ -24,4 +24,5 @@ export const allBadges = [
   await import('./emoji-only-commit/emoji-only-commit.js'),
   await import('./spooky-commit/spooky-commit.js'),
   await import('./cosmetic-commit/cosmetic-commit.js'),
+  await import('./cafe-commit/cafe-commit.js')
 ] as const