Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark organization members in top contributors #391

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"editor.formatOnSave": true,
"editor.formatOnPaste": true
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnPaste": true
},
"markdown.extension.list.indentationSize": "inherit",
"markdown.extension.toc.levels": "1..3"
}
19 changes: 15 additions & 4 deletions scripts/most-helpful-contributors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Author, Comment, Reply, listComments } from "./src/list-comments"
import { listMemberLogins } from "./src/list-member-logins"
import { updateDiscussion } from "./src/update-discussion"

export const ORGANIZATION_NAME = "AxisCommunications"
Expand Down Expand Up @@ -69,6 +70,7 @@ const filterAnswers = (comments: Comment[]): AuthorCount[] => {
}
}

console.log()
return authorCounts
}

Expand All @@ -90,7 +92,7 @@ const byCount = (a: AuthorCount, b: AuthorCount) => {
return b.count - a.count || a.author.login.localeCompare(b.author.login)
}

const createBody = (answers: AuthorCount[], interactions: AuthorCount[]) => {
const createBody = (answers: AuthorCount[], interactions: AuthorCount[], memberLogins: Set<string>) => {
return [
"# Let's celebrate our contributors!",
"",
Expand All @@ -104,7 +106,10 @@ const createBody = (answers: AuthorCount[], interactions: AuthorCount[]) => {
"| :------: | ----------- | :--------------------: |",
...interactions.map((interaction, i) => {
const { author, count } = interaction
return `| ${i + 1} | [${author.login}](https://github.com${author.resourcePath}) | ${count} |`

return memberLogins.has(author.login)
? `| ${i + 1} | [${author.login}](https://github.com${author.resourcePath}) (member) | ${count} |`
: `| ${i + 1} | [${author.login}](https://github.com${author.resourcePath}) | ${count} |`
}),
"",
"## Most helpful with providing answers",
Expand All @@ -115,7 +120,9 @@ const createBody = (answers: AuthorCount[], interactions: AuthorCount[]) => {
"| :------: | ----------- | :---------------: |",
...answers.map((answer, i) => {
const { author, count } = answer
return `| ${i + 1} | [${author.login}](https://github.com${author.resourcePath}) | ${count} |`
return memberLogins.has(author.login)
? `| ${i + 1} | [${author.login}](https://github.com${author.resourcePath}) (member) | ${count} |`
: `| ${i + 1} | [${author.login}](https://github.com${author.resourcePath}) | ${count} |`
}),
"",
"---",
Expand All @@ -138,7 +145,11 @@ const main = async () => {
const answers = filterAnswers(comments).sort(byCount).splice(0, 20)
const interactions = filterInteractions(comments).sort(byCount).splice(0, 20)

const body = createBody(answers, interactions)
const memberLogins = await listMemberLogins(ORGANIZATION_NAME, personalAccessToken)

const body = createBody(answers, interactions, memberLogins)
console.log(body)

await updateDiscussion(discussionId, body, personalAccessToken)
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/src/list-comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const listComments = async (organizationName: string, repositoryName: str
const comments: Comment[] = []

for (const d of discussions) {
for (const { discussion, isAnswer, author, replies} of d.comments.nodes) {
for (const { discussion, isAnswer, author, replies } of d.comments.nodes) {
comments.push({
discussion,
isAnswer,
Expand Down
44 changes: 44 additions & 0 deletions scripts/src/list-member-logins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Octokit } from "octokit"
import { PageInfo, processPagedQuery } from "./paging"

export const listMemberLogins = async (organizationName: string, personalAccessToken: string): Promise<Set<string>> => {
const octokit = new Octokit({
auth: personalAccessToken,
})

const query = createQuery(organizationName)
const members = await processPagedQuery<Response, Member>(octokit, query, (res) => res.organization.membersWithRole)
const logins = members.map((m) => m.login)

return new Set(logins)
}

interface Member {
login: string
}

const createQuery = (organizationName: string): string => {
return `
query($cursor: String) {
organization(login: "${organizationName}") {
membersWithRole(first: 100, after: $cursor) {
nodes {
login
}
pageInfo {
hasNextPage
endCursor
}
}
}
}`
}

interface Response {
organization: {
membersWithRole: {
nodes: Member[]
pageInfo: PageInfo
}
}
}