Skip to content

Commit

Permalink
remove hasura refs
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjdominguez committed Jan 8, 2024
1 parent bbbc261 commit d339aa5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
6 changes: 3 additions & 3 deletions __tests__/openai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions dist/github/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -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() ?? '');
Expand Down
12 changes: 6 additions & 6 deletions src/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ export const getAssertion = async (description: string): Promise<string | null>
};

// If we have a diff_url we can get the diff
export const getDiff = async (prNumber: number): Promise<string> => {
export const getDiff = async (prNumber: number, owner: string, repo: string): Promise<string> => {
const { data: diff } = await github.pulls.get({
owner: 'hasura',
repo: 'v3-docs',
owner,
repo,
pull_number: prNumber,
mediaType: {
format: 'diff',
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() ?? '');
Expand Down

0 comments on commit d339aa5

Please sign in to comment.