Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

feat: follow up with reviewer #783

Closed
wants to merge 14 commits into from
21 changes: 20 additions & 1 deletion src/handlers/wildcard/unassign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getAllIssueComments,
getCommitsOnPullRequest,
getOpenedPullRequestsForAnIssue,
getRequestedReviewerStart,
getReviewRequests,
listAllIssuesForRepo,
removeAssignees,
Expand Down Expand Up @@ -56,7 +57,25 @@ const checkBountyToUnassign = async (issue: Issue): Promise<boolean> => {

if (pullRequest.length > 0) {
const reviewRequests = await getReviewRequests(context, pullRequest[0].number, payload.repository.owner.login, payload.repository.name);
if (!reviewRequests || reviewRequests.users?.length > 0) {
if (!reviewRequests) return false;
if (reviewRequests.users?.length > 0) {
let msg = "";
for (const reviewer of reviewRequests.users) {
//check if reviewer has to be followed up with
let reviewRequestedAt = await getRequestedReviewerStart(reviewer.login);
if (!reviewRequestedAt) return false;
EtherealGlow marked this conversation as resolved.
Show resolved Hide resolved

let currDate = new Date();
let expectedDate = new Date(reviewRequestedAt);
expectedDate.setDate(expectedDate.getDate() + 3);
EtherealGlow marked this conversation as resolved.
Show resolved Hide resolved

if (currDate >= expectedDate) {
msg += "@" + reviewer.login + " ";
}
}
msg += "Can you please review this pull request";
// the below function can also add comment to prs
await addCommentToIssue(msg, pullRequest[0].number);
return false;
}
}
Expand Down
46 changes: 46 additions & 0 deletions src/helpers/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,52 @@ export const getPullByNumber = async (context: Context, pull_number: number) =>
}
};

export const getAllIssueEvents = async () => {
EtherealGlow marked this conversation as resolved.
Show resolved Hide resolved
const context = getBotContext();
const logger = getLogger();
const payload = context.payload as Payload;
if (!payload.issue) return;

let shouldFetch = true;
let page_number = 1;
const events = [];

try {
while (shouldFetch) {
// Fetch issue events
const response = await context.octokit.issues.listEvents({
owner: payload.repository.owner.login,
repo: payload.repository.full_name,
issue_number: payload.issue.number,
per_page: 100,
page: page_number,
});

await checkRateLimitGit(response?.headers);

if (response?.data?.length > 0) {
events.push(...response.data);
page_number++;
} else {
shouldFetch = false;
}
}
} catch (e: unknown) {
shouldFetch = false;
logger.error(`Getting all issue events failed, reason: ${e}`);
return null;
}
return events;
};

export const getRequestedReviewerStart = async (user: String) => {
EtherealGlow marked this conversation as resolved.
Show resolved Hide resolved
let events = await getAllIssueEvents();
if (!events) return null;
events = events.filter((e) => e.event === "review_requested");
events = events.filter((e) => e.requested_reviewer?.login === user);
EtherealGlow marked this conversation as resolved.
Show resolved Hide resolved
return events[events.length - 1].created_at;
EtherealGlow marked this conversation as resolved.
Show resolved Hide resolved
};

// Get issues assigned to a username
export const getAssignedIssues = async (username: string) => {
const issuesArr = [];
Expand Down