Skip to content

Commit

Permalink
Merge pull request #50 from dannyl1u/feat/improve-PR-feedback
Browse files Browse the repository at this point in the history
Feat/improve pr feedback using code diff
  • Loading branch information
dannyl1u authored Nov 10, 2024
2 parents 34be6a9 + 36afdd4 commit 80484b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/pull_request_handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging

import ollama

from config import OLLAMA_MODEL
Expand All @@ -13,15 +14,18 @@ def handle_new_pull_request(
pull_request_number,
pull_request_title,
pull_request_body,
pr_diff,
):
context = "I am programming and I plan to merge in a pull request.\
Given the title and description of my pull request, succinctly identify any potential issues or downsides. \
End your response by asking if the PR author has considered these points"

prompt = (
f"{context} \n Title: {pull_request_title} \n Description: {pull_request_body}"
context = (
"I am programming and I plan to merge in a pull request.\ Given the title, description, and pull rquest "
"code diff "
"of my pull request, succinctly identify any potential issues or downsides. Remember that in the code "
"diff, '+' is a code addition and '-' is code subtraction. \ End your response by asking if the PR "
"author has considered these points "
)

prompt = f'{context} \n Title: {pull_request_title} \n Description: {pull_request_body} \n Code diff: \n """\n {pr_diff} \n """\n '

response = ollama.chat(
model=OLLAMA_MODEL,
messages=[
Expand Down
4 changes: 4 additions & 0 deletions src/webhook_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import hmac
import logging

import requests
from flask import Blueprint, request, jsonify, abort

from config import WEBHOOK_SECRET
Expand Down Expand Up @@ -125,11 +126,14 @@ def handle_pull_requests(data, installation_id):
if not repo_full_name:
abort(400, "Repository full name is missing")

pr_diff = requests.get(pull_request["diff_url"]).text

if action == "opened":
handle_new_pull_request(
installation_id,
repo_full_name,
pull_request["number"],
pull_request.get("title", ""),
pull_request.get("body", ""),
pr_diff,
)

0 comments on commit 80484b6

Please sign in to comment.