Created
May 6, 2020 10:14
-
-
Save foolip/21391a51977d199fa0509b0c4dfdbe13 to your computer and use it in GitHub Desktop.
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
const { Octokit } = require('@octokit/rest'); | |
const { throttling } = require('@octokit/plugin-throttling'); | |
const MyOctokit = Octokit.plugin(throttling); | |
const octokit = new MyOctokit({ | |
auth: process.env.GH_TOKEN, | |
throttle: { | |
onRateLimit: (retryAfter, options) => { | |
console.warn(`Request quota exhausted for request ${options.method} ${options.url}, retrying after ${retryAfter} seconds`); | |
return true; | |
}, | |
onAbuseLimit: (retryAfter, options) => { | |
console.warn(`Abuse detected for request ${options.method} ${options.url}`); | |
} | |
} | |
}); | |
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 = 0; | |
while (true) { | |
const prs = (await octokit.pulls.list({ | |
...repoOptions, | |
...prOptions, | |
per_page: 100, | |
page, | |
})).data; | |
if (prs.length === 0) { | |
break; | |
} | |
console.log(`# page ${page}`); | |
for (const pr of prs) { | |
yield pr; | |
} | |
page++; | |
} | |
} | |
async function main() { | |
// Note: with pagination on a filtered subset of PRs that can change we may | |
// miss some PRs or see some twice. But the alternative is to fetch every | |
// single PR, since old PRs can be merged at any time and should be tagged. | |
const prs = getAllPullRequests({ | |
base: 'master', | |
state: 'closed', | |
sort: 'created', | |
direction: 'desc', | |
}); | |
for await (const pr of prs) { | |
// 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