Commit 4647571
Changed files (7)
src
all-badges
fuck-commit
mass-delete-commit
revert-revert-commit
collect
src/all-badges/fuck-commit/fuck-commit.ts
@@ -5,21 +5,22 @@ import {linkCommit} from '../../utils.js'
export default new class implements BadgePresenter {
url = new URL(import.meta.url)
badges = [
- 'fuck-commit'
+ 'fuck-commit',
] as const
present: Present = (data, grant) => {
- const commits: { repo: Repo, commit: Commit }[] = []
+ const commits: Commit[] = []
for (const repo of data.repos) {
for (const commit of repo.commits) {
if (/fuck/i.test(commit.message + commit.messageBody)) {
- commits.push({repo, commit})
+ commits.push(commit)
}
}
}
+
if (commits.length > 0) {
grant('fuck-commit', 'I used a word "fuck" in my commit message.')
- .evidenceCommits(commits)
+ .evidenceCommits(...commits)
}
}
}
src/all-badges/mass-delete-commit/mass-delete-commit.ts
@@ -14,7 +14,7 @@ export default new class implements BadgePresenter {
(commit.deletions ?? 0) / (commit.additions ?? 0) > 100
) {
grant('mass-delete-commit', 'When I delete code, I delete a lot.')
- .evidenceCommits([{repo, commit}])
+ .evidenceCommits(commit)
}
if (
@@ -22,7 +22,7 @@ export default new class implements BadgePresenter {
(commit.deletions ?? 0) / (commit.additions ?? 0) > 100
) {
grant('mass-delete-commit-10k', 'When I delete code, I delete a lot.')
- .evidenceCommits([{repo, commit}])
+ .evidenceCommits(commit)
}
}
}
src/all-badges/revert-revert-commit/revert-revert-commit.ts
@@ -1,4 +1,4 @@
-import {Commit, Repo} from '../../collect/collect.js'
+import {Commit} from '../../collect/collect.js'
import {BadgePresenter, Present} from '../../badges.js'
export default new class implements BadgePresenter {
@@ -7,19 +7,19 @@ export default new class implements BadgePresenter {
'revert-revert-commit',
] as const
present: Present = (data, grant) => {
- const commits: { repo: Repo, commit: Commit }[] = []
+ const commits: Commit[] = []
for (const repo of data.repos) {
for (const commit of repo.commits) {
if (/Revert.+Revert/.test(commit.message)) {
- commits.push({repo, commit})
+ commits.push(commit)
}
}
}
if (commits.length > 0) {
grant('revert-revert-commit', 'I reverted a revert commit.')
- .evidenceCommits(commits)
+ .evidenceCommits(...commits)
}
}
}
src/collect/commits.graphql
@@ -17,6 +17,12 @@ query CommitsQuery(
messageBody
additions
deletions
+ repository {
+ owner {
+ login
+ }
+ name
+ }
}
pageInfo {
hasNextPage
src/collect/commits.ts
@@ -10,6 +10,12 @@ export type CommitsQuery = {
messageBody: string
additions: number
deletions: number
+ repository: {
+ owner: {
+ login: string
+ }
+ name: string
+ }
}>
pageInfo: {
hasNextPage: boolean
src/badges.ts
@@ -44,7 +44,7 @@ export function badgeCollection(badges: Badge[], baseUrl: URL) {
evidence(text: string) {
badge.body = text
},
- evidenceCommits(commits: { repo: Repo, commit: Commit }[]) {
+ evidenceCommits(...commits: Commit[]) {
this.evidence('Commits:\n\n' + commits.map(linkCommit).map(x => '- ' + x).join('\n'))
},
}
src/utils.ts
@@ -1,7 +1,7 @@
-import {Commit, Repo} from './collect/collect.js'
+import {Commit} from './collect/collect.js'
-export function linkCommit({repo, commit}: { repo: Repo, commit: Commit }): string {
- return `<a href="https://github.com/${repo.owner.login}/${repo.name}/commit/${commit.sha}">${commit.sha.slice(0, 7)}</a>`
+export function linkCommit(commit: Commit): string {
+ return `<a href="https://github.com/${commit.repository.owner.login}/${commit.repository.name}/commit/${commit.sha}">${commit.sha.slice(0, 7)}</a>`
}
export function quoteAttr(s: string) {