Commit 3dd848a

Andrew J.Swan <ajs.blackhole@gmail.com>
2024-03-22 19:44:12
Spooky Commit badge (Only Halloween for Now) (#59)
* Add spooky-commit * Add spooky-commit badge * Add spooky-commit to Index
1 parent ffff97c
Changed files (3)
src/all-badges/spooky-commit/spooky-commit.png
Binary file
src/all-badges/spooky-commit/spooky-commit.ts
@@ -0,0 +1,32 @@
+import { BadgePresenter, Present } from '../../badges.js'
+import { Commit } from '../../collect/collect.js'
+
+export default new (class implements BadgePresenter {
+  url = new URL(import.meta.url)
+  badges = ['spooky-commit'] as const
+  present: Present = (data, grant) => {
+    const commits: Commit[] = []
+
+    for (const repo of data.repos) {
+      for (const commit of repo.commits) {
+        const data = new Date(commit.committedDate)
+        if (data.getMonth() === 10 && data.getDate() === 31) {
+          commits.push(commit)
+        }
+      }
+    }
+
+    if (commits.length > 0) {
+      grant(
+        'spooky-commit',
+        'I committed on the Halloween! Boo!',
+      ).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
@@ -22,4 +22,5 @@ export const allBadges = [
   await import('./favorite-word/favorite-word.js'),
   await import('./polite-coder/polite-coder.js'),
   await import('./emoji-only-commit/emoji-only-commit.js'),
+  await import('./spooky-commit/spooky-commit.js'),
 ] as const