From 3de08ec596a6572eac3ee72adfcc5ced498ba456 Mon Sep 17 00:00:00 2001 From: Mattias Kindborg Date: Wed, 11 Oct 2023 09:58:00 +0200 Subject: [PATCH 1/3] wip --- .vscode/settings.json | 5 ++++ scripts/most-helpful-contributors.ts | 20 ++++++++++--- scripts/src/list-member-logins.ts | 44 ++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 scripts/src/list-member-logins.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 1775865..e9605ae 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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" } diff --git a/scripts/most-helpful-contributors.ts b/scripts/most-helpful-contributors.ts index bac2c52..7f9ecc8 100644 --- a/scripts/most-helpful-contributors.ts +++ b/scripts/most-helpful-contributors.ts @@ -1,4 +1,6 @@ +import { log } from "console" 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" @@ -69,6 +71,7 @@ const filterAnswers = (comments: Comment[]): AuthorCount[] => { } } + console.log() return authorCounts } @@ -90,7 +93,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) => { return [ "# Let's celebrate our contributors!", "", @@ -104,7 +107,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", @@ -115,7 +121,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} |` }), "", "---", @@ -138,7 +146,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) } diff --git a/scripts/src/list-member-logins.ts b/scripts/src/list-member-logins.ts new file mode 100644 index 0000000..73853b2 --- /dev/null +++ b/scripts/src/list-member-logins.ts @@ -0,0 +1,44 @@ +import { Octokit } from "octokit" +import { PageInfo, processPagedQuery } from "./paging" + +export const listMemberLogins = async (organizationName: string, personalAccessToken: string): Promise> => { + const octokit = new Octokit({ + auth: personalAccessToken, + }) + + const query = createQuery(organizationName) + const members = await processPagedQuery(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 + } + } +} From 7e20abc0c1825732e5f5f5cef9f3569b573f148f Mon Sep 17 00:00:00 2001 From: Mattias Kindborg Date: Wed, 11 Oct 2023 10:06:31 +0200 Subject: [PATCH 2/3] wip --- scripts/src/list-comments.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/src/list-comments.ts b/scripts/src/list-comments.ts index 96fee4f..f72c158 100644 --- a/scripts/src/list-comments.ts +++ b/scripts/src/list-comments.ts @@ -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, From 7466c717d8d49875fa9486bf1ee6aefcdd2e966f Mon Sep 17 00:00:00 2001 From: Mattias Kindborg Date: Wed, 11 Oct 2023 10:06:55 +0200 Subject: [PATCH 3/3] wip --- scripts/most-helpful-contributors.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/most-helpful-contributors.ts b/scripts/most-helpful-contributors.ts index 7f9ecc8..85743db 100644 --- a/scripts/most-helpful-contributors.ts +++ b/scripts/most-helpful-contributors.ts @@ -1,4 +1,3 @@ -import { log } from "console" import { Author, Comment, Reply, listComments } from "./src/list-comments" import { listMemberLogins } from "./src/list-member-logins" import { updateDiscussion } from "./src/update-discussion"