Skip to content

Instantly share code, notes, and snippets.

@caugner
Created October 31, 2023 17:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caugner/26e1c7359fa852f6c2248584e7feb863 to your computer and use it in GitHub Desktop.
Save caugner/26e1c7359fa852f6c2248584e7feb863 to your computer and use it in GitHub Desktop.
Last 1000 mdn/content PRs with size metrics as CSV
import { writeFileSync } from "node:fs";
import { octokit } from "./lib.js";
async function pullRequests(login, repo, limit, { columns }) {
const items = [];
let after = null;
let hasNextPage = false;
do {
const first = Math.min(limit - items.length, 100);
const res = await octokit.graphql(
`query($login: String!, $repo: String!, $first: Int!, $after: String) {
organization(login: $login) {
repository(name: $repo) {
pullRequests(first: $first, after: $after, orderBy: { direction: DESC, field: CREATED_AT }) {
pageInfo {
startCursor
hasNextPage
endCursor
}
totalCount
nodes {
... on PullRequest {
${columns.join(" ")}
}
}
}
}
}
}`,
{
login,
repo,
first,
after,
},
);
const {
organization: {
repository: {
pullRequests: { pageInfo, nodes },
},
},
} = res;
hasNextPage = pageInfo.hasNextPage;
after = pageInfo.endCursor;
items.push(...nodes);
} while (hasNextPage && items.length < limit);
return items;
}
const columns = [
"url",
"createdAt",
"closedAt",
"mergedAt",
"updatedAt",
"changedFiles",
"additions",
"deletions",
];
const prs = await pullRequests("mdn", "content", 1000, { columns });
const csv = [columns, ...prs.map((pr) => columns.map((column) => pr[column]))]
.map((cells) => cells.join("\t"))
.join("\n");
writeFileSync("prs.csv", csv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment