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

Validation of pull requests using OpenAI #310

Merged
merged 10 commits into from
Feb 4, 2024
Merged

Conversation

SleekMutt
Copy link
Contributor

There has been created a service that validates PR with the help of OpenAi. After the validation there will be a review left based on the AI response and user will be notified as there are results. Notification logic will be added after it is merged.

The task

for (GHPullRequestCommitDetail commitDetail :
pullRequest.listCommits().toList()
.stream().filter(commit -> !commit.getCommit()
.getAuthor().getName().equals("github-classroom[bot]"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract please those huge parts of code to separate variables, and format the identation to make it bit more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted lists to separate variables

throw new RuntimeException(e);
}
} catch (JsonProcessingException exception) {
requests.add(process);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add explanation, why we are doing this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added explanation to the Javadoc

GHRepository repository;
try {
repository = getGitHubConnection().getRepository(nameRepository);
repository = getGitHubConnection().getRepository(repositoryName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try placing return statement here, so there is no need in repository variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed variable to return repository on the spot

.stream().filter(Objects::nonNull).collect(Collectors.toList())) {
fileList.add(new CommitFileDto(file.getFileName(), file.getPatch()));
}
String prompt = "Provide me with the code review where you point out lines of code "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract prompt to static final field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted to the prompt template variable

+ "The code will be provided in JSON format as "
+ "[{filename: ${filename}, code: ${code}}]. Ignore git patch headers. "
+ "The code to rate is:"
+ objectMapper.writeValueAsString(fileList)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This you can replace with %s, then, when using prompt, use String.format()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used String.format() instead

…template variable. To create prompt used string format instead. Removed repository variable in the getGitHubRepositoryByName method to return it on the spot.
@SleekMutt SleekMutt requested a review from rainett January 24, 2024 11:14
…dded explanation of JsonProcessingException to the Javadoc
@SleekMutt SleekMutt requested a review from lez-doit January 24, 2024 11:32
public void validatePullRequest(String repositoryName) {
GHRepository repository = gitService.getGitHubRepositoryByName(repositoryName);
try {
GHPullRequest pullRequest = repository.getPullRequest(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how should it work if we have 2 PR's opened?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is supposed that we validate Feedback PR that's generated in the classroom
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we look for some specific PR or it always on the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we generate feedback PR with classroom repository it always will be by id 1

@SleekMutt SleekMutt merged commit 6710c5e into master Feb 4, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants