Skip to content

Commit

Permalink
fix: compile error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Oct 6, 2024
1 parent 4a4c259 commit 5414acd
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 117 deletions.
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
"open-source"
],
"dependencies": {
"@actions/core": "1.10.1",
"@actions/core": "1.11.1",
"@actions/github": "6.0.0",
"@octokit/graphql-schema": "15.25.0",
"@octokit/plugin-paginate-graphql": "5.2.2",
"@octokit/plugin-retry": "6.0.1",
"@octokit/rest": "20.1.0",
"@octokit/webhooks": "13.2.7",
"@octokit/graphql-schema": "^15.25.0",
"@octokit/plugin-paginate-graphql": "^5.2.3",
"@octokit/plugin-retry": "^7.1.2",
"@octokit/rest": "^21.0.2",
"@octokit/webhooks": "^13.3.0",
"@sinclair/typebox": "0.32.23",
"@supabase/supabase-js": "2.42.0",
"@ubiquibot/permit-generation": "^1.6.0",
Expand All @@ -40,7 +40,7 @@
"decimal.js": "10.4.3",
"dotenv": "16.4.5",
"ethers": "^6.13.0",
"js-tiktoken": "1.0.14",
"js-tiktoken": "1.0.15",
"jsdom": "24.0.0",
"markdown-it": "14.1.0",
"openai": "4.56.0",
Expand All @@ -64,6 +64,7 @@
"@types/node": "20.11.28",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"@vercel/ncc": "0.38.2",
"babel-jest": "29.7.0",
"cspell": "8.3.2",
"eslint": "8.56.0",
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/web3.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RPCHandler, HandlerConstructorConfig } from "@ubiquity-dao/rpc-handler/";
import { RPCHandler, HandlerConstructorConfig } from "@ubiquity-dao/rpc-handler";
import { ethers } from "ethers";

/**
Expand All @@ -12,6 +12,7 @@ export async function getERC20TokenSymbol(networkId: number, tokenAddress: strin

// get fastest RPC
const config: HandlerConstructorConfig = {
// @ts-expect-error expects an enum when imported through ESNext
networkId: networkId,
rpcTimeout: 1500,
autoStorage: false,
Expand All @@ -21,6 +22,7 @@ export async function getERC20TokenSymbol(networkId: number, tokenAddress: strin
const provider = await handler.getFastestRpcProvider();

// fetch token symbol
// @ts-expect-error expects a contract when imported through ESNext
const contract = new ethers.Contract(tokenAddress, abi, provider);
return await contract.symbol();
}
12 changes: 8 additions & 4 deletions src/octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { Octokit } from "@octokit/rest";
import { retry } from "@octokit/plugin-retry";
import program from "./parser/command-line";
import configuration from "./configuration/config-reader";
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
import { paginateGraphQL, paginateGraphQLInterface } from "@octokit/plugin-paginate-graphql";

// @ts-expect-error retry and paginateGraphql do not use latest hook types
// https://github.com/octokit/plugin-retry.js/issues/528
const customOctokit = Octokit.plugin(retry, paginateGraphQL);

let octokitInstance: InstanceType<typeof customOctokit> | null = null;
type OctokitInstanceType = InstanceType<typeof customOctokit> & paginateGraphQLInterface;

let octokitInstance: OctokitInstanceType | null = null;

function getOctokitInstance() {
if (!octokitInstance) {
Expand All @@ -16,9 +20,9 @@ function getOctokitInstance() {
retries: configuration.dataCollection.maxAttempts,
retryAfterBaseValue: configuration.dataCollection.delayMs,
},
});
}) as OctokitInstanceType;
}
return octokitInstance;
return octokitInstance as OctokitInstanceType;
}

export { getOctokitInstance };
10 changes: 5 additions & 5 deletions src/parser/content-evaluator-module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Decimal from "decimal.js";
import { encodingForModel, Tiktoken } from "js-tiktoken";
import OpenAI from "openai";
import configuration from "../configuration/config-reader";
import { OPENAI_API_KEY } from "../configuration/constants";
Expand All @@ -13,12 +12,13 @@ import { Value } from "@sinclair/typebox/value";
import { commentEnum, CommentKind, CommentType } from "../configuration/comment-types";
import logger from "../helpers/logger";
import {
openAiRelevanceResponseSchema,
AllComments,
CommentToEvaluate,
Relevances,
openAiRelevanceResponseSchema,
PrCommentToEvaluate,
AllComments,
Relevances,
} from "../types/content-evaluator-module-type";
import { encodingForModel } from "js-tiktoken";

/**
* Evaluates and rates comments.
Expand Down Expand Up @@ -140,7 +140,7 @@ export class ContentEvaluatorModule implements Module {
* Will try to predict the maximum of tokens expected, to a maximum of totalTokenLimit.
*/
_calculateMaxTokens(prompt: string, totalTokenLimit: number = 16384) {
const tokenizer: Tiktoken = encodingForModel("gpt-4o-2024-08-06");
const tokenizer = encodingForModel("gpt-4o-2024-08-06");
const inputTokens = tokenizer.encode(prompt).length;
return Math.min(inputTokens, totalTokenLimit);
}
Expand Down
28 changes: 0 additions & 28 deletions src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
GitHubPullRequestReviewState,
GitHubRepository,
GitHubTimelineEvent,
GitHubUser,
} from "./github-types";
import { getMinimizedCommentStatus } from "./helpers/get-comment-details";

Expand Down Expand Up @@ -96,33 +95,6 @@ export async function getPullRequestReviewComments(pullParams: PullParams): Prom
return await octokit.paginate(octokit.pulls.listReviewComments.endpoint.merge(pullParams));
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function getAllIssueActivity(issueParams: IssueParams) {
// @DEV: this is very useful for seeing every type of event,
// which includes the issue specification, any events, and all conversation
// that has occurred on the issue in chronological order

const octokit = getOctokitInstance();
const [issue, events, comments] = await Promise.all([
octokit.issues.get(issueParams),
octokit.paginate(octokit.issues.listEvents.endpoint.merge(issueParams)),
octokit.paginate(octokit.issues.listComments.endpoint.merge(issueParams)),
]);

const mixedEventsAndComments = [...events, ...comments];
mixedEventsAndComments.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
// Prepend the issue to the events array
mixedEventsAndComments.unshift(issue.data);
return mixedEventsAndComments;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function getTimelineUsers(issueParams: IssueParams): Promise<GitHubUser[]> {
const timelineEvents = await getAllTimelineEvents(issueParams);
const users = timelineEvents.filter((event) => event.actor).map((event) => event.actor);
return [...new Set(users)];
}

export async function getAllTimelineEvents(issueParams: IssueParams): Promise<GitHubTimelineEvent[]> {
const octokit = getOctokitInstance();
const options = octokit.issues.listEventsForTimeline.endpoint.merge(issueParams);
Expand Down
2 changes: 2 additions & 0 deletions tests/parser/permit-generation-module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const resultOriginal: Result = {
type: CommentKind.ISSUE,
score: {
reward: 10,
multiplier: 1,
},
},
],
Expand All @@ -89,6 +90,7 @@ const resultOriginal: Result = {
type: CommentKind.ISSUE,
score: {
reward: 1.12,
multiplier: 1,
},
},
],
Expand Down
13 changes: 10 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

/* Modules */
"module": "Node16" /* Specify what module code is generated. */,
"module": "ESNext" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */,
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
"paths": {
"@ubiquibot/permit-generation/core": [
"node_modules/@ubiquibot/permit-generation/dist/core/index.d.ts"

Check failure on line 34 in tsconfig.json

View workflow job for this annotation

GitHub Actions / Update Configuration in manifest.json

Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?
],
"@ubiquibot/permit-generation/utils": [
"node_modules/@ubiquibot/permit-generation/dist/utils/index.d.ts"

Check failure on line 37 in tsconfig.json

View workflow job for this annotation

GitHub Actions / Update Configuration in manifest.json

Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?
]
}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
Expand Down
Loading

0 comments on commit 5414acd

Please sign in to comment.