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
2 changes: 2 additions & 0 deletions src/bindings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
botDelay,
followUpTime,
disqualifyTime,
followUpReviewerTime,
} = await getWideConfig(context);

const publicKey = await getScalarKey(process.env.X25519_PRIVATE_KEY);
Expand Down Expand Up @@ -71,6 +72,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
: timeRangeForMaxIssueEnabled,
followUpTime: ms(process.env.FOLLOW_UP_TIME || followUpTime),
disqualifyTime: ms(process.env.DISQUALIFY_TIME || disqualifyTime),
followUpReviewerTime: ms(process.env.FOLLOW_UP_REVIEWER_TIME || followUpReviewerTime),
},
supabase: {
url: process.env.SUPABASE_URL ?? "",
Expand Down
1 change: 1 addition & 0 deletions src/configs/ubiquibot-config-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const DefaultConfig: MergedConfig = {
permitBaseUrl: "https://pay.ubq.fi",
botDelay: 100, // 100ms
followUpTime: "4 days",
followUpReviewerTime: "3 days",
disqualifyTime: "7 days",
newContributorGreeting: {
enabled: true,
Expand Down
23 changes: 21 additions & 2 deletions 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 @@ -36,7 +37,7 @@ const checkBountyToUnassign = async (issue: Issue): Promise<boolean> => {
const payload = context.payload as Payload;
const logger = getLogger();
const {
unassign: { followUpTime, disqualifyTime },
unassign: { followUpTime, disqualifyTime, followUpReviewerTime },
} = getBotConfig();
logger.info(`Checking the bounty to unassign, issue_number: ${issue.number}`);
const { unassignComment, askUpdate } = GLOBAL_STRINGS;
Expand All @@ -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) continue;

let currDate = new Date();
let expectedDate = new Date(reviewRequestedAt);
expectedDate.setTime(expectedDate.getTime() + followUpReviewerTime);

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
10 changes: 10 additions & 0 deletions src/helpers/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,16 @@ export const getPullByNumber = async (context: Context, pull_number: number) =>
}
};

export const getRequestedReviewerStart = async (user: string) => {
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
let events = await getAllIssueEvents();
if (!events) return null;
const filteredEvents = events.filter((e) => e.event === "review_requested" && e.requested_reviewer?.login === user);
if (!filteredEvents) {
return null;
} else {
return events[events.length - 1].created_at;
}
};
// Get issues assigned to a username
export const getAssignedIssues = async (username: string) => {
const issuesArr = [];
Expand Down
2 changes: 2 additions & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const PayoutConfigSchema = Type.Object({

export const UnassignConfigSchema = Type.Object({
followUpTime: Type.Number(),
followUpReviewerTime: Type.Number(),
disqualifyTime: Type.Number(),
timeRangeForMaxIssue: Type.Number(),
timeRangeForMaxIssueEnabled: Type.Boolean(),
Expand Down Expand Up @@ -241,6 +242,7 @@ export const MergedConfigSchema = Type.Object({
permitBaseUrl: Type.String(),
botDelay: Type.Number(),
followUpTime: Type.String(),
followUpReviewerTime: Type.String(),
disqualifyTime: Type.String(),
});

Expand Down
1 change: 1 addition & 0 deletions src/utils/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export const getWideConfig = async (context: Context) => {
botDelay: mergedConfigData.botDelay,
followUpTime: mergedConfigData.followUpTime,
disqualifyTime: mergedConfigData.disqualifyTime,
followUpReviewerTime: mergedConfigData.followUpReviewerTime,
};

return configData;
Expand Down