Skip to content

Commit

Permalink
Use pagination for PRs where needed; labels count as activity
Browse files Browse the repository at this point in the history
  • Loading branch information
area committed Jul 29, 2024
1 parent bbd2535 commit b4e771a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
10 changes: 7 additions & 3 deletions scripts/github-pr-reminder-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getMessage = async robot => {
const BASE_URL = `https://api.github.com/repos/${repo}`


const { getPRs, getReviews, getComments } = prHelpers(robot)
const { getPRs, getReviews, getComments, getPREvents } = prHelpers(robot)
const prs = await getPRs(BASE_URL)

const soon = [];
Expand All @@ -40,12 +40,16 @@ const getMessage = async robot => {
continue;
}
const reviews = await getReviews(pr);

const comments = await getComments(pr);
const events = await getPREvents(pr);

const labellingEvents = events.filter(event => event.event === 'labeled' || event.event === 'unlabeled');

const last_review_timestamp = reviews.length > 0 ? reviews[reviews.length - 1].submitted_at : pr.created_at;
const last_comment_timestamp = comments.length > 0 ? comments[comments.length - 1].created_at : pr.created_at;
const last_label_timestamp = labellingEvents.length > 0 ? labellingEvents[labellingEvents.length - 1].created_at : pr.created_at;

const last_event_timestamp = Math.max(new Date(last_review_timestamp), new Date(last_comment_timestamp));
const last_event_timestamp = Math.max(new Date(last_review_timestamp), new Date(last_comment_timestamp), new Date(last_label_timestamp));

const days = getBusinessDatesCount(new Date(last_event_timestamp), new Date());
if (days >= threshold -2 && days < threshold) {
Expand Down
44 changes: 35 additions & 9 deletions scripts/utils/prs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,45 @@ const prHelpers = robot => {
}

const getPREvents = async pr => {
return new Promise(resolve => {
github.get(`${pr.issue_url}/events`, res => {
resolve(res)
const events = []
let nOnPage = 30
let page = 1
const ghget = async function(url) {
return new Promise(resolve => {
github.get(url, res => {
resolve(res)
})
})
})
}

while (nOnPage === 30) {
const res = await ghget(`${pr.issue_url}/events?per_page=${nOnPage}&page=${page}`)
nOnPage = res.length
page +=1
events.push(...res)
}

return events
}

const getReviews = async pr => {
return new Promise(resolve => {
github.get(`${pr.url}/reviews`, res => {
resolve(res)
})
})
const reviews = []
let nOnPage = 30
let page = 1
const ghget = async function(url) {
return new Promise(resolve => {
github.get(url, res => {
resolve(res)
})
})
}
while (nOnPage === 30) {
const res = await ghget(`${pr.url}/reviews?per_page=${nOnPage}&page=${page}`)
nOnPage = res.length
page +=1
reviews.push(...res)
}
return reviews
}

const getComments = async pr => {
Expand Down

0 comments on commit b4e771a

Please sign in to comment.