By default, pulls
sorts by created
, so we can check to see if the 0th index has a number
property greater than the old number
. (the number
is like #1, #4, etc. that shows up on the website). During the time that we're waiting for a new PR, multiple PR's could be made, so we need to filter out data
so that we can have multiple PR's above the previous value.
This was based off of the documentation:
and testing the routes with curl
const { Octokit } = require('@octokit/rest');
const octokit = new Octokit({
auth: "REDACTED"
});
const getData = () => octokit.request('/repos/foo/bar/pulls?state=all');
const getLatestPRNumber = (data) => data.length === 0 ? 0 : data[0]["number"];
const getPRsAboveNumber = (data, prNumber) => data.filter(({number}) => number > prNumber)
(async () => {
const data = await getData();
let latestPR = getLatestPRNumber(data);
setInterval(async () => {
const data = await getData();
const firstPRNumber = getLatestPRNumber(data);
if (firstPRNumber > latestPR) {
const newPRs = getPRsAboveNumber(data, latestPR);
console.log(newPRs);
latestPR = firstPRNumber;
}
}, 1000 * 60); // 1000ms * 60 = 60s
})();
If too many PR's are made, then some PR's wouldn't be accessible since the GitHub API using pagination
Per the documentation:
Name |
Type |
In |
Desc |
per_page |
integer |
query |
Results per page (max 100). Default: 30 |
page |
integer |
query |
Page number of the results to fetch. Default: 1 |