diff --git a/.eslintrc b/.eslintrc index 5cd1103a6..e93d19143 100644 --- a/.eslintrc +++ b/.eslintrc @@ -34,7 +34,23 @@ { "selector": "interface", "format": ["PascalCase"], "custom": { "regex": "^I[A-Z]", "match": false } }, { "selector": ["function", "variable"], "format": ["camelCase"] }, { "selector": "variable", "modifiers": ["destructured"], "format": null }, - { "selector": "variable", "format": ["camelCase"], "leadingUnderscore": "allow", "trailingUnderscore": "allow" } + { "selector": "variable", "format": ["camelCase"], "leadingUnderscore": "allow", "trailingUnderscore": "allow" }, + + { + "selector": "parameter", + "format": ["camelCase"], + "leadingUnderscore": "allow", // This allows the use of a leading underscore + "trailingUnderscore": "allow" // This allows the use of a trailing underscore + }, + { + "selector": "parameter", + "format": null, + "filter": { + // This allows parameters to be named as just an underscore + "regex": "^_$", + "match": true + } + } ] } } diff --git a/src/adapters/index.ts b/src/adapters/index.ts index 07d1ec74e..9e5bf3ee1 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -7,8 +7,9 @@ import { Settlement } from "./supabase/helpers/tables/settlement"; import { Super } from "./supabase/helpers/tables/super"; import { User } from "./supabase/helpers/tables/user"; import { Wallet } from "./supabase/helpers/tables/wallet"; -import { Database } from "./supabase/types"; + import { env } from "../bindings/env"; +import { Database } from "./supabase/types/database"; export const supabaseClient = createClient(env.SUPABASE_URL, env.SUPABASE_KEY, { auth: { persistSession: false }, diff --git a/src/adapters/supabase/helpers/tables/label.ts b/src/adapters/supabase/helpers/tables/label.ts index da1236213..bf61e35ea 100644 --- a/src/adapters/supabase/helpers/tables/label.ts +++ b/src/adapters/supabase/helpers/tables/label.ts @@ -1,8 +1,9 @@ import { SupabaseClient } from "@supabase/supabase-js"; import { Repository } from "../../../../types/payload"; -import { Database } from "../../types"; -import { Super } from "./super"; + import Runtime from "../../../../bindings/bot-runtime"; +import { Super } from "./super"; +import { Database } from "../../types/database"; type LabelRow = Database["public"]["Tables"]["labels"]["Row"]; diff --git a/src/adapters/supabase/helpers/tables/logs.ts b/src/adapters/supabase/helpers/tables/logs.ts index 334e39e5c..bb5684be7 100644 --- a/src/adapters/supabase/helpers/tables/logs.ts +++ b/src/adapters/supabase/helpers/tables/logs.ts @@ -7,7 +7,8 @@ import { SupabaseClient } from "@supabase/supabase-js"; import { execSync } from "child_process"; import { Context as ProbotContext } from "probot"; import Runtime from "../../../../bindings/bot-runtime"; -import { Database } from "../../types"; +import { Database } from "../../types/database"; + import { LogLevel, PrettyLogs } from "../pretty-logs"; type LogFunction = (message: string, metadata?: any) => void; diff --git a/src/adapters/supabase/helpers/tables/wallet.test.ts b/src/adapters/supabase/helpers/tables/wallet.test.ts index ebee5afbe..5fe9905ed 100644 --- a/src/adapters/supabase/helpers/tables/wallet.test.ts +++ b/src/adapters/supabase/helpers/tables/wallet.test.ts @@ -2,7 +2,7 @@ import dotenv from "dotenv"; dotenv.config(); import { createAdapters } from "../../.."; -import { User } from "../../../../types"; +import { User } from "../../../../types/payload"; const SUPABASE_URL = process.env.SUPABASE_URL; if (!SUPABASE_URL) throw new Error("SUPABASE_URL is not defined"); const SUPABASE_KEY = process.env.SUPABASE_KEY; diff --git a/src/adapters/supabase/helpers/tables/wallet.ts b/src/adapters/supabase/helpers/tables/wallet.ts index dc055476e..a6dc286e2 100644 --- a/src/adapters/supabase/helpers/tables/wallet.ts +++ b/src/adapters/supabase/helpers/tables/wallet.ts @@ -1,7 +1,8 @@ import { PostgrestError, SupabaseClient } from "@supabase/supabase-js"; import { Context as ProbotContext } from "probot"; import Runtime from "../../../../bindings/bot-runtime"; -import { User } from "../../../../types"; +import { User } from "../../../../types/payload"; + import { Database } from "../../types/database"; import { Super } from "./super"; import { UserRow } from "./user"; diff --git a/src/bindings/event.ts b/src/bindings/event.ts index 67307e4fc..a5a552ccf 100644 --- a/src/bindings/event.ts +++ b/src/bindings/event.ts @@ -7,7 +7,8 @@ import { processors, wildcardProcessors } from "../handlers/processors"; import { validateConfigChange } from "../handlers/push"; import structuredMetadata from "../handlers/shared/structured-metadata"; import { addCommentToIssue, shouldSkip } from "../helpers"; -import { BotConfig } from "../types"; +import { BotConfig } from "../types/configuration-types"; + import { Context } from "../types/context"; import { HandlerReturnValuesNoVoid, diff --git a/src/handlers/access/labels-access.ts b/src/handlers/access/labels-access.ts index 28b17d96d..4b7b47695 100644 --- a/src/handlers/access/labels-access.ts +++ b/src/handlers/access/labels-access.ts @@ -1,6 +1,7 @@ import Runtime from "../../bindings/bot-runtime"; -import { addCommentToIssue, isUserAdminOrBillingManager, removeLabel, addLabelToIssue } from "../../helpers"; -import { Context, UserType } from "../../types"; +import { addCommentToIssue, addLabelToIssue, isUserAdminOrBillingManager, removeLabel } from "../../helpers"; +import { Context } from "../../types/context"; +import { UserType } from "../../types/payload"; export async function labelAccessPermissionsCheck(context: Context) { const runtime = Runtime.getState(); diff --git a/src/handlers/assign/action.ts b/src/handlers/assign/action.ts index e5adc5dc5..3f53df1e1 100644 --- a/src/handlers/assign/action.ts +++ b/src/handlers/assign/action.ts @@ -1,6 +1,8 @@ import { calculateDurations, calculateLabelValue, closePullRequest } from "../../helpers"; import { getLinkedPullRequests } from "../../helpers/parser"; -import { Context, Label, Payload } from "../../types"; +import { Context } from "../../types/context"; +import { Label } from "../../types/label"; +import { Payload } from "../../types/payload"; export async function startCommandHandler(context: Context) { const config = context.config; diff --git a/src/handlers/assign/auto.ts b/src/handlers/assign/auto.ts index 828546d2c..b2f96dab8 100644 --- a/src/handlers/assign/auto.ts +++ b/src/handlers/assign/auto.ts @@ -1,6 +1,6 @@ import { addAssignees, getAllPullRequests, getIssueByNumber, getPullByNumber } from "../../helpers"; import { getLinkedIssues } from "../../helpers/parser"; -import { Context } from "../../types"; +import { Context } from "../../types/context"; // Check for pull requests linked to their respective issues but not assigned to them export async function checkPullRequests(context: Context) { diff --git a/src/handlers/comment/action.ts b/src/handlers/comment/action.ts index 0bae451c4..a0a8ea8f9 100644 --- a/src/handlers/comment/action.ts +++ b/src/handlers/comment/action.ts @@ -1,6 +1,8 @@ -import { Comment, Payload, Context } from "../../types"; +import { Context } from "../../types/context"; import { commentParser, userCommands } from "./handlers"; import { verifyFirstCommentInRepository } from "./handlers/first"; +import { Payload } from "../../types/payload"; +import { Comment } from "../../types/payload"; export async function commentCreatedOrEdited(context: Context) { const config = context.config, diff --git a/src/handlers/comment/handlers/ask.ts b/src/handlers/comment/handlers/ask.ts index 877909706..cdfad0863 100644 --- a/src/handlers/comment/handlers/ask.ts +++ b/src/handlers/comment/handlers/ask.ts @@ -1,7 +1,9 @@ -import { Context, Payload, StreamlinedComment, UserType } from "../../../types"; -import { getAllIssueComments, getAllLinkedIssuesAndPullsInBody } from "../../../helpers"; import { CreateChatCompletionRequestMessage } from "openai/resources/chat"; +import { getAllIssueComments, getAllLinkedIssuesAndPullsInBody } from "../../../helpers"; import { askGPT, decideContextGPT, sysMsg } from "../../../helpers/gpt"; +import { Context } from "../../../types/context"; +import { StreamlinedComment } from "../../../types/openai"; +import { Payload, UserType } from "../../../types/payload"; export async function ask(context: Context, body: string) { // The question to ask diff --git a/src/handlers/comment/handlers/assign/check-task-stale.ts b/src/handlers/comment/handlers/assign/check-task-stale.ts index 121456afd..040d81e2b 100644 --- a/src/handlers/comment/handlers/assign/check-task-stale.ts +++ b/src/handlers/comment/handlers/assign/check-task-stale.ts @@ -1,4 +1,4 @@ -import { Issue } from "../../../../types"; +import { Issue } from "../../../../types/payload"; export function checkTaskStale(staleTask: number, issue: Issue) { let days: number | undefined; diff --git a/src/handlers/comment/handlers/assign/generate-assignment-comment.ts b/src/handlers/comment/handlers/assign/generate-assignment-comment.ts index aa3e4751e..104498922 100644 --- a/src/handlers/comment/handlers/assign/generate-assignment-comment.ts +++ b/src/handlers/comment/handlers/assign/generate-assignment-comment.ts @@ -1,5 +1,6 @@ import Runtime from "../../../../bindings/bot-runtime"; -import { Context, Payload } from "../../../../types"; +import { Context } from "../../../../types/context"; +import { Payload } from "../../../../types/payload"; const options: Intl.DateTimeFormatOptions = { weekday: "short", diff --git a/src/handlers/comment/handlers/assign/get-multiplier-info-to-display.ts b/src/handlers/comment/handlers/assign/get-multiplier-info-to-display.ts index 022e7cbfd..312d81ac7 100644 --- a/src/handlers/comment/handlers/assign/get-multiplier-info-to-display.ts +++ b/src/handlers/comment/handlers/assign/get-multiplier-info-to-display.ts @@ -1,4 +1,5 @@ -import { Issue, Context } from "../../../../types"; +import { Context } from "../../../../types/context"; +import { Issue } from "../../../../types/payload"; import { taskPaymentMetaData } from "../../../wildcard"; import { getUserMultiplier } from "./get-user-multiplier"; diff --git a/src/handlers/comment/handlers/assign/get-time-labels-assigned.ts b/src/handlers/comment/handlers/assign/get-time-labels-assigned.ts index fde0dd8eb..4ee9a33f7 100644 --- a/src/handlers/comment/handlers/assign/get-time-labels-assigned.ts +++ b/src/handlers/comment/handlers/assign/get-time-labels-assigned.ts @@ -1,4 +1,7 @@ -import { BotConfig, Context, Label, Payload } from "../../../../types"; +import { BotConfig } from "../../../../types/configuration-types"; +import { Context } from "../../../../types/context"; +import { Label } from "../../../../types/label"; +import { Payload } from "../../../../types/payload"; export function getTimeLabelsAssigned(context: Context, payload: Payload, config: BotConfig) { const logger = context.logger; diff --git a/src/handlers/comment/handlers/assign/index.ts b/src/handlers/comment/handlers/assign/index.ts index 33d84972c..00918d9a7 100644 --- a/src/handlers/comment/handlers/assign/index.ts +++ b/src/handlers/comment/handlers/assign/index.ts @@ -4,7 +4,9 @@ import { getAssignedIssues, getAvailableOpenedPullRequests, } from "../../../../helpers"; -import { Context, IssueType, Payload, User } from "../../../../types"; +import { Context } from "../../../../types/context"; +import { User, IssueType, Payload } from "../../../../types/payload"; + import { isParentIssue } from "../../../pricing"; import structuredMetadata from "../../../shared/structured-metadata"; import { assignTableComment } from "../table"; @@ -24,7 +26,7 @@ export async function assign(context: Context, body: string) { disabledCommands, } = context.config; - const isStartDisabled = disabledCommands.some((command) => command === "start"); + const isStartDisabled = disabledCommands.some((command: string) => command === "start"); logger.info("Received '/start' command", { sender: payload.sender.login, body }); diff --git a/src/handlers/comment/handlers/authorize.ts b/src/handlers/comment/handlers/authorize.ts index a1c6b2d60..2456bda9b 100644 --- a/src/handlers/comment/handlers/authorize.ts +++ b/src/handlers/comment/handlers/authorize.ts @@ -1,6 +1,8 @@ import Runtime from "../../../bindings/bot-runtime"; import { isUserAdminOrBillingManager } from "../../../helpers"; -import { Context, Payload } from "../../../types"; +import { Context } from "../../../types/context"; +import { Payload } from "../../../types/payload"; + import { taskPaymentMetaData } from "../../wildcard"; export async function authorizeLabelChanges(context: Context) { diff --git a/src/handlers/comment/handlers/first.ts b/src/handlers/comment/handlers/first.ts index e96dfa8cc..c7fbff3a2 100644 --- a/src/handlers/comment/handlers/first.ts +++ b/src/handlers/comment/handlers/first.ts @@ -1,4 +1,5 @@ -import { Context, Payload } from "../../../types"; +import { Context } from "../../../types/context"; +import { Payload } from "../../../types/payload"; import { generateHelpMenu } from "./help"; export async function verifyFirstCommentInRepository(context: Context) { diff --git a/src/handlers/comment/handlers/help.ts b/src/handlers/comment/handlers/help.ts index 396ae5a72..8515491df 100644 --- a/src/handlers/comment/handlers/help.ts +++ b/src/handlers/comment/handlers/help.ts @@ -1,5 +1,5 @@ import { userCommands } from "."; -import { Context } from "../../../types"; +import { Context } from "../../../types/context"; export async function listAvailableCommands(context: Context, body: string) { const logger = context.logger; diff --git a/src/handlers/comment/handlers/index.ts b/src/handlers/comment/handlers/index.ts index 2a2a299b3..1cefd04cc 100644 --- a/src/handlers/comment/handlers/index.ts +++ b/src/handlers/comment/handlers/index.ts @@ -1,4 +1,3 @@ -import { UserCommands } from "../../../types"; import { assign } from "./assign"; import { listAvailableCommands } from "./help"; // Commented out until Gnosis Safe is integrated (https://github.com/ubiquity/ubiquibot/issues/353) @@ -13,6 +12,7 @@ import { registerWallet } from "./wallet"; import { autoPay } from "./payout"; import { query } from "./query"; +import { UserCommands } from "../../../types/handlers"; export * from "./ask"; export * from "./assign"; diff --git a/src/handlers/comment/handlers/issue/assignee-scoring.ts b/src/handlers/comment/handlers/issue/assignee-scoring.ts index da9f79b02..6498bf58d 100644 --- a/src/handlers/comment/handlers/issue/assignee-scoring.ts +++ b/src/handlers/comment/handlers/issue/assignee-scoring.ts @@ -2,7 +2,7 @@ import Decimal from "decimal.js"; import { Issue, User } from "../../../../types/payload"; import { ContributorView } from "./contribution-style-types"; import { UserScoreDetails } from "./issue-shared-types"; -import { Context } from "../../../../types"; +import { Context } from "../../../../types/context"; export async function assigneeScoring( context: Context, diff --git a/src/handlers/comment/handlers/issue/calculate-quality-score.test.ts b/src/handlers/comment/handlers/issue/calculate-quality-score.test.ts index 4e741a0a0..c32e3a47b 100644 --- a/src/handlers/comment/handlers/issue/calculate-quality-score.test.ts +++ b/src/handlers/comment/handlers/issue/calculate-quality-score.test.ts @@ -1,5 +1,5 @@ import OpenAI from "openai"; -import { Context } from "../../../../types"; +import { Context } from "../../../../types/context"; import { Comment, Issue, User, UserType } from "../../../../types/payload"; import { countTokensOfConversation, estimateOptimalModel, gptRelevance, relevanceScoring } from "./relevance-scoring"; diff --git a/src/handlers/comment/handlers/issue/comment-scoring-rubric.ts b/src/handlers/comment/handlers/issue/comment-scoring-rubric.ts index 3be4194ef..aee1694b8 100644 --- a/src/handlers/comment/handlers/issue/comment-scoring-rubric.ts +++ b/src/handlers/comment/handlers/issue/comment-scoring-rubric.ts @@ -6,7 +6,7 @@ import MarkdownIt from "markdown-it"; import { Comment } from "../../../../types/payload"; import { ContributorClassesKeys } from "./contribution-style-types"; import { FormatScoreConfig, FormatScoreConfigParams } from "./element-score-config"; -import { Context } from "../../../../types"; +import { Context } from "../../../../types/context"; export type Tags = keyof HTMLElementTagNameMap; diff --git a/src/handlers/comment/handlers/issue/generate-permit-2-signature.ts b/src/handlers/comment/handlers/issue/generate-permit-2-signature.ts index fdb2bba08..c81c367cd 100644 --- a/src/handlers/comment/handlers/issue/generate-permit-2-signature.ts +++ b/src/handlers/comment/handlers/issue/generate-permit-2-signature.ts @@ -2,9 +2,10 @@ import { MaxUint256, PERMIT2_ADDRESS, PermitTransferFrom, SignatureTransfer } fr import Decimal from "decimal.js"; import { BigNumber, ethers } from "ethers"; import { keccak256, toUtf8Bytes } from "ethers/lib/utils"; -import { Context } from "../../../../types"; + import { getPayoutConfigByNetworkId } from "../../../../helpers"; import { decryptKeys } from "../../../../utils/private"; +import { Context } from "../../../../types/context"; export async function generatePermit2Signature( context: Context, diff --git a/src/handlers/comment/handlers/issue/generate-permits.ts b/src/handlers/comment/handlers/issue/generate-permits.ts index 75ff5ee5d..bced36afa 100644 --- a/src/handlers/comment/handlers/issue/generate-permits.ts +++ b/src/handlers/comment/handlers/issue/generate-permits.ts @@ -4,7 +4,9 @@ import { stringify } from "yaml"; import Runtime from "../../../../bindings/bot-runtime"; import { getPayoutConfigByNetworkId } from "../../../../helpers"; import { getTokenSymbol } from "../../../../helpers/contracts"; -import { Context, Issue, Payload } from "../../../../types"; +import { Context } from "../../../../types/context"; +import { Issue, Payload } from "../../../../types/payload"; + import structuredMetadata from "../../../shared/structured-metadata"; import { generatePermit2Signature } from "./generate-permit-2-signature"; import { UserScoreTotals } from "./issue-shared-types"; diff --git a/src/handlers/comment/handlers/issue/get-collaborator-ids-for-repo.ts b/src/handlers/comment/handlers/issue/get-collaborator-ids-for-repo.ts index 751e1c674..1b480c8c4 100644 --- a/src/handlers/comment/handlers/issue/get-collaborator-ids-for-repo.ts +++ b/src/handlers/comment/handlers/issue/get-collaborator-ids-for-repo.ts @@ -1,4 +1,5 @@ -import { Context, Payload, User } from "../../../../types"; +import { Context } from "../../../../types/context"; +import { Payload, User } from "../../../../types/payload"; export async function getCollaboratorsForRepo(context: Context): Promise { const payload = context.event.payload as Payload; diff --git a/src/handlers/comment/handlers/issue/getPullRequestComments.ts b/src/handlers/comment/handlers/issue/getPullRequestComments.ts index f0831d258..ae01f968b 100644 --- a/src/handlers/comment/handlers/issue/getPullRequestComments.ts +++ b/src/handlers/comment/handlers/issue/getPullRequestComments.ts @@ -1,6 +1,7 @@ import { getAllIssueComments } from "../../../../helpers"; import { getLinkedPullRequests } from "../../../../helpers/parser"; -import { Context } from "../../../../types"; +import { Context } from "../../../../types/context"; + import { Comment } from "../../../../types/payload"; export async function getPullRequestComments(context: Context, owner: string, repository: string, issueNumber: number) { diff --git a/src/handlers/comment/handlers/issue/identify-user-ids.ts b/src/handlers/comment/handlers/issue/identify-user-ids.ts index a7c7940ce..17c12271a 100644 --- a/src/handlers/comment/handlers/issue/identify-user-ids.ts +++ b/src/handlers/comment/handlers/issue/identify-user-ids.ts @@ -1,4 +1,4 @@ -import { Context } from "../../../../types"; +import { Context } from "../../../../types/context"; import { Comment, Issue, User } from "../../../../types/payload"; import { ContributorClasses } from "./contribution-style-types"; import { getCollaboratorsForRepo } from "./get-collaborator-ids-for-repo"; diff --git a/src/handlers/comment/handlers/issue/issue-closed.ts b/src/handlers/comment/handlers/issue/issue-closed.ts index c3c125b6a..8820f8ccc 100644 --- a/src/handlers/comment/handlers/issue/issue-closed.ts +++ b/src/handlers/comment/handlers/issue/issue-closed.ts @@ -1,6 +1,7 @@ import Runtime from "../../../../bindings/bot-runtime"; import { checkUserPermissionForRepoAndOrg, getAllIssueComments } from "../../../../helpers"; -import { Context } from "../../../../types"; +import { Context } from "../../../../types/context"; + import { Comment, Issue, Payload, StateReason } from "../../../../types/payload"; import structuredMetadata from "../../../shared/structured-metadata"; import { generatePermits } from "./generate-permits"; diff --git a/src/handlers/comment/handlers/issue/perUserCommentScoring.ts b/src/handlers/comment/handlers/issue/perUserCommentScoring.ts index 64e007c15..cfeeee1e6 100644 --- a/src/handlers/comment/handlers/issue/perUserCommentScoring.ts +++ b/src/handlers/comment/handlers/issue/perUserCommentScoring.ts @@ -1,4 +1,4 @@ -import { Context } from "../../../../types"; +import { Context } from "../../../../types/context"; import { Comment, User } from "../../../../types/payload"; import { CommentScoring } from "./comment-scoring-rubric"; diff --git a/src/handlers/comment/handlers/issue/relevance-scoring.ts b/src/handlers/comment/handlers/issue/relevance-scoring.ts index 86fed1792..29852f6a4 100644 --- a/src/handlers/comment/handlers/issue/relevance-scoring.ts +++ b/src/handlers/comment/handlers/issue/relevance-scoring.ts @@ -1,7 +1,8 @@ import Decimal from "decimal.js"; import { encodingForModel } from "js-tiktoken"; import OpenAI from "openai"; -import { Context } from "../../../../types"; +import { Context } from "../../../../types/context"; + import { Comment, Issue } from "../../../../types/payload"; export async function relevanceScoring(context: Context, issue: Issue, contributorComments: Comment[]) { @@ -145,7 +146,7 @@ function filterSamples(context: Context, batchResults: number[][], correctLength function averageSamples(batchResults: (number | Decimal)[][], precision: number) { const averageScores = batchResults[0] - .map((x, columnIndex) => { + .map((_, columnIndex) => { let sum = new Decimal(0); batchResults.forEach((row) => { sum = sum.plus(row[columnIndex]); diff --git a/src/handlers/comment/handlers/issue/specification-scoring.ts b/src/handlers/comment/handlers/issue/specification-scoring.ts index 26f8c298d..a663e2040 100644 --- a/src/handlers/comment/handlers/issue/specification-scoring.ts +++ b/src/handlers/comment/handlers/issue/specification-scoring.ts @@ -1,6 +1,5 @@ import Decimal from "decimal.js"; -import { Context } from "../../../../types"; import { Comment, Issue } from "../../../../types/payload"; import { allCommentScoring } from "./allCommentScoring"; import { UserScoreDetails } from "./issue-shared-types"; @@ -8,6 +7,7 @@ import { addRelevanceAndFormatScoring } from "./relevance-format-scoring"; // import Runtime from "../../../../bindings/bot-runtime"; import { ContributorView } from "./contribution-style-types"; +import { Context } from "../../../../types/context"; export type ContextIssue = { context: Context; issue: Issue }; diff --git a/src/handlers/comment/handlers/labels.ts b/src/handlers/comment/handlers/labels.ts index ec3068c6b..4b04c5dd5 100644 --- a/src/handlers/comment/handlers/labels.ts +++ b/src/handlers/comment/handlers/labels.ts @@ -1,6 +1,7 @@ import Runtime from "../../../bindings/bot-runtime"; import { isUserAdminOrBillingManager } from "../../../helpers"; -import { Context, Payload } from "../../../types"; +import { Context } from "../../../types/context"; +import { Payload } from "../../../types/payload"; export async function setLabels(context: Context, body: string) { const logger = context.logger; diff --git a/src/handlers/comment/handlers/multiplier.ts b/src/handlers/comment/handlers/multiplier.ts index 984b37d72..bb6a8cf76 100644 --- a/src/handlers/comment/handlers/multiplier.ts +++ b/src/handlers/comment/handlers/multiplier.ts @@ -1,6 +1,8 @@ import Runtime from "../../../bindings/bot-runtime"; import { isUserAdminOrBillingManager } from "../../../helpers"; -import { Context, Payload } from "../../../types"; +import { Context } from "../../../types/context"; +import { Payload } from "../../../types/payload"; + /** * You can use this command to set a multiplier for a user. * It will accept arguments in any order. diff --git a/src/handlers/comment/handlers/payout.ts b/src/handlers/comment/handlers/payout.ts index fcc379686..32d1ff4a4 100644 --- a/src/handlers/comment/handlers/payout.ts +++ b/src/handlers/comment/handlers/payout.ts @@ -1,5 +1,6 @@ -import { Context, Payload } from "../../../types"; import { isUserAdminOrBillingManager } from "../../../helpers/issue"; +import { Context } from "../../../types/context"; +import { Payload } from "../../../types/payload"; export async function autoPay(context: Context, body: string) { const payload = context.event.payload as Payload; diff --git a/src/handlers/comment/handlers/query.ts b/src/handlers/comment/handlers/query.ts index 365612c00..a65ef134e 100644 --- a/src/handlers/comment/handlers/query.ts +++ b/src/handlers/comment/handlers/query.ts @@ -1,6 +1,8 @@ import Runtime from "../../../bindings/bot-runtime"; -import { Context, Payload } from "../../../types"; + import _ from "lodash"; +import { Context } from "../../../types/context"; +import { Payload } from "../../../types/payload"; export async function query(context: Context, body: string) { const runtime = Runtime.getState(), diff --git a/src/handlers/comment/handlers/unassign.ts b/src/handlers/comment/handlers/unassign.ts index 903c2768f..bcfbf2046 100644 --- a/src/handlers/comment/handlers/unassign.ts +++ b/src/handlers/comment/handlers/unassign.ts @@ -1,5 +1,6 @@ -import { Context, Payload } from "../../../types"; import { closePullRequestForAnIssue } from "../../assign/index"; +import { Payload } from "../../../types/payload"; +import { Context } from "../../../types/context"; export async function unassign(context: Context, body: string) { const logger = context.logger; diff --git a/src/handlers/comment/handlers/wallet.ts b/src/handlers/comment/handlers/wallet.ts index 11bde13f2..09c847978 100644 --- a/src/handlers/comment/handlers/wallet.ts +++ b/src/handlers/comment/handlers/wallet.ts @@ -1,7 +1,9 @@ import { constants, ethers } from "ethers"; import Runtime from "../../../bindings/bot-runtime"; import { resolveAddress } from "../../../helpers"; -import { Context, Payload } from "../../../types"; +import { Context } from "../../../types/context"; +import { Payload } from "../../../types/payload"; + // Extracts ensname from raw text. function extractEnsName(text: string) { // Define a regular expression to match ENS names diff --git a/src/handlers/label/index.ts b/src/handlers/label/index.ts index 168a50bbe..6e25c4170 100644 --- a/src/handlers/label/index.ts +++ b/src/handlers/label/index.ts @@ -1,6 +1,7 @@ +import { Context } from "../../types/context"; import Runtime from "../../bindings/bot-runtime"; import { hasLabelEditPermission } from "../../helpers"; -import { Context, Payload } from "../../types"; +import { Payload } from "../../types/payload"; export async function watchLabelChange(context: Context) { const logger = context.logger; diff --git a/src/handlers/pricing/action.ts b/src/handlers/pricing/action.ts index 69978695a..f5ba94074 100644 --- a/src/handlers/pricing/action.ts +++ b/src/handlers/pricing/action.ts @@ -1,5 +1,6 @@ +import { Context } from "../../types/context"; import { calculateLabelValue, clearAllPriceLabelsOnIssue } from "../../helpers"; -import { Label, Context } from "../../types"; +import { Label } from "../../types/label"; export async function handleParentIssue(context: Context, labels: Label[]) { const issuePrices = labels.filter((label) => label.name.toString().startsWith("Price:")); diff --git a/src/handlers/pricing/pre.ts b/src/handlers/pricing/pre.ts index f91850214..3b7ae0e99 100644 --- a/src/handlers/pricing/pre.ts +++ b/src/handlers/pricing/pre.ts @@ -1,5 +1,6 @@ +import { Context } from "../../types/context"; import { calculateLabelValue, createLabel, listLabelsForRepo } from "../../helpers"; -import { Context } from "../../types"; + import { calculateTaskPrice } from "../shared/pricing"; // This just checks all the labels in the config have been set in gh issue diff --git a/src/handlers/pricing/pricing-label.ts b/src/handlers/pricing/pricing-label.ts index 026f96ad9..ebf7c47b3 100644 --- a/src/handlers/pricing/pricing-label.ts +++ b/src/handlers/pricing/pricing-label.ts @@ -1,8 +1,12 @@ +import { Context } from "../../types/context"; import { addLabelToIssue, clearAllPriceLabelsOnIssue, createLabel, getAllLabeledEvents } from "../../helpers"; -import { BotConfig, Context, Label, Payload, UserType } from "../../types"; + import { labelAccessPermissionsCheck } from "../access"; import { setPrice } from "../shared/pricing"; import { handleParentIssue, isParentIssue, sortLabelsByValue } from "./action"; +import { Payload, UserType } from "../../types/payload"; +import { Label } from "../../types/label"; +import { BotConfig } from "../../types/configuration-types"; export async function onLabelChangeSetPricing(context: Context): Promise { const config = context.config; diff --git a/src/handlers/processors.ts b/src/handlers/processors.ts index 411276423..dc71c8034 100644 --- a/src/handlers/processors.ts +++ b/src/handlers/processors.ts @@ -1,16 +1,17 @@ -import { GitHubEvent, Handler, WildCardHandler } from "../types"; import { closePullRequestForAnIssue, startCommandHandler } from "./assign"; import { syncPriceLabelsToConfig } from "./pricing"; import { checkTasksToUnassign } from "./wildcard"; +import Runtime from "../bindings/bot-runtime"; import { checkPullRequests } from "./assign/auto"; import { commentCreatedOrEdited } from "./comment/action"; import { issueClosed } from "./comment/handlers/issue/issue-closed"; import { watchLabelChange } from "./label"; +import { onLabelChangeSetPricing } from "./pricing/pricing-label"; import { createDevPoolPR } from "./pull-request"; import { checkModifiedBaseRate } from "./push/check-modified-base-rate"; -import { onLabelChangeSetPricing } from "./pricing/pricing-label"; -import Runtime from "../bindings/bot-runtime"; +import { Handler, WildCardHandler } from "../types/handlers"; +import { GitHubEvent } from "../types/payload"; /** * @dev diff --git a/src/handlers/pull-request/create-devpool-pr.ts b/src/handlers/pull-request/create-devpool-pr.ts index a2201857f..197b74fbe 100644 --- a/src/handlers/pull-request/create-devpool-pr.ts +++ b/src/handlers/pull-request/create-devpool-pr.ts @@ -1,4 +1,5 @@ -import { Context, GithubContent, Payload } from "../../types"; +import { Context } from "../../types/context"; +import { Payload, GithubContent } from "../../types/payload"; export async function createDevPoolPR(context: Context) { const logger = context.logger; diff --git a/src/handlers/push/check-modified-base-rate.ts b/src/handlers/push/check-modified-base-rate.ts index c389e660b..ad3264626 100644 --- a/src/handlers/push/check-modified-base-rate.ts +++ b/src/handlers/push/check-modified-base-rate.ts @@ -1,6 +1,7 @@ -import { PushPayload, Context } from "../../types"; +import { Context } from "../../types/context"; +import { PushPayload } from "../../types/payload"; +import { BASE_RATE_FILE, getCommitChanges, ZERO_SHA } from "./index"; import { updateBaseRate } from "./update-base-rate"; -import { ZERO_SHA, getCommitChanges, BASE_RATE_FILE } from "./index"; export async function checkModifiedBaseRate(context: Context) { const logger = context.logger; diff --git a/src/handlers/push/index.ts b/src/handlers/push/index.ts index 30f7ad897..09c59e2e3 100644 --- a/src/handlers/push/index.ts +++ b/src/handlers/push/index.ts @@ -1,9 +1,11 @@ import { Context as ProbotContext } from "probot"; import Runtime from "../../bindings/bot-runtime"; import { createCommitComment, getFileContent } from "../../helpers"; -import { BotConfig, CommitsPayload, PushPayload, validateBotConfig } from "../../types"; -import { parseYaml, transformConfig } from "../../utils/generate-configuration"; + import { DefinedError } from "ajv"; +import { parseYaml, transformConfig } from "../../utils/generate-configuration"; +import { validateBotConfig, BotConfig } from "../../types/configuration-types"; +import { CommitsPayload, PushPayload } from "../../types/payload"; export const ZERO_SHA = "0000000000000000000000000000000000000000"; export const BASE_RATE_FILE = ".github/ubiquibot-config.yml"; diff --git a/src/handlers/push/update-base-rate.ts b/src/handlers/push/update-base-rate.ts index a157d70e1..274692a5f 100644 --- a/src/handlers/push/update-base-rate.ts +++ b/src/handlers/push/update-base-rate.ts @@ -1,5 +1,8 @@ import { getPreviousFileContent, listLabelsForRepo, updateLabelsFromBaseRate } from "../../helpers"; -import { Label, PushPayload, Context } from "../../types"; +import { Context } from "../../types/context"; +import { Label } from "../../types/label"; +import { PushPayload } from "../../types/payload"; + import { parseYaml } from "../../utils/generate-configuration"; export async function updateBaseRate(context: Context, filePath: string) { diff --git a/src/handlers/shared/pricing.ts b/src/handlers/shared/pricing.ts index c061bd3d2..ee58c4b67 100644 --- a/src/handlers/shared/pricing.ts +++ b/src/handlers/shared/pricing.ts @@ -1,5 +1,6 @@ import { calculateLabelValue } from "../../helpers"; -import { Label, Context } from "../../types"; +import { Context } from "../../types/context"; +import { Label } from "../../types/label"; export function calculateTaskPrice( context: Context, diff --git a/src/handlers/wildcard/analytics.ts b/src/handlers/wildcard/analytics.ts index 177df86ce..2c30319dc 100644 --- a/src/handlers/wildcard/analytics.ts +++ b/src/handlers/wildcard/analytics.ts @@ -1,5 +1,6 @@ import { calculateLabelValue } from "../../helpers"; -import { Issue, Context } from "../../types"; +import { Context } from "../../types/context"; +import { Issue } from "../../types/payload"; // Checks the issue whether it's an open task for public self assignment export function taskPaymentMetaData( diff --git a/src/handlers/wildcard/unassign/unassign.ts b/src/handlers/wildcard/unassign/unassign.ts index 80e72a18e..d36251857 100644 --- a/src/handlers/wildcard/unassign/unassign.ts +++ b/src/handlers/wildcard/unassign/unassign.ts @@ -1,7 +1,10 @@ import { RestEndpointMethodTypes } from "@octokit/rest"; import { listAllIssuesAndPullsForRepo } from "../../../helpers"; import { getLinkedPullRequests } from "../../../helpers/parser"; -import { Commit, Context, Issue, IssueType, Payload, User } from "../../../types"; +import { Commit } from "../../../types/commit"; +import { Context } from "../../../types/context"; +import { Issue, IssueType, Payload, User } from "../../../types/payload"; +// import { Commit, Context, Issue, IssueType, Payload, User } from "../../../types"; type IssuesListEventsResponseData = RestEndpointMethodTypes["issues"]["listEvents"]["response"]["data"]; // type Commit[] = Commit[]; // RestEndpointMethodTypes["pulls"]["listCommits"]["response"]["data"]; @@ -356,8 +359,8 @@ async function getAllCommitsFromPullRequest({ context, owner, repo, pullNumber } return allCommits; } -function isCorrectType(event: IssuesListEventsResponseData): event is IssuesListEventsResponseData { - return event && typeof event.id === "number"; +function isCorrectType(event: any): event is AssignedEventExample { + return event && typeof event.id === "number" && event.event === "assigned"; } interface DisqualifyIdleAssignees { diff --git a/src/helpers/commit.ts b/src/helpers/commit.ts index 3406422ae..9a0958be8 100644 --- a/src/helpers/commit.ts +++ b/src/helpers/commit.ts @@ -1,5 +1,5 @@ -import { Payload } from "../types"; import { Context as ProbotContext } from "probot"; +import { Payload } from "../types/payload"; export async function createCommitComment( context: ProbotContext, diff --git a/src/helpers/file.ts b/src/helpers/file.ts index 4d9a78584..1d3c42915 100644 --- a/src/helpers/file.ts +++ b/src/helpers/file.ts @@ -1,6 +1,7 @@ import Runtime from "../bindings/bot-runtime"; -import { Context } from "../types"; + import { Context as ProbotContext } from "probot"; +import { Context } from "../types/context"; // Get the previous file content export async function getPreviousFileContent( diff --git a/src/helpers/gpt.ts b/src/helpers/gpt.ts index 586e88788..756986711 100644 --- a/src/helpers/gpt.ts +++ b/src/helpers/gpt.ts @@ -1,7 +1,9 @@ import OpenAI from "openai"; import { CreateChatCompletionRequestMessage } from "openai/resources/chat"; import { getAllIssueComments, getAllLinkedIssuesAndPullsInBody } from "../helpers"; -import { Context, Payload, StreamlinedComment, UserType } from "../types"; +import { Context } from "../types/context"; +import { StreamlinedComment } from "../types/openai"; +import { Payload, UserType } from "../types/payload"; export const sysMsg = `You are the UbiquiBot, designed to provide accurate technical answers. \n Whenever appropriate, format your response using GitHub Flavored Markdown. Utilize tables, lists, and code blocks for clear and organized answers. \n diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 288850f37..f37b608b4 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -1,15 +1,11 @@ -import { - AssignEvent, - Comment, - HandlerReturnValuesNoVoid, - Issue, - IssueType, - StreamlinedComment, - UserType, -} from "../types"; -import { checkRateLimitGit } from "../utils"; import { LogReturn } from "../adapters/supabase"; -import { Payload, Context } from "../types"; + +import { Context } from "../types/context"; +import { HandlerReturnValuesNoVoid } from "../types/handlers"; +import { StreamlinedComment } from "../types/openai"; +import { AssignEvent, Issue, IssueType, Payload, UserType } from "../types/payload"; +import { checkRateLimitGit } from "../utils"; +import { Comment } from "../types/payload"; type PromiseType = T extends Promise ? U : never; diff --git a/src/helpers/label.ts b/src/helpers/label.ts index f4f31d2be..2df7f8778 100644 --- a/src/helpers/label.ts +++ b/src/helpers/label.ts @@ -1,7 +1,10 @@ import { labelExists } from "../handlers/pricing/pricing-label"; import { calculateTaskPrice } from "../handlers/shared/pricing"; import { calculateLabelValue } from "../helpers"; -import { Context, Label, Payload } from "../types"; +import { Context } from "../types/context"; +import { Label } from "../types/label"; +import { Payload } from "../types/payload"; + import { deleteLabel } from "./issue"; // cspell:disable diff --git a/src/helpers/parser.ts b/src/helpers/parser.ts index 2f83dfefe..915965968 100644 --- a/src/helpers/parser.ts +++ b/src/helpers/parser.ts @@ -1,7 +1,7 @@ import axios from "axios"; import { HTMLElement, parse } from "node-html-parser"; +import { Context } from "../types/context"; import { getPullByNumber } from "./issue"; -import { Context } from "../types"; interface GetLinkedParams { owner: string; diff --git a/src/helpers/payout.ts b/src/helpers/payout.ts index eb8d008ca..ae5f35767 100644 --- a/src/helpers/payout.ts +++ b/src/helpers/payout.ts @@ -12,7 +12,8 @@ */ import Runtime from "../bindings/bot-runtime"; -import { Context } from "../types"; +import { Context } from "../types/context"; + import { isUserAdminOrBillingManager } from "./issue"; // available tokens for payouts diff --git a/src/helpers/shared.ts b/src/helpers/shared.ts index 4ec9e30ee..54a95175d 100644 --- a/src/helpers/shared.ts +++ b/src/helpers/shared.ts @@ -1,6 +1,8 @@ import ms from "ms"; -import { Label, Payload, UserType } from "../types"; + import { Context as ProbotContext } from "probot"; +import { Label } from "../types/label"; +import { Payload, UserType } from "../types/payload"; const contextNamesToSkip = ["workflow_run"]; diff --git a/src/index.ts b/src/index.ts index 30878e08f..6401a63b1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ sourceMapSupport.install(); import { Probot } from "probot"; import { bindEvents } from "./bindings"; -import { GitHubEvent } from "./types"; +import { GitHubEvent } from "./types/payload"; export default function main(app: Probot) { const allowedEvents = Object.values(GitHubEvent); diff --git a/src/tests/before-all-handler.ts b/src/tests/before-all-handler.ts index 0b7d56ee0..f2301bcd1 100644 --- a/src/tests/before-all-handler.ts +++ b/src/tests/before-all-handler.ts @@ -8,7 +8,6 @@ import { getAdminUsername, getCollaboratorUser, getCollaboratorUsername, - orgConfig, owner, repo, setAdminUser, @@ -17,7 +16,6 @@ import { setCollaboratorUsername, setServer, } from "./commands-test"; -import { repoConfig } from "./test-repo-config"; import { updateConfig, waitForNWebhooks, webhookEventEmitter } from "./utils"; export function beforeAllHandler(): jest.ProvidesHookCallback { @@ -95,7 +93,7 @@ export function beforeAllHandler(): jest.ProvidesHookCallback { await updateConfig({ octokit: getAdminUser(), owner, - repo, + repo: "ubiquibot-config", path: ".github/ubiquibot-config.yml", config: repoConfig, }); diff --git a/src/tests/commands-test.ts b/src/tests/commands-test.ts index 81a700bdf..0662abe15 100644 --- a/src/tests/commands-test.ts +++ b/src/tests/commands-test.ts @@ -3,7 +3,6 @@ import { execSync } from "child_process"; import "dotenv/config"; import { Octokit } from "octokit"; import { Server } from "probot"; -import { Config } from "../types/config"; import { afterAllHandler } from "./after-all-handler"; import { beforeAllHandler } from "./before-all-handler"; import { testSuite } from "./test-suite"; @@ -57,11 +56,6 @@ export function setServer(value: Server) { server = value; } -export const orgConfig: Config = { - privateEncrypted: - "YU-tFJFczN3JPVoJu0pQKSbWoeiCFPjKiTXMoFnJxDDxUNX-BBXc6ZHkcQcHVjdOd6ZcEnU1o2jU3F-i05mGJPmhF2rhQYXkNlxu5U5fZMMcgxJ9INhAmktzRBUxWncg4L1HOalZIoQ7gm3nk1a84g", -}; - export const customOctokit = Octokit.defaults({ throttle: { onRateLimit: () => true, diff --git a/src/tests/test-suite.ts b/src/tests/test-suite.ts index 6da617180..093b67518 100644 --- a/src/tests/test-suite.ts +++ b/src/tests/test-suite.ts @@ -1,5 +1,5 @@ import { expect, test } from "@jest/globals"; -import { Issue } from "../types"; +import { Issue } from "../types/payload"; import { GIT_COMMIT_HASH, owner, diff --git a/src/tests/utils.ts b/src/tests/utils.ts index d11756eb6..1e8eb62fb 100644 --- a/src/tests/utils.ts +++ b/src/tests/utils.ts @@ -3,7 +3,7 @@ import { RequestError } from "@octokit/request-error"; import EventEmitter from "events"; import { Octokit } from "octokit"; import YAML from "yaml"; -import { Config } from "../types"; +import { BotConfig } from "../types/configuration-types"; export const webhookEventEmitter = new EventEmitter(); @@ -169,7 +169,7 @@ interface CreateLabel extends LabelParams { interface UpdateConfig extends OctokitParams { path: string; - config: Config; + config: BotConfig; } interface CreateComment extends IssueParams { diff --git a/src/types/context.ts b/src/types/context.ts index b568ba843..27b4bf4b1 100644 --- a/src/types/context.ts +++ b/src/types/context.ts @@ -1,7 +1,8 @@ import { Context as ProbotContext, ProbotOctokit } from "probot"; -import { BotConfig, Payload } from "./"; import OpenAI from "openai"; import { Logs } from "../adapters/supabase"; +import { BotConfig } from "./configuration-types"; +import { Payload } from "./payload"; export interface Context { event: ProbotContext; diff --git a/src/types/index.ts b/src/types/index.ts deleted file mode 100644 index 2ce11d211..000000000 --- a/src/types/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -export * from "./payload"; -export * from "./label"; -export * from "./handlers"; -export * from "./configuration-types"; -export * from "./markdown"; -export * from "./context"; -export * from "./commit"; -export * from "./openai"; -export * from "./logs"; diff --git a/src/types/logs.ts b/src/types/logs.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/utils/generate-configuration.ts b/src/utils/generate-configuration.ts index f3532aa09..3b05ad06d 100644 --- a/src/utils/generate-configuration.ts +++ b/src/utils/generate-configuration.ts @@ -4,7 +4,8 @@ import mergeWith from "lodash/merge"; import { Context as ProbotContext } from "probot"; import YAML from "yaml"; import Runtime from "../bindings/bot-runtime"; -import { BotConfig, Payload, stringDuration, validateBotConfig } from "../types"; +import { BotConfig, validateBotConfig, stringDuration } from "../types/configuration-types"; +import { Payload } from "../types/payload"; const UBIQUIBOT_CONFIG_REPOSITORY = "ubiquibot-config"; const UBIQUIBOT_CONFIG_FULL_PATH = ".github/ubiquibot-config.yml";