-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add script to build contributors.md #639
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Deny from all |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules | ||
| keys.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Contributors | ||
| Generate the /about/contributors.md file from contributors on Github and translators on crowdin. | ||
|
|
||
| ## Usage | ||
| ```sh | ||
| node . --crowdin-key <crowdin-key> --github-key <github-key> | ||
| ``` | ||
| Run `node . --help` for more |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * Keyman is copyright (C) SIL Global. MIT License. | ||
| * | ||
| * Created by pbdurdin on 2026-01-18 | ||
| * | ||
| * Generate contributors.md | ||
| */ | ||
| import { Command } from "commander"; | ||
| import * as fs from "node:fs"; | ||
| import { getGithub, genGithub } from "./github.mjs"; | ||
| import { getCrowdin, genCrowdin } from "./crowdin.mjs"; | ||
|
|
||
| // Parse CLI input | ||
| const program = new Command(); | ||
| program.name("node .") | ||
| .description("Script to generate https://keyman.com/about/contributors") | ||
| .version("0.1.0") | ||
| .option("-o, --output <filename>", "output file", "contributors.md") | ||
| .option("-g, --github-key <key>", "github api authentication key (https://github.com/settings/tokens)") | ||
| .option("-c, --crowdin-key <key>", "crowdin api authentication key (https://crowdin.com/setting#api-key)") | ||
| .action(main); | ||
| program.parse(process.argv); | ||
|
|
||
| async function main() { | ||
| // Header for the markdown file. Can include explanation, title, etc. | ||
| let headers = ` | ||
| --- | ||
| title: Keyman Contributors | ||
| --- | ||
| <div><style>@import './contributors.css';</style></div> | ||
| `; | ||
|
|
||
| let githubSeg = null; | ||
| // If the user provided a key for github | ||
| if (program.opts().githubKey) { | ||
| // Fetch a list users that have made contributions to "keymanapp" on github, transform it, then generate markdown. | ||
| let githubData = await getGithub(program.opts().githubKey); | ||
| let [gMajor, gMinor] = genGithub(githubData); | ||
| githubSeg = genMarkdownSegment("Contributors", gMajor, gMinor); | ||
| } | ||
|
|
||
| let crowdinSeg = null; | ||
| if (program.opts().crowdinKey) { | ||
| // Fetch a list users that have made contributions to "keyman" on crowdin, transform it, then generate markdown. | ||
| let crowdinData = await getCrowdin(program.opts().crowdinKey); | ||
| let [cMajor, cMinor] = genCrowdin(crowdinData); | ||
| crowdinSeg = genMarkdownSegment("Translators", cMajor, cMinor); | ||
| } | ||
|
|
||
| // To the users input file for output (default: contributors.md), write a join of the header, the github segment. | ||
| fs.writeFileSync(program.opts().output, `${headers}\n${githubSeg != null ? githubSeg : ""}\n${crowdinSeg != null ? crowdinSeg : ""}`); | ||
| } | ||
|
|
||
| function genMarkdownSegment(name, major, minor) { | ||
| // Initiate the markdown variable as a level 2 header of the section's name. | ||
| let markDown = `## ${name}\n`; | ||
|
|
||
| if (major.length > 0) { | ||
| // Add the Major contributors, one at a time | ||
| if (minor.length > 0) { | ||
| markDown += `### Major ${name}\n`; | ||
| } | ||
| major.forEach((user) => { | ||
| markDown += `[<img class='contributor-major' src="${user.avatar_url}" alt="${user.login}" width="50"/>](${user.html_url} "${user.login}") `; | ||
| markDown += `[${user.login}](${user.html_url})\n\n`; | ||
| }); | ||
| } | ||
|
|
||
| if (minor.length > 0) { | ||
| // Add the "Minor" contributors, one at a time | ||
| if (major.length > 0) { | ||
| markDown += `### Other ${name}\n`; | ||
| } | ||
| minor.forEach((user) => { | ||
| markDown += `[<img class='contributor-minor' src="${user.avatar_url}" alt="${user.login}" width="50"/>](${user.html_url} "${user.login}") `; | ||
| }); | ||
| } | ||
| return markDown; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Keyman is copyright (C) SIL Global. MIT License. | ||
| * | ||
| * Created by pbdurdin on 2026-01-18 | ||
| * | ||
| * Generate crowdin section of contributors.md | ||
| */ | ||
| import { Client } from "@crowdin/crowdin-api-client"; | ||
|
|
||
| // Initalize an empty crowdin api variable. | ||
| let crowdin = null; | ||
| const crowdinId = 386703; | ||
|
|
||
| export async function getCrowdin(crowdinKey) { | ||
| // Set the aforementioned Crowdin vegtable, with the provided key. | ||
| crowdin = new Client({ | ||
| token: crowdinKey, | ||
| }); | ||
|
|
||
| console.log("Generating Crowdin report"); | ||
|
|
||
| // Generate a Crowdin report | ||
| const crowdata = await crowdin.reportsApi.generateReport(crowdinId, { name: "top-members", schema: { format: "json" } }); | ||
| if (crowdata.data.status !== "finished") { | ||
| // Wait for the report to complete it's generation | ||
| console.log("Waiting"); | ||
| let cdc = await crowdin.reportsApi.checkReportStatus(crowdinId, crowdata.data.identifier); | ||
| while (cdc.data.status !== "finished") { | ||
| await new Promise(resolve => setTimeout(resolve, 1000)); | ||
| cdc = await crowdin.reportsApi.checkReportStatus(crowdinId, crowdata.data.identifier); | ||
| } | ||
| } | ||
|
|
||
| // Fetch generated report. | ||
| console.log("Downloading Crowdin report"); | ||
| const crowdmembers = await crowdin.reportsApi.downloadReport(crowdinId, crowdata.data.identifier); | ||
|
|
||
| const data = await (await fetch(crowdmembers.data.url)).json(); | ||
| return data; | ||
| } | ||
|
|
||
| export function genCrowdin(data) { | ||
| // Modify crowdin data to appear like the github data | ||
| const crowdinMembers = data.data.filter(member => member.translated > 10).map(member => ({ | ||
| login: member.user.username, | ||
| avatar_url: member.user.avatarUrl, | ||
| html_url: `https://crowdin.com/profile/${member.user.username}`, | ||
| contributions: member.translated, | ||
| })); | ||
|
|
||
| // Sort the users by name | ||
| crowdinMembers.sort((a, b) => a.login.localeCompare(b.login)); | ||
| return [[], crowdinMembers]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import js from "@eslint/js"; | ||
| import globals from "globals"; | ||
| import { defineConfig } from "eslint/config"; | ||
| import stylistic from "@stylistic/eslint-plugin"; | ||
|
|
||
| export default defineConfig([ | ||
| { files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.node } }, | ||
| stylistic.configs.customize({ | ||
| indent: 2, | ||
| quotes: "double", | ||
| semi: true, | ||
| jsx: false, | ||
| }), | ||
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * Keyman is copyright (C) SIL Global. MIT License. | ||
| * | ||
| * Created by pbdurdin on 2026-01-18 | ||
| * | ||
| * Generate github section of contributors.md | ||
| */ | ||
| import { Octokit } from "octokit"; | ||
| import { paginateRest } from "@octokit/plugin-paginate-rest"; | ||
|
|
||
| // Initiatlize an empty Octokit variable, to be set later. | ||
| const OctokitInit = Octokit.plugin(paginateRest); | ||
| let octokit = null; | ||
| const githubOrgName = "keymanapp"; | ||
|
|
||
| export async function getGithub(githubKey) { | ||
| // Set the aforementioned Octokit variable, with the provided key. | ||
| octokit = new OctokitInit({ | ||
| auth: githubKey, | ||
| }); | ||
|
|
||
| // Get a list of every repo in the keymanapp github organization | ||
| let allRepos = await getReposByOrg(githubOrgName); | ||
|
|
||
| // Get the data of each of those repositories | ||
| let allRepoData = await getAllRepos(allRepos); | ||
| return allRepoData; | ||
| } | ||
|
|
||
| export function genGithub(repo) { | ||
| const MAJOR_CONTRIBUTION_THRESHOLD = 100; | ||
|
|
||
| // Initialize empty arrays, to be added to later | ||
| let major = []; | ||
| let minor = []; | ||
| let all = []; | ||
|
|
||
| // For each item in the provided data, | ||
| repo.forEach((user) => { | ||
| // ... check for bots, and skip over if one is found, | ||
| if (/^(keyman-server|keyman-status|.+\[bot\])$/.test(user.login)) { | ||
| return; | ||
| } | ||
|
|
||
| // ... if we have not already added this user to the user list, add them, | ||
| if (!all.map(user => user.login).includes(user.login)) { | ||
| all.push(user); | ||
| return; | ||
| } | ||
|
|
||
| // ... Otherwise, increase their contributions score. | ||
| let i = all.findIndex(oldUser => oldUser.login == user.login); | ||
| all[i].contributions += user.contributions; | ||
| }); | ||
|
|
||
| // Sort into the major and minor categories | ||
| all.forEach((user) => { | ||
| if (user.contributions > MAJOR_CONTRIBUTION_THRESHOLD) { | ||
| major.push(user); | ||
| } | ||
| else { | ||
| minor.push(user); | ||
| }; | ||
| }); | ||
|
|
||
| // Sort the major and minor categories by contributions | ||
| major.sort((a, b) => a.login.localeCompare(b.login)); | ||
| minor.sort((a, b) => a.login.localeCompare(b.login)); | ||
| return [major, minor]; | ||
| } | ||
|
|
||
| async function getReposByOrg(org) { | ||
| // Fetch a list of all repositories belonging to this organization. | ||
|
|
||
| console.log("Retrieving list of Repositories"); | ||
| let repos = await octokit.paginate(`GET /orgs/${org}/repos`, { | ||
| org, | ||
| per_page: 100, | ||
| type: "sources", | ||
| headers: { | ||
| "X-GitHub-Api-Version": "2022-11-28", | ||
| }, | ||
| }); | ||
|
|
||
| // Map the repository data to make mearly a list of names. | ||
| return repos.map(repo => repo.name); | ||
| } | ||
|
|
||
| async function getAllRepos(allRepos) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you rename this to make it clearer what it is doing? |
||
| // Fetch the data for the given list of repositories. | ||
|
|
||
| let allRepoData = []; | ||
|
|
||
| // Using for instead of foreach, as foreach does not support asynchrony. | ||
| for (let repo of allRepos) { | ||
| // Get data, then concat it to all previously fetched data. | ||
| console.log(`Fetching repository contributors: ${repo}`); | ||
| let repoData = await getRepo(repo); | ||
| allRepoData = allRepoData.concat(repoData); | ||
| }; | ||
| return allRepoData; | ||
| } | ||
|
|
||
| async function getRepo(repoName) { | ||
| // Fetch data for repo of the inputted name. | ||
| let repo = await octokit.paginate(`GET /repos/${githubOrgName}/${repoName}/contributors`, { | ||
| owner: "keymanapp", | ||
| repo: repoName, | ||
| per_page: 100, | ||
| headers: { | ||
| "X-GitHub-Api-Version": "2022-11-28", | ||
| }, | ||
| }); | ||
| return repo; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.