Skip to content

Instantly share code, notes, and snippets.

@foolip
Created October 11, 2018 09:26
Show Gist options
  • Save foolip/9b0bd9060a99873d19d5ed77f90becd7 to your computer and use it in GitHub Desktop.
Save foolip/9b0bd9060a99873d19d5ed77f90becd7 to your computer and use it in GitHub Desktop.
const octokit = require('@octokit/rest')()
const repoOptions = { owner: 'web-platform-tests', repo: 'wpt' };
// merge_pr_* tags should exist since July 2017.
const SINCE = Date.parse('2017-07-01T00:00Z');
// gets all PRs with pagination
async function* getAllPullRequests(prOptions) {
let page = 1;
while (true) {
const prs = (await octokit.pullRequests.getAll({
...repoOptions,
...prOptions,
per_page: 100,
page,
})).data;
if (prs.length === 0) {
break;
}
for (const pr of prs) {
yield pr;
}
page++;
}
}
async function main() {
octokit.authenticate({
type: 'token',
token: process.env.GH_TOKEN,
});
// Note: sorting by update time means the order can change, so with
// pagination we may miss some PRs and see some twice. But the
// alternative is to fetch every single PR, since old triple-digit
// PRs can be merged at any time and should be tagged.
const prs = getAllPullRequests({
base: 'master',
state: 'closed',
sort: 'updated',
direction: 'desc',
});
for await (const pr of prs) {
if (Date.parse(pr.updated_at) < SINCE) {
console.log(`Stopping search at PR #${pr.number} updated at ${pr.updated_at}`)
break;
}
// Skip unmerged and old PRs
if (!pr.merged_at || Date.parse(pr.merged_at) < SINCE) {
continue;
}
const tag = `merge_pr_${pr.number}`;
let release;
try {
release = (await octokit.repos.getReleaseByTag({
...repoOptions,
tag
})).data;
} catch (e) {
// no release, check if there's a tag
try {
await octokit.gitdata.getReference({
...repoOptions,
ref: `tags/${tag}`
});
// there is a tag, just no release
console.log(`${tag}: no release`);
} catch(e) {
console.log(`${tag}: no tag`);
}
continue;
}
const manifest = release.assets.find(asset => {
return /^MANIFEST-[0-9a-f]{40}.json.gz$/.test(asset.name);
});
if (!manifest) {
console.log(`${tag}: no manifest`);
continue;
}
// The (compressed) manifest should be >2MB.
if (manifest.size < 2000000) {
console.log(`${tag}: manifest too small (${manifest.size})`);
}
console.log(`${tag}: OK`);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment