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

fix: get all commits from pr #723

Open
wants to merge 16 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ubiquibot-config.yml
kamaalsultan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ priceMultiplier: 1.5
# enabled: true
# header: "Thank you for contributing to UbiquiBot! Please be sure to set your wallet address before completing your first bounty so that the automatic payout upon task completion will work for you."
# helpMenu: true
# footer: "###### Also please star this repository and [@ubiquity/devpool-directory](https://github.com/ubiquity/devpool-directory/) to show your support. It helps a lot!"
# footer: "###### Also please star this repository and [@ubiquity/devpool-directory](https://github.com/ubiquity/devpool-directory/) to show your support. It helps a lot!"
4 changes: 2 additions & 2 deletions src/handlers/wildcard/unassign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const checkBountyToUnassign = async (issue: Issue): Promise<boolean> => {
const curTimestamp = new Date().getTime();
const lastActivity = await lastActivityTime(issue, comments);
const passedDuration = curTimestamp - lastActivity.getTime();
const pullRequest = await getOpenedPullRequestsForAnIssue(issue.number, issue.assignee.login);
const pullRequest = await getOpenedPullRequestsForAnIssue(issue.number, issue.assignee.login, "ready");
kamaalsultan marked this conversation as resolved.
Show resolved Hide resolved

if (pullRequest.length > 0) {
const reviewRequests = await getReviewRequests(context, pullRequest[0].number, payload.repository.owner.login, payload.repository.name);
Expand Down Expand Up @@ -110,7 +110,7 @@ const lastActivityTime = async (issue: Issue, comments: Comment[]): Promise<Date

if (lastCommentsOfHunterForIssue.length > 0) activities.push(new Date(lastCommentsOfHunterForIssue[0].created_at));

const openedPrsForIssue = await getOpenedPullRequestsForAnIssue(issue.number, assignees[0]);
const openedPrsForIssue = await getOpenedPullRequestsForAnIssue(issue.number, assignees[0], "all");
const pr = openedPrsForIssue.length > 0 ? openedPrsForIssue[0] : undefined;
// get last commit and last comment on the linked pr
if (pr) {
Expand Down
36 changes: 25 additions & 11 deletions src/helpers/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,8 @@ export const getAssignedIssues = async (username: string) => {
return assigned_issues;
};

export const getOpenedPullRequestsForAnIssue = async (issueNumber: number, userName: string) => {
const pulls = await getOpenedPullRequests(userName);
export const getOpenedPullRequestsForAnIssue = async (issueNumber: number, userName: string, state: "draft" | "ready" | "all") => {
const pulls = await getOpenedPullRequests(userName, state);

return pulls.filter((pull) => {
if (!pull.body) return false;
Expand All @@ -639,23 +639,37 @@ export const getOpenedPullRequestsForAnIssue = async (issueNumber: number, userN
});
};

export const getOpenedPullRequests = async (username: string) => {
export const getOpenedPullRequests = async (username: string, state: "ready" | "draft" | "all") => {
const context = getBotContext();
const prs = await getAllPullRequests(context, "open");
return prs.filter((pr) => !pr.draft && (pr.user?.login === username || !username));
return prs.filter((pr) => (state === "ready" ? !pr.draft : state === "draft" ? pr.draft : true) && (pr.user?.login === username || !username));
};

export const getCommitsOnPullRequest = async (pullNumber: number) => {
const logger = getLogger();
const context = getBotContext();
const payload = getBotContext().payload as Payload;
try {
const { data: commits } = await context.octokit.rest.pulls.listCommits({
owner: payload.repository.owner.login,
repo: payload.repository.name,
pull_number: pullNumber,
});
return commits;
const perPage = 100;
let curPage = 1;
const allCommits = [];
let fetchDone = false;
while (!fetchDone) {
const response = await context.octokit.rest.pulls.listCommits({
owner: payload.repository.owner.login,
repo: payload.repository.name,
pull_number: pullNumber,
per_page: 100,
0xcodercrane marked this conversation as resolved.
Show resolved Hide resolved
page: curPage,
});
await checkRateLimitGit(response.headers);
kamaalsultan marked this conversation as resolved.
Show resolved Hide resolved
allCommits.push(...response.data);
if (response.data.length < perPage) {
fetchDone = true;
return allCommits;
0xcodercrane marked this conversation as resolved.
Show resolved Hide resolved
} else curPage++;
}
return allCommits;
} catch (e: unknown) {
logger.debug(`Fetching pull request commits failed!, reason: ${e}`);
return [];
Expand All @@ -669,7 +683,7 @@ export const getAvailableOpenedPullRequests = async (username: string) => {
} = await getBotConfig();
if (!timeRangeForMaxIssueEnabled) return [];

const opened_prs = await getOpenedPullRequests(username);
const opened_prs = await getOpenedPullRequests(username, "ready");

const result = [];

Expand Down
Loading