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 10 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
58 changes: 52 additions & 6 deletions .github/ubiquibot-config.yml
kamaalsultan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,52 @@
priceMultiplier: 1.5
# newContributorGreeting:
# 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!"
evmNetworkId: 100
priceMultiplier: 1
issueCreatorMultiplier: 2
privateKeyEncrypted: "YU-tFJFczN3JPVoJu0pQKSbWoeiCFPjKiTXMoFnJxDDxUNX-BBXc6ZHkcQcHVjdOd6ZcEnU1o2jU3F-i05mGJPmhF2rhQYXkNlxu5U5fZMMcgxJ9INhAmktzRBUxWncg4L1HOalZIoQ7gm3nk1a84g"
timeLabels:
- name: "Time: <1 Hour"
- name: "Time: <2 Hours"
- name: "Time: <4 Hours"
- name: "Time: <1 Day"
- name: "Time: <1 Week"
priorityLabels:
- name: "Priority: 0 (Normal)"
- name: "Priority: 1 (Medium)"
- name: "Priority: 2 (High)"
- name: "Priority: 3 (Urgent)"
- name: "Priority: 4 (Emergency)"
defaultLabels:
- "Time: <1 Hour"
- "Priority: 0 (Normal)"
commandSettings:
- name: start
enabled: true
- name: stop
enabled: true
- name: wallet
enabled: true
- name: payout
enabled: true
- name: multiplier
enabled: true
- name: query
enabled: true
- name: allow
enabled: true
- name: autopay
enabled: true
paymentPermitMaxPrice: 1000
commentIncentives: true
disableAnalytics: false
maxConcurrentAssigns: 2
promotionComment: "\n<h6>If you enjoy the DevPool experience, please follow <a href='https://github.com/ubiquity'>Ubiquity on GitHub</a> and star <a href='https://github.com/ubiquity/devpool-directory'>this repo</a> to show your support. It helps a lot!</h6>"
registerWalletWithVerification: false
assistivePricing: true
incentives:
comment:
elements:
h1: 5
totals:
word: 0.1
enableAccessControl:
label: true
organization: true
4 changes: 2 additions & 2 deletions src/configs/shared.ts
kamaalsultan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const ASSIGN_COMMAND_ENABLED = true;
* ms('-1h') // -3600000
* ms('-200') // -200
*/
export const DEFAULT_FOLLOWUP_TIME = "4 days"; // 4 days
export const DEFAULT_DISQUALIFY_TIME = "7 days"; // 7 days
export const DEFAULT_FOLLOWUP_TIME = "5s"; // 4 days
export const DEFAULT_DISQUALIFY_TIME = "20s"; // 7 days

export const DEFAULT_NETWORK_ID = 1; // ethereum
export const DEFAULT_RPC_ENDPOINT = "https://rpc-bot.ubq.fi/v1/mainnet";
Expand Down
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