From 19771163be1ed6daad6644dbde1281255babf438 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Sun, 1 Sep 2024 16:18:59 +0900 Subject: [PATCH] chore: merge changes --- .../shared/get-user-task-limit-and-role.ts | 25 ------------------- src/types/payload.ts | 2 -- src/utils/issue.ts | 6 ++--- 3 files changed, 3 insertions(+), 30 deletions(-) delete mode 100644 src/handlers/shared/get-user-task-limit-and-role.ts diff --git a/src/handlers/shared/get-user-task-limit-and-role.ts b/src/handlers/shared/get-user-task-limit-and-role.ts deleted file mode 100644 index 4be9b5f..0000000 --- a/src/handlers/shared/get-user-task-limit-and-role.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Context } from "../../types"; - -interface MatchingUserProps { - role: string; - limit: number; -} - -export async function getUserRoleAndTaskLimit(context: Context, user: string): Promise { - const orgLogin = context.payload.organization?.login; - const { config, logger } = context; - const { maxConcurrentTasks } = config.miscellaneous; - const smallestTask = maxConcurrentTasks.reduce((minTask, currentTask) => (currentTask.limit < minTask.limit ? currentTask : minTask)); - - try { - const response = await context.octokit.orgs.getMembershipForUser({ - org: orgLogin as string, - username: user, - }); - - return maxConcurrentTasks.find(({ role }) => role.toLowerCase() === response.data.role) ?? smallestTask; - } catch (err) { - logger.error("Could not get user role", { err }); - return smallestTask; - } -} diff --git a/src/types/payload.ts b/src/types/payload.ts index ab7e671..c0a7787 100644 --- a/src/types/payload.ts +++ b/src/types/payload.ts @@ -9,8 +9,6 @@ export type Assignee = Issue["assignee"]; export type GitHubIssueSearch = RestEndpointMethodTypes["search"]["issuesAndPullRequests"]["response"]["data"]; export type Sender = { login: string; id: number }; -export type Sender = { login: string; id: number }; - export const ISSUE_TYPE = { OPEN: "open", CLOSED: "closed", diff --git a/src/utils/issue.ts b/src/utils/issue.ts index 13adb55..4133c5d 100644 --- a/src/utils/issue.ts +++ b/src/utils/issue.ts @@ -8,7 +8,7 @@ export function isParentIssue(body: string) { return body.match(parentPattern); } -export async function getAssignedIssues(context: Context, username: string): Promise { +export async function getAssignedIssues(context: Context, username: string): Promise { const { payload } = context; try { @@ -163,7 +163,7 @@ export async function getAllPullRequests(context: Context, state: "open" | "clos try { return (await context.octokit.paginate(context.octokit.search.issuesAndPullRequests, { - q: `org:${payload.repository.owner.login} author:${username} state:${state} is:pr`, + q: `org:${payload.repository.owner.login} author:${username} state:${state}`, per_page: 100, order: "desc", sort: "created", @@ -206,7 +206,7 @@ export async function getAvailableOpenedPullRequests(context: Context, username: for (let i = 0; i < openedPullRequests.length; i++) { const openedPullRequest = openedPullRequests[i]; - const [owner, repo] = openedPullRequest.html_url.split("/").slice(3, 4); + const { owner, repo } = getOwnerRepoFromHtmlUrl(openedPullRequest.html_url); const reviews = await getAllPullRequestReviews(context, openedPullRequest.number, owner, repo); if (reviews.length > 0) {