Skip to content

Instantly share code, notes, and snippets.

@eps1lon
Last active November 22, 2019 11:08
Show Gist options
  • Save eps1lon/04d76f0a12f8f00c69fb3484fd07eccd to your computer and use it in GitHub Desktop.
Save eps1lon/04d76f0a12f8f00c69fb3484fd07eccd to your computer and use it in GitHub Desktop.
/**
* usage:
* 1. edit scripts/getPrAuthors and past a newline separated list of pr numbers
* 2. $ GH_API_TOKEN=YOUR_TOKEN node scripts/getPrAuthors
*/
const { graphql } = require('@octokit/graphql');
const token = process.env.GH_API_TOKEN;
run().catch(error => {
console.error(error);
process.exit(1);
});
async function run() {
const prs = getPrNums().sort();
const authors = await Promise.all(prs.map(getAuthorForPr));
const alreadyMentioned = new Set(getAlreadyMentionedAuthors());
console.log(prs.join(', '));
console.log(
unique(authors)
.filter(author => author !== null)
.map(author => `@${author}`)
.filter(mention => !alreadyMentioned.has(mention))
.join(', '),
);
}
async function getAuthorForPr(number) {
const {
repository: { pullRequest },
} = await graphql(
`
query prAuthor($number: Int!) {
repository(owner: "mui-org", name: "material-ui") {
pullRequest(number: $number) {
author {
login
}
}
}
}
`,
{
number,
headers: {
authorization: `token ${token}`,
},
},
);
if (pullRequest === null) {
return null;
}
return pullRequest.author.login;
}
function unique(list) {
return Array.from(new Set(list));
}
function getPrNums() {
return unique([
15522,
15522,
15485,
15755,
14772,
14954,
15013,
14969,
14969,
14969,
14979,
15139,
17862,
15130,
15011,
15011,
15011,
15011,
15222,
15228,
15237,
17964,
15052,
15050,
15052,
16322,
16322,
15271,
15271,
15273,
15271,
15271,
15271,
15272,
15271,
15271,
15271,
15037,
15284,
15119,
15119,
15119,
15119,
15119,
15119,
15119,
15119,
15162,
15118,
15970,
16003,
16003,
15323,
15323,
15323,
15323,
15323,
15416,
15493,
15323,
15417,
15493,
17913,
17913,
15103,
16322,
16322,
16322,
16322,
16322,
16004,
15104,
15104,
15104,
15104,
15104,
15551,
15104,
15104,
15104,
15104,
15288,
15087,
15223,
15223,
15223,
15223,
15223,
15223,
15223,
15223,
15223,
15086,
15086,
15755,
17938,
15755,
14985,
14985,
15053,
15209,
15061,
15419,
15419,
16003,
16003,
17770,
17766,
17930,
16003,
16003,
16003,
17771,
17790,
17793,
17994,
17983,
16200,
17788,
17788,
17785,
17683,
16334,
16334,
17910,
16334,
16334,
16334,
16334,
16334,
16334,
16334,
16134,
16131,
15548,
16334,
16334,
16334,
15548,
15548,
16875,
16875,
16875,
16875,
16334,
16334,
16334,
16334,
16334,
16334,
16334,
]);
}
function getAlreadyMentionedAuthors() {
return '@VincentLanglet, @vitkon, @cojennin, @jasondashwang, @Dudrie, @rahmatrhd, @eluchsinger, @sperry94, @cahilfoley, @Adherentman, @donigianrp, @bh1505, @JarkEMones, @lksilva, @nareshbhatia, @merceyz'.split(
', ',
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment