From 48ea9d9f99b1ea3e99c69d3fd284eda139aa85b9 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Thu, 31 Oct 2024 17:40:49 +0900 Subject: [PATCH 1/2] fix: update octokit method calls to use the rest API Migrated to octokit.rest for users, repos, and issues methods. --- src/generate-permits-from-context.ts | 4 ++-- src/handlers/generate-erc20-permit.ts | 2 +- src/handlers/generate-erc721-permit.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/generate-permits-from-context.ts b/src/generate-permits-from-context.ts index b4918ff..58571e3 100644 --- a/src/generate-permits-from-context.ts +++ b/src/generate-permits-from-context.ts @@ -71,7 +71,7 @@ export async function generatePermitsFromContext() { async function returnDataToKernel(repoToken: string, stateId: string, output: object) { const octokit = new Octokit({ auth: repoToken }); - await octokit.repos.createDispatchEvent({ + await octokit.rest.repos.createDispatchEvent({ owner: github.context.repo.owner, repo: github.context.repo.repo, event_type: "return_data_to_ubiquibot_kernel", @@ -93,7 +93,7 @@ async function handleSlashCommands(context: Context, octokit: Octokit) { const address = matches[0]; // try registering wallet, if it fails, notify the user if (!(await registerWallet(context, address))) { - await octokit.issues.createComment({ + await octokit.rest.issues.createComment({ owner: github.context.repo.owner, repo: github.context.repo.repo, issue_number: payload.issue.number, diff --git a/src/handlers/generate-erc20-permit.ts b/src/handlers/generate-erc20-permit.ts index 35f1e1d..1936286 100644 --- a/src/handlers/generate-erc20-permit.ts +++ b/src/handlers/generate-erc20-permit.ts @@ -41,7 +41,7 @@ export async function generateErc20PermitSignature( const config = contextOrPayload.config; logger = contextOrPayload.logger; const { evmNetworkId: configEvmNetworkId, evmPrivateEncrypted: configEvmPrivateEncrypted } = config; - const { data: userData } = await contextOrPayload.octokit.users.getByUsername({ username: _username }); + const { data: userData } = await contextOrPayload.octokit.rest.users.getByUsername({ username: _username }); if (!userData) { throw new Error(`GitHub user was not found for id ${_username}`); } diff --git a/src/handlers/generate-erc721-permit.ts b/src/handlers/generate-erc721-permit.ts index 39ebced..35e07a9 100644 --- a/src/handlers/generate-erc721-permit.ts +++ b/src/handlers/generate-erc721-permit.ts @@ -82,7 +82,7 @@ export async function generateErc721PermitSignature( } _organizationName = contextOrPermitPayload.payload.repository.owner.login; _repositoryName = contextOrPermitPayload.payload.repository.name; - const { data: userData } = await contextOrPermitPayload.octokit.users.getByUsername({ username: _username }); + const { data: userData } = await contextOrPermitPayload.octokit.rest.users.getByUsername({ username: _username }); if (!userData) { throw new Error(`GitHub user was not found for id ${_username}`); } From f528113af1df5b38cc865ff2dd25eedaee3f2c5d Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Thu, 31 Oct 2024 17:45:15 +0900 Subject: [PATCH 2/2] chore: update user context structure in tests Switch `users` to `rest.users` in ERC721 and ERC20 tests. --- tests/generate-erc20-permit.test.ts | 25 +++++++++++++------------ tests/generate-erc721-permit.test.ts | 6 ++++-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/generate-erc20-permit.test.ts b/tests/generate-erc20-permit.test.ts index a18f82d..b55c48c 100644 --- a/tests/generate-erc20-permit.test.ts +++ b/tests/generate-erc20-permit.test.ts @@ -54,8 +54,10 @@ describe("generateErc20PermitSignature", () => { request() { return { data: { id: 1, login: "123" } }; }, - users: { - getByUsername: jest.fn().mockReturnValue({ data: { id: 123 } }), + rest: { + users: { + getByUsername: jest.fn().mockReturnValue({ data: { id: 123 } }), + }, }, }, } as unknown as Context; @@ -69,20 +71,19 @@ describe("generateErc20PermitSignature", () => { const result = await generateErc20PermitSignature(context, SPENDER, amount, ERC20_REWARD_TOKEN_ADDRESS); const expectedResult = { - tokenType: 'ERC20', - tokenAddress: '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', - beneficiary: '0xefC0e701A824943b469a694aC564Aa1efF7Ab7dd', - nonce: '28290789875493039658039458533958603742651083423638415458747066904844975862062', - deadline: '115792089237316195423570985008687907853269984665640564039457584007913129639935', - amount: '100000000000000000000', - owner: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', - signature: '0xad87653fb0ecf740c73b78a8f414cdd5b1ffb18670cde5a1d21c65e43d6bb2a36c5470c5529334dc11566f0c380889b734a8539d69ec74cc2abf37af0ea7a7781b', - networkId: 100 + tokenType: "ERC20", + tokenAddress: "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d", + beneficiary: "0xefC0e701A824943b469a694aC564Aa1efF7Ab7dd", + nonce: "28290789875493039658039458533958603742651083423638415458747066904844975862062", + deadline: "115792089237316195423570985008687907853269984665640564039457584007913129639935", + amount: "100000000000000000000", + owner: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + signature: "0xad87653fb0ecf740c73b78a8f414cdd5b1ffb18670cde5a1d21c65e43d6bb2a36c5470c5529334dc11566f0c380889b734a8539d69ec74cc2abf37af0ea7a7781b", + networkId: 100, }; expect(result).toEqual(expectedResult); expect(context.logger.info).toHaveBeenCalledWith("Generated ERC20 permit2 signature", expect.any(Object)); - }); it("should throw error when evmPrivateEncrypted is not defined", async () => { diff --git a/tests/generate-erc721-permit.test.ts b/tests/generate-erc721-permit.test.ts index b65da8c..07c65ea 100644 --- a/tests/generate-erc721-permit.test.ts +++ b/tests/generate-erc721-permit.test.ts @@ -42,8 +42,10 @@ describe("generateErc721PermitSignature", () => { request() { return { data: { id: 1, login: "123" } }; }, - users: { - getByUsername: jest.fn().mockReturnValue({ data: { id: userId } }), + rest: { + users: { + getByUsername: jest.fn().mockReturnValue({ data: { id: userId } }), + }, }, }, } as unknown as Context;