From 2251c84188951529a339f65f781ff310f1a771a0 Mon Sep 17 00:00:00 2001 From: ByteBallet Date: Tue, 5 Sep 2023 05:02:30 -0500 Subject: [PATCH 01/12] fix: get all commits from pr --- src/helpers/issue.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 00ccd0e93..8b90c20aa 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -627,12 +627,25 @@ export const getCommitsOnPullRequest = async (pullNumber: number) => { 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 { data: commits } = await context.octokit.rest.pulls.listCommits({ + owner: payload.repository.owner.login, + repo: payload.repository.name, + pull_number: pullNumber, + per_page: 100, + page: curPage, + }); + allCommits.push(...commits); + if (commits.length < perPage) { + fetchDone = true; + return allCommits; + } else curPage++; + } + return allCommits; } catch (e: unknown) { logger.debug(`Fetching pull request commits failed!, reason: ${e}`); return []; From 094d9e5e2804c50f42574434f9b8feb10e8a0967 Mon Sep 17 00:00:00 2001 From: ByteBallet Date: Wed, 6 Sep 2023 01:37:29 -0500 Subject: [PATCH 02/12] fix: check git rate limit --- src/helpers/issue.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 8b90c20aa..cf830c432 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -632,15 +632,16 @@ export const getCommitsOnPullRequest = async (pullNumber: number) => { const allCommits = []; let fetchDone = false; while (!fetchDone) { - const { data: commits } = await context.octokit.rest.pulls.listCommits({ + const response = await context.octokit.rest.pulls.listCommits({ owner: payload.repository.owner.login, repo: payload.repository.name, pull_number: pullNumber, per_page: 100, page: curPage, }); - allCommits.push(...commits); - if (commits.length < perPage) { + await checkRateLimitGit(response.headers); + allCommits.push(...response.data); + if (response.data.length < perPage) { fetchDone = true; return allCommits; } else curPage++; From ff1384170e6863fc7f60571befab98acb77ce10d Mon Sep 17 00:00:00 2001 From: ByteBallet Date: Mon, 11 Sep 2023 01:14:34 -0500 Subject: [PATCH 03/12] fix: remove draft filter from getOpenedPullRequests --- src/helpers/issue.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index cf830c432..d57485b28 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -619,7 +619,7 @@ export const getOpenedPullRequestsForAnIssue = async (issueNumber: number, userN export const getOpenedPullRequests = async (username: string) => { const context = getBotContext(); const prs = await getAllPullRequests(context, "open"); - return prs.filter((pr) => !pr.draft && (pr.user?.login === username || !username)); + return prs.filter((pr) => pr.user?.login === username || !username); }; export const getCommitsOnPullRequest = async (pullNumber: number) => { From 1191cfdd059092c9a156dc40c8686ff86d0dfa42 Mon Sep 17 00:00:00 2001 From: ByteBallet Date: Tue, 12 Sep 2023 06:37:30 -0500 Subject: [PATCH 04/12] feat: add state to getOpenedPullRequests --- src/handlers/assign/action.ts | 2 +- src/handlers/wildcard/unassign.ts | 2 +- src/helpers/issue.ts | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/handlers/assign/action.ts b/src/handlers/assign/action.ts index b42312a88..deb80e4d3 100644 --- a/src/handlers/assign/action.ts +++ b/src/handlers/assign/action.ts @@ -72,7 +72,7 @@ export const closePullRequestForAnIssue = async (): Promise => { const payload = context.payload as Payload; if (!payload.issue?.number) return; - const prs = await getOpenedPullRequestsForAnIssue(payload.issue.number, ""); + const prs = await getOpenedPullRequestsForAnIssue(payload.issue.number, "", "all"); if (!prs.length) return; logger.info(`Opened prs for this issue: ${JSON.stringify(prs)}`); let comment = `These linked pull requests are closed: `; diff --git a/src/handlers/wildcard/unassign.ts b/src/handlers/wildcard/unassign.ts index 8e06ecebd..9b01dacf2 100644 --- a/src/handlers/wildcard/unassign.ts +++ b/src/handlers/wildcard/unassign.ts @@ -94,7 +94,7 @@ const lastActivityTime = async (issue: Issue, comments: Comment[]): Promise 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) { diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index d57485b28..09df7b3f6 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -601,8 +601,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; @@ -616,10 +616,10 @@ 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.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) => { @@ -658,7 +658,7 @@ export const getAvailableOpenedPullRequests = async (username: string) => { const botConfig = await loadConfig(context); if (!botConfig.unassign.timeRangeForMaxIssueEnabled) return []; - const opened_prs = await getOpenedPullRequests(username); + const opened_prs = await getOpenedPullRequests(username, "ready"); const result = []; From 9c570555cbcc2852a85e529f69efd9307f08c99b Mon Sep 17 00:00:00 2001 From: ByteBallet Date: Tue, 12 Sep 2023 06:41:23 -0500 Subject: [PATCH 05/12] fix: added a param --- src/handlers/wildcard/unassign.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/wildcard/unassign.ts b/src/handlers/wildcard/unassign.ts index 73185abe0..856edfd5d 100644 --- a/src/handlers/wildcard/unassign.ts +++ b/src/handlers/wildcard/unassign.ts @@ -52,7 +52,7 @@ const checkBountyToUnassign = async (issue: Issue): Promise => { 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"); if (pullRequest.length > 0) { const reviewRequests = await getReviewRequests(context, pullRequest[0].number, payload.repository.owner.login, payload.repository.name); From 4166e06b73c114ec858dab95cd80859921b4b667 Mon Sep 17 00:00:00 2001 From: ByteBallet Date: Fri, 22 Sep 2023 05:50:56 -0700 Subject: [PATCH 06/12] chore: change followup time to 5s for pr --- src/configs/shared.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/configs/shared.ts b/src/configs/shared.ts index 8c287c4ff..399c1042c 100644 --- a/src/configs/shared.ts +++ b/src/configs/shared.ts @@ -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"; From db3ba19f352f017a8a4b68ff61ec741e589c9988 Mon Sep 17 00:00:00 2001 From: ByteBallet Date: Mon, 25 Sep 2023 01:55:39 -0700 Subject: [PATCH 07/12] fix: ubiquibot-config --- .github/ubiquibot-config.yml | 58 ++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/.github/ubiquibot-config.yml b/.github/ubiquibot-config.yml index 3658a5818..284eede44 100644 --- a/.github/ubiquibot-config.yml +++ b/.github/ubiquibot-config.yml @@ -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!" \ No newline at end of file +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
If you enjoy the DevPool experience, please follow Ubiquity on GitHub and star this repo to show your support. It helps a lot!
" +registerWalletWithVerification: false +assistivePricing: true +incentives: + comment: + elements: + h1: 5 + totals: + word: 0.1 +enableAccessControl: + label: true + organization: true From 2bb8ae42c2bedfe28d0843309d6773e47fe3d8be Mon Sep 17 00:00:00 2001 From: ByteBallet Date: Mon, 25 Sep 2023 02:50:41 -0700 Subject: [PATCH 08/12] fix: turn config to origin --- .github/ubiquibot-config.yml | 58 ++++-------------------------------- src/configs/shared.ts | 4 +-- 2 files changed, 8 insertions(+), 54 deletions(-) diff --git a/.github/ubiquibot-config.yml b/.github/ubiquibot-config.yml index 284eede44..5aa56f4d6 100644 --- a/.github/ubiquibot-config.yml +++ b/.github/ubiquibot-config.yml @@ -1,52 +1,6 @@ -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
If you enjoy the DevPool experience, please follow Ubiquity on GitHub and star this repo to show your support. It helps a lot!
" -registerWalletWithVerification: false -assistivePricing: true -incentives: - comment: - elements: - h1: 5 - totals: - word: 0.1 -enableAccessControl: - label: true - organization: true +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!" diff --git a/src/configs/shared.ts b/src/configs/shared.ts index 399c1042c..8c287c4ff 100644 --- a/src/configs/shared.ts +++ b/src/configs/shared.ts @@ -21,8 +21,8 @@ export const ASSIGN_COMMAND_ENABLED = true; * ms('-1h') // -3600000 * ms('-200') // -200 */ -export const DEFAULT_FOLLOWUP_TIME = "5s"; // 4 days -export const DEFAULT_DISQUALIFY_TIME = "20s"; // 7 days +export const DEFAULT_FOLLOWUP_TIME = "4 days"; // 4 days +export const DEFAULT_DISQUALIFY_TIME = "7 days"; // 7 days export const DEFAULT_NETWORK_ID = 1; // ethereum export const DEFAULT_RPC_ENDPOINT = "https://rpc-bot.ubq.fi/v1/mainnet"; From 219207dd9029b9493567686e160f0e078915c908 Mon Sep 17 00:00:00 2001 From: byteballet Date: Mon, 2 Oct 2023 19:10:44 -0700 Subject: [PATCH 09/12] fix: remove rate limit check --- src/helpers/issue.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 4cbce0efe..18b08e2dd 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -706,7 +706,6 @@ export const getCommitsOnPullRequest = async (pullNumber: number) => { per_page: 100, page: curPage, }); - await checkRateLimitGit(response.headers); allCommits.push(...response.data); if (response.data.length < perPage) { fetchDone = true; From acba18d110881c6d2b2ff2606bc27b51fcc5c5f2 Mon Sep 17 00:00:00 2001 From: 0xcodercrane <108444211+0xcodercrane@users.noreply.github.com> Date: Tue, 3 Oct 2023 16:27:49 +0800 Subject: [PATCH 10/12] refactor: make it reusable --- src/handlers/wildcard/unassign.ts | 4 ++-- src/helpers/issue.ts | 12 +++++++----- src/types/payload.ts | 6 ++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/handlers/wildcard/unassign.ts b/src/handlers/wildcard/unassign.ts index 93ffec662..ceba8c2bf 100644 --- a/src/handlers/wildcard/unassign.ts +++ b/src/handlers/wildcard/unassign.ts @@ -9,7 +9,7 @@ import { listAllIssuesForRepo, removeAssignees, } from "../../helpers"; -import { Comment, Issue, IssueType, Payload, UserType } from "../../types"; +import { Comment, Issue, IssueType, Payload, PullRequestState, UserType } from "../../types"; import { deadLinePrefix } from "../shared"; /** @@ -52,7 +52,7 @@ const checkBountyToUnassign = async (issue: Issue): Promise => { 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, "ready"); + const pullRequest = await getOpenedPullRequestsForAnIssue(issue.number, issue.assignee.login, PullRequestState.READY); if (pullRequest.length > 0) { const reviewRequests = await getReviewRequests(context, pullRequest[0].number, payload.repository.owner.login, payload.repository.name); diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 18b08e2dd..93d5704c4 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -1,6 +1,6 @@ import { Context } from "probot"; import { getBotConfig, getBotContext, getLogger } from "../bindings"; -import { AssignEvent, Comment, IssueType, Payload, StreamlinedComment, UserType } from "../types"; +import { AssignEvent, Comment, IssueType, Payload, PullRequestState, StreamlinedComment, UserType } from "../types"; import { checkRateLimitGit } from "../utils"; export const getAllIssueEvents = async () => { @@ -668,7 +668,7 @@ export const getAssignedIssues = async (username: string) => { return assigned_issues; }; -export const getOpenedPullRequestsForAnIssue = async (issueNumber: number, userName: string, state: "draft" | "ready" | "all") => { +export const getOpenedPullRequestsForAnIssue = async (issueNumber: number, userName: string, state: PullRequestState) => { const pulls = await getOpenedPullRequests(userName, state); return pulls.filter((pull) => { @@ -683,10 +683,12 @@ export const getOpenedPullRequestsForAnIssue = async (issueNumber: number, userN }); }; -export const getOpenedPullRequests = async (username: string, state: "ready" | "draft" | "all") => { +export const getOpenedPullRequests = async (username: string, state: PullRequestState) => { const context = getBotContext(); const prs = await getAllPullRequests(context, "open"); - return prs.filter((pr) => (state === "ready" ? !pr.draft : state === "draft" ? pr.draft : true) && (pr.user?.login === username || !username)); + return prs.filter( + (pr) => (state === PullRequestState.READY ? !pr.draft : state === PullRequestState.DRAFT ? pr.draft : true) && (pr.user?.login === username || !username) + ); }; export const getCommitsOnPullRequest = async (pullNumber: number) => { @@ -726,7 +728,7 @@ export const getAvailableOpenedPullRequests = async (username: string) => { } = await getBotConfig(); if (!timeRangeForMaxIssueEnabled) return []; - const opened_prs = await getOpenedPullRequests(username, "ready"); + const opened_prs = await getOpenedPullRequests(username, PullRequestState.READY); const result = []; diff --git a/src/types/payload.ts b/src/types/payload.ts index 404991852..61a007b1c 100644 --- a/src/types/payload.ts +++ b/src/types/payload.ts @@ -48,6 +48,12 @@ export enum StateReason { REOPENED = "reopened", } +export enum PullRequestState { + DRAFT = "draft", + READY = "ready", + ALL = "all", +} + const UserSchema = Type.Object({ login: Type.String(), id: Type.Number(), From a296fa3d08ad5ca6525b742b06acac01a25f8c7f Mon Sep 17 00:00:00 2001 From: 0xcodercrane <108444211+0xcodercrane@users.noreply.github.com> Date: Wed, 4 Oct 2023 09:22:37 +0800 Subject: [PATCH 11/12] build: replace more --- src/handlers/wildcard/unassign.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/wildcard/unassign.ts b/src/handlers/wildcard/unassign.ts index ceba8c2bf..e9b8c05dc 100644 --- a/src/handlers/wildcard/unassign.ts +++ b/src/handlers/wildcard/unassign.ts @@ -110,7 +110,7 @@ const lastActivityTime = async (issue: Issue, comments: Comment[]): Promise 0) activities.push(new Date(lastCommentsOfHunterForIssue[0].created_at)); - const openedPrsForIssue = await getOpenedPullRequestsForAnIssue(issue.number, assignees[0], "all"); + const openedPrsForIssue = await getOpenedPullRequestsForAnIssue(issue.number, assignees[0], PullRequestState.ALL); const pr = openedPrsForIssue.length > 0 ? openedPrsForIssue[0] : undefined; // get last commit and last comment on the linked pr if (pr) { From bc6406cade78c3212f5ddfe3b601391ff856d67a Mon Sep 17 00:00:00 2001 From: 0xcodercrane <108444211+0xcodercrane@users.noreply.github.com> Date: Wed, 4 Oct 2023 09:45:14 +0800 Subject: [PATCH 12/12] refactor: a little bit more --- src/helpers/issue.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 93d5704c4..245bbaf8e 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -699,22 +699,21 @@ export const getCommitsOnPullRequest = async (pullNumber: number) => { const perPage = 100; let curPage = 1; const allCommits = []; - let fetchDone = false; - while (!fetchDone) { + + // eslint-disable-next-line no-constant-condition + while (true) { const response = await context.octokit.rest.pulls.listCommits({ owner: payload.repository.owner.login, repo: payload.repository.name, pull_number: pullNumber, - per_page: 100, + per_page: perPage, page: curPage, }); allCommits.push(...response.data); if (response.data.length < perPage) { - fetchDone = true; return allCommits; } else curPage++; } - return allCommits; } catch (e: unknown) { logger.debug(`Fetching pull request commits failed! reason: ${e}`); return [];