From d339aa5e3e3106348fa17b44fe1ccd93f6c99949 Mon Sep 17 00:00:00 2001 From: Rob Dominguez Date: Mon, 8 Jan 2024 09:30:30 -0600 Subject: [PATCH] remove hasura refs --- __tests__/github.test.ts | 6 +++--- __tests__/openai.test.ts | 6 +++--- dist/github/index.js | 12 ++++++------ dist/index.js | 16 ++++++++-------- src/github/index.ts | 12 ++++++------ src/index.ts | 4 ++-- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/__tests__/github.test.ts b/__tests__/github.test.ts index 08379d1..2bb8fe7 100644 --- a/__tests__/github.test.ts +++ b/__tests__/github.test.ts @@ -34,17 +34,17 @@ describe('GitHub Functionality', () => { }); it('Should be able to return the diff of a PR', async () => { const diffUrl: number = 262; - const diff = await getDiff(diffUrl); + const diff = await getDiff(diffUrl, 'hasura', 'v3-docs'); expect(diff).toContain('diff'); }); it('Should be able to determine which files were changed in a PR', async () => { const diffUrl: number = 262; - const diff = await getDiff(diffUrl); + const diff = await getDiff(diffUrl, 'hasura', 'v3-docs'); const files = getChangedFiles(diff); expect(files).toContain('docs/ci-cd/projects.mdx'); }); it('Should be able to get the contents of a file', async () => { - const contents = await getFileContent(['README.md']); + const contents = await getFileContent(['README.md'], 'hasura', 'v3-docs'); expect(contents).toContain('Website'); }); }); diff --git a/__tests__/openai.test.ts b/__tests__/openai.test.ts index 7069a1e..d8aeade 100644 --- a/__tests__/openai.test.ts +++ b/__tests__/openai.test.ts @@ -6,7 +6,7 @@ describe('OpenAI Functionality', () => { await expect(testConnection()).resolves.toBe(true); }); it('Should be able to generate a prompt using the diff, assertion, and whole file', async () => { - const diff: string = await getDiff(262); + const diff: string = await getDiff(262, 'hasura', 'v3-docs'); const assertion: string = 'The documentation is easy to read and understand.'; const file: string = 'This is a test file.'; const prompt: string = generatePrompt(diff, assertion, file); @@ -22,9 +22,9 @@ describe('OpenAI Functionality', () => { const prNumber: number = 262; const PR = await getSinglePR('hasura', 'v3-docs', prNumber); const assertion = await getAssertion(PR?.body || ''); - const diff: string = await getDiff(prNumber); + const diff: string = await getDiff(prNumber, 'hasura', 'v3-docs'); const changedFiles = getChangedFiles(diff); - const file: any = await getFileContent(changedFiles); + const file: any = await getFileContent(changedFiles, 'hasura', 'v3-docs'); const prompt: string = generatePrompt(diff, assertion, file); const response = await testAssertion(prompt); expect(response).toBeTruthy(); diff --git a/dist/github/index.js b/dist/github/index.js index a22c987..8939cbb 100644 --- a/dist/github/index.js +++ b/dist/github/index.js @@ -100,10 +100,10 @@ const getAssertion = async (description) => { }; exports.getAssertion = getAssertion; // If we have a diff_url we can get the diff -const getDiff = async (prNumber) => { +const getDiff = async (prNumber, owner, repo) => { const { data: diff } = await exports.github.pulls.get({ - owner: 'hasura', - repo: 'v3-docs', + owner, + repo, pull_number: prNumber, mediaType: { format: 'diff', @@ -129,14 +129,14 @@ const getChangedFiles = (diff) => { }; exports.getChangedFiles = getChangedFiles; // We'll also need to get the whole file using the files changed from -async function getFileContent(path) { +async function getFileContent(path, owner, repo) { let content = ''; // loop over the array of files for (let i = 0; i < path.length; i++) { // get the file content const { data } = await exports.github.repos.getContent({ - owner: 'hasura', - repo: 'v3-docs', + owner, + repo, path: path[i], }); // decode the file content diff --git a/dist/index.js b/dist/index.js index 563fe23..64069e5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -107,10 +107,10 @@ const getAssertion = async (description) => { }; exports.getAssertion = getAssertion; // If we have a diff_url we can get the diff -const getDiff = async (prNumber) => { +const getDiff = async (prNumber, owner, repo) => { const { data: diff } = await exports.github.pulls.get({ - owner: 'hasura', - repo: 'v3-docs', + owner, + repo, pull_number: prNumber, mediaType: { format: 'diff', @@ -136,14 +136,14 @@ const getChangedFiles = (diff) => { }; exports.getChangedFiles = getChangedFiles; // We'll also need to get the whole file using the files changed from -async function getFileContent(path) { +async function getFileContent(path, owner, repo) { let content = ''; // loop over the array of files for (let i = 0; i < path.length; i++) { // get the file content const { data } = await exports.github.repos.getContent({ - owner: 'hasura', - repo: 'v3-docs', + owner, + repo, path: path[i], }); // decode the file content @@ -211,9 +211,9 @@ async function main() { return; } else { - const diff = await (0, github_1.getDiff)(prNumber); + const diff = await (0, github_1.getDiff)(prNumber, org, repoName); const changedFiles = (0, github_1.getChangedFiles)(diff); - const file = await (0, github_1.getFileContent)(changedFiles); + const file = await (0, github_1.getFileContent)(changedFiles, org, repoName); const prompt = (0, open_ai_1.generatePrompt)(diff, assertion, file); const rawAnalysis = await (0, open_ai_1.testAssertion)(prompt); const analysis = (0, open_ai_1.writeAnalysis)(rawAnalysis?.toString() ?? ''); diff --git a/src/github/index.ts b/src/github/index.ts index b3794af..d2c6df6 100644 --- a/src/github/index.ts +++ b/src/github/index.ts @@ -82,10 +82,10 @@ export const getAssertion = async (description: string): Promise }; // If we have a diff_url we can get the diff -export const getDiff = async (prNumber: number): Promise => { +export const getDiff = async (prNumber: number, owner: string, repo: string): Promise => { const { data: diff } = await github.pulls.get({ - owner: 'hasura', - repo: 'v3-docs', + owner, + repo, pull_number: prNumber, mediaType: { format: 'diff', @@ -112,14 +112,14 @@ export const getChangedFiles = (diff: string): string[] => { }; // We'll also need to get the whole file using the files changed from -export async function getFileContent(path: string[]) { +export async function getFileContent(path: string[], owner: string, repo: string) { let content: string = ''; // loop over the array of files for (let i = 0; i < path.length; i++) { // get the file content const { data }: any = await github.repos.getContent({ - owner: 'hasura', - repo: 'v3-docs', + owner, + repo, path: path[i], }); // decode the file content diff --git a/src/index.ts b/src/index.ts index e9916d5..020d6a3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,9 +21,9 @@ async function main() { core.setFailed('No assertion found'); return; } else { - const diff: string = await getDiff(prNumber); + const diff: string = await getDiff(prNumber, org, repoName); const changedFiles = getChangedFiles(diff); - const file: any = await getFileContent(changedFiles); + const file: any = await getFileContent(changedFiles, org, repoName); const prompt: string = generatePrompt(diff, assertion, file); const rawAnalysis = await testAssertion(prompt); const analysis = writeAnalysis(rawAnalysis?.toString() ?? '');