Last active
June 9, 2021 22:49
-
-
Save ewanharris/66e37ab52822ed429cf7de31546faa3c to your computer and use it in GitHub Desktop.
Check for all PRs that had more than 30 commits
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
/** | |
* Requirements: | |
* | |
* node 14 | |
* these dependencies - npm i @octokit/rest date-fns fs-extra | |
*/ | |
import fs from 'fs-extra'; | |
import { isAfter } from 'date-fns'; | |
import Octokit from '@octokit/rest'; | |
import path from 'path'; | |
// we only added the backport action from this date, so we don't care about things before then | |
const addedDate = new Date(2020, 6, 22); | |
const owner = 'appcelerator'; | |
const repo = 'titanium_mobile'; | |
// Ignore backports and prs from dependabot | |
const ignoreAuthors = ['build', 'dependabot-preview[bot]', 'dependabot[bot]']; | |
const octokit = new Octokit.Octokit({ | |
auth: process.env.GITHUB_AUTH | |
}); | |
const options = octokit.pulls.list.endpoint.merge({ | |
owner, | |
repo, | |
state: 'all', | |
per_page: 100 | |
}); | |
const toReview = []; | |
const closeButNoCigar = []; | |
for (const pr of await getPrs()) { | |
if (!isAfter(new Date(pr.created_at), addedDate)) { | |
continue; | |
} | |
if (ignoreAuthors.includes(pr.user.login)) { | |
continue; | |
} | |
const { data: commits } = await octokit.pulls.listCommits({ | |
owner, | |
repo, | |
pull_number: pr.number | |
}); | |
console.log(`${pr.number} ${commits.length}`); | |
if (commits.length >= 30) { | |
const commitOpts = octokit.pulls.listCommits.endpoint.merge({ | |
owner, | |
repo, | |
pull_number: pr.number | |
}); | |
toReview.push({ | |
pr: pr.number, | |
commits: await octokit.paginate(commitOpts), | |
url: pr.html_url | |
}) | |
} else if (commits.length >= 20 ) { | |
closeButNoCigar.push({ | |
pr, | |
commits | |
}); | |
} | |
} | |
console.log('----------------------------------'); | |
console.log('- TO REVIEW -'); | |
console.log('----------------------------------'); | |
for (const pr of toReview) { | |
console.log(`${pr.url} had ${pr.commits.length} commits`); | |
} | |
console.log('----------------------------------'); | |
console.log('- YOU TRIED! -'); | |
console.log('----------------------------------'); | |
for (const { pr, commits } of closeButNoCigar) { | |
console.log(`Congrats ${pr.user.login}, you got ${commits.length} on ${pr.html_url}`); | |
} | |
async function getPrs () { | |
const filename = path.join(process.cwd(), 'cache', 'titanium_mobile_prs.json'); | |
if (await fs.pathExists(filename)) { | |
return fs.readJson(filename); | |
} | |
const prs = await octokit.paginate(options, (response, done) => { | |
const allAfter = response.data.every(pr => !isAfter(new Date(pr.created_at), addedDate)); | |
if (allAfter) { | |
done(); | |
} | |
return response.data; | |
}); | |
await fs.ensureDir(path.join(process.cwd(), 'cache')); | |
await fs.writeJson(filename, prs); | |
return prs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment