Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the description if the author hasn't added an assertion #3

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ export const getSinglePR = async (
}
};


// If we can get a PR, we can parse the description and try to isolate the description
export const getDescription = (description: string): string | null => {
// find everything after ## Description and before the next ## heading
const regexDescription = /(?<=## Description)(.*?)(?=##|$)/gm
const regexBetweenComments = /(?<=-->)(.*?)(?=<!--)/gm
const descriptionWithComments = regexDescription.exec(description);
if (descriptionWithComments) {
const DescriptionActual = regexBetweenComments.exec(descriptionWithComments[1]);
if (DescriptionActual) {
console.log(`✅ Got actual description: ${DescriptionActual[1]}`);
return DescriptionActual[1];
}
}
return null;
};


// If we can get a PR, we can parse the description and isolate the assertion using the comments
export const getAssertion = async (description: string): Promise<string | null> => {
// find everything in between <!-- DX:Assertion-start --> and <!-- DX:Assertion-end -->
Expand Down
33 changes: 18 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dotenv from 'dotenv';
import * as core from '@actions/core';
import { getSinglePR, getAssertion, getDiff, getChangedFiles, getFileContent } from './github';
import { getSinglePR, getAssertion, getDiff, getChangedFiles, getFileContent, getDescription } from './github';
import { generatePrompt, testAssertion, writeAnalysis, openAiFeedback } from './open_ai';

dotenv.config();
Expand All @@ -16,20 +16,23 @@ const repoName = repo.split('/')[1];
async function main() {
const PR = await getSinglePR(org, repoName, prNumber);
const assertion = await getAssertion(PR?.body ?? '');
if (assertion?.length === 0 || assertion === null) {
console.log('No assertion found');
core.setFailed('No assertion found');
return;
} else {
const diff: string = await getDiff(prNumber, org, repoName);
const changedFiles = getChangedFiles(diff);
const file: any = await getFileContent(changedFiles, org, repoName);
const prompt: string = generatePrompt(diff, assertion, file);
const rawAnalysis = await testAssertion(prompt);
const analysis = writeAnalysis(rawAnalysis);
console.log(analysis);
core.setOutput('analysis', analysis);
return analysis;
if (!assertion) {
const description = getDescription(PR?.body ?? '');
if (!description) {
console.log('No assertion or description found');
core.setFailed('No assertion or description found');
return;
} else {
const diff: string = await getDiff(prNumber, org, repoName);
const changedFiles = getChangedFiles(diff);
const file: any = await getFileContent(changedFiles, org, repoName);
const prompt: string = generatePrompt(diff, assertion, file);
const rawAnalysis = await testAssertion(prompt);
const analysis = writeAnalysis(rawAnalysis);
console.log(analysis);
core.setOutput('analysis', analysis);
return analysis;
}
}
}

Expand Down