Commit 2d74c06
Changed files (7)
badges
most-reactions
src
badges/most-reactions/most-reactions.ts
@@ -0,0 +1,58 @@
+import { define, plural } from '#src'
+
+export default define({
+ url: import.meta.url,
+ badges: ['most-reactions'] as const,
+ present(data, grant) {
+ const reactions: Record<string, { count: number; repository: string }> = {}
+
+ for (const issue of data.issues) {
+ if (issue.reactions.totalCount > 0) {
+ reactions[issue.url] = {
+ count: issue.reactions.totalCount,
+ repository: issue.repository.nameWithOwner,
+ }
+ }
+ }
+
+ for (const pull of data.pulls) {
+ if (pull.reactions.totalCount > 0) {
+ reactions[pull.url] = {
+ count: pull.reactions.totalCount,
+ repository: pull.repository.nameWithOwner,
+ }
+ }
+ }
+
+ for (const comment of data.issueComments) {
+ if (comment.reactions.totalCount > 0) {
+ reactions[comment.repository.nameWithOwner] = {
+ count: comment.reactions.totalCount,
+ repository: comment.repository.nameWithOwner,
+ }
+ }
+ }
+
+ for (const discussion of data.discussionComments) {
+ if (discussion.reactions.totalCount > 0) {
+ reactions[discussion.discussion.repository.nameWithOwner] = {
+ count: discussion.reactions.totalCount,
+ repository: discussion.discussion.repository.nameWithOwner,
+ }
+ }
+ }
+
+ const pairs = Object.entries(reactions)
+ pairs.sort((a, b) => b[1].count - a[1].count)
+ if (pairs.length === 0) return
+
+ const topReactions = pairs.slice(0, 10)
+ // grant(
+ // 'most-reactions',
+ // `I have received the most reactions on issues!\n\n` +
+ // topReactions
+ // .map((p) => `- ${p[1].repository}: ${p[1].count} reactions`)
+ // .join('\n'),
+ // )
+ },
+})
badges/index.ts
@@ -13,6 +13,7 @@ export default [
await import('./fix-commit/fix-commit.js'),
await import('./github-anniversary/github-anniversary.js'),
await import('./mass-delete-commit/mass-delete-commit.js'),
+ await import('./most-reactions/most-reactions.js'),
await import('./my-badges-contributor/my-badges-contributor.js'),
await import('./old-issue/old-issue.js'),
await import('./polite-coder/polite-coder.js'),
src/collect/discussion-comments.ts
@@ -1,9 +1,12 @@
+import { Reactions } from './types.js'
+
export const discussionCommentsQuery = `#graphql
query DiscussionCommentsQuery($login: String!, $num: Int = 100, $cursor: String) {
user(login: $login) {
repositoryDiscussionComments(first: $num, after: $cursor) {
totalCount
nodes {
+ url
author {
login
}
@@ -52,6 +55,7 @@ export type DiscussionCommentsQuery = {
repositoryDiscussionComments: {
totalCount: number
nodes: Array<{
+ url: string
author: {
login: string
}
@@ -70,23 +74,7 @@ export type DiscussionCommentsQuery = {
editor: {
login: string
} | null
- reactions: {
- totalCount: number
- nodes: Array<{
- content:
- | 'CONFUSED'
- | 'EYES'
- | 'HEART'
- | 'HOORAY'
- | 'LAUGH'
- | 'ROCKET'
- | 'THUMBS_DOWN'
- | 'THUMBS_UP'
- user: {
- login: string
- }
- }>
- }
+ reactions: Reactions
}>
pageInfo: {
hasNextPage: boolean
src/collect/issue-comments.ts
@@ -1,9 +1,12 @@
+import { Reactions } from './types.js'
+
export const issueCommentsQuery = `#graphql
query IssueCommentsQuery($login: String!, $num: Int = 100, $cursor: String) {
user(login: $login) {
issueComments(first: $num, after: $cursor) {
totalCount
nodes {
+ url
author {
login
}
@@ -52,6 +55,7 @@ export type IssueCommentsQuery = {
issueComments: {
totalCount: number
nodes: Array<{
+ url: string
author: {
login: string
}
@@ -70,23 +74,7 @@ export type IssueCommentsQuery = {
editor: {
login: string
} | null
- reactions: {
- totalCount: number
- nodes: Array<{
- content:
- | 'CONFUSED'
- | 'EYES'
- | 'HEART'
- | 'HOORAY'
- | 'LAUGH'
- | 'ROCKET'
- | 'THUMBS_DOWN'
- | 'THUMBS_UP'
- user: {
- login: string
- }
- }>
- }
+ reactions: Reactions
}>
pageInfo: {
hasNextPage: boolean
src/collect/issues.ts
@@ -1,4 +1,4 @@
-import { Extra } from './types.js'
+import { Extra, Reactions } from './types.js'
export const issuesQuery = `#graphql
query IssuesQuery($username: String!, $num: Int = 100, $cursor: String) {
@@ -12,6 +12,7 @@ query IssuesQuery($username: String!, $num: Int = 100, $cursor: String) {
author {
login
}
+ url
number
title
labels(first: 10) {
@@ -24,13 +25,20 @@ query IssuesQuery($username: String!, $num: Int = 100, $cursor: String) {
comments(first: 1) {
totalCount
}
- reactions(first: 10) {
+ reactions(first: 100) {
totalCount
+ nodes {
+ content
+ user {
+ login
+ }
+ }
}
assignees(first: 3) {
totalCount
}
repository {
+ nameWithOwner
owner {
login
}
@@ -64,6 +72,7 @@ export type IssuesQuery = {
author: {
login: string
}
+ url: string
number: number
title: string
labels: {
@@ -76,13 +85,12 @@ export type IssuesQuery = {
comments: {
totalCount: number
}
- reactions: {
- totalCount: number
- }
+ reactions: Reactions
assignees: {
totalCount: number
}
repository: {
+ nameWithOwner: string
owner: {
login: string
}
src/collect/pulls.ts
@@ -1,3 +1,5 @@
+import { Reactions } from './types.js'
+
export const pullsQuery = `#graphql
query PullsQuery($username: String!, $num: Int = 100, $cursor: String) {
user(login: $username) {
@@ -5,6 +7,7 @@ query PullsQuery($username: String!, $num: Int = 100, $cursor: String) {
totalCount
nodes {
createdAt
+ url
number
title
body
@@ -15,6 +18,7 @@ query PullsQuery($username: String!, $num: Int = 100, $cursor: String) {
login
}
repository {
+ nameWithOwner
owner {
login
}
@@ -61,6 +65,15 @@ query PullsQuery($username: String!, $num: Int = 100, $cursor: String) {
}
}
}
+ reactions(first: 100) {
+ totalCount
+ nodes {
+ content
+ user {
+ login
+ }
+ }
+ }
}
pageInfo {
hasNextPage
@@ -83,6 +96,7 @@ export type PullsQuery = {
totalCount: number
nodes: Array<{
createdAt: string
+ url: string
number: number
title: string
body: string
@@ -93,6 +107,7 @@ export type PullsQuery = {
login: string
}
repository: {
+ nameWithOwner: string
owner: {
login: string
}
@@ -154,6 +169,7 @@ export type PullsQuery = {
}
}>
}
+ reactions: Reactions
}>
}
pageInfo: {
src/collect/types.ts
@@ -42,3 +42,21 @@ export type DiscussionComment =
DiscussionCommentsQuery['user']['repositoryDiscussionComments']['nodes'][0]
export type StarredRepo = StarsQuery['user']['starredRepositories']['nodes'][0]
+
+export type Reactions = {
+ totalCount: number
+ nodes: Array<{
+ content:
+ | 'CONFUSED'
+ | 'EYES'
+ | 'HEART'
+ | 'HOORAY'
+ | 'LAUGH'
+ | 'ROCKET'
+ | 'THUMBS_DOWN'
+ | 'THUMBS_UP'
+ user: {
+ login: string
+ }
+ }>
+}