Files
freeCodeCamp/tools/contributor/lib/get-prs/pr-stats.js
Oliver Eyton-Williams c8d7f0a782 feat(tools): remove eslint-plugin-prettier for prettier (#42438)
* feat: remove eslint-plugin-prettier for prettier

This removes the annoying lint warnings when all that needs to change is
formatting

* fix: use .js lint-staged config to ignore properly

* fix: lint everything if a lot of files are changed

It's faster than making lots of individual linter calls

* chore: apply prettier

* fix: ignore code in curriculum-file-structure
2021-10-06 21:02:21 +05:30

55 lines
1.2 KiB
JavaScript

const { Octokit } = require('@octokit/rest');
const {
github: { owner, secret }
} = require('../config');
const octokit = new Octokit({ auth: secret });
const getCount = async (repo, base) => {
const baseStr = base ? `+base:${base}` : '';
/* eslint-disable camelcase */
const {
data: { total_count: count }
} = await octokit.search
.issues({
q: `repo:${owner}/${repo}+is:open+type:pr${baseStr}`,
sort: 'created',
order: 'asc',
page: 1,
per_page: 1
})
.catch((err) => console.log(err));
return count;
};
const getRange = async (repo, base) => {
let methodProps = {
owner,
repo,
state: 'open',
sort: 'created',
page: 1,
per_page: 1
};
if (base) {
methodProps = { ...methodProps, base };
}
let response = await octokit.pulls.list({
direction: 'asc',
...methodProps
});
// In the case there are no open PRs for repo
if (!response.data.length) {
return [null, null];
}
const firstPR = response.data[0].number;
response = await octokit.pulls.list({
direction: 'desc',
...methodProps
});
const lastPR = response.data[0].number;
return [firstPR, lastPR];
};
module.exports = { getCount, getRange };