diff --git a/src/pull_request_handler.py b/src/pull_request_handler.py index 06eee3c..9031759 100644 --- a/src/pull_request_handler.py +++ b/src/pull_request_handler.py @@ -1,4 +1,5 @@ import logging + import ollama from config import OLLAMA_MODEL @@ -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=[ diff --git a/src/webhook_handler.py b/src/webhook_handler.py index 687ee73..414b692 100644 --- a/src/webhook_handler.py +++ b/src/webhook_handler.py @@ -2,6 +2,7 @@ import hmac import logging +import requests from flask import Blueprint, request, jsonify, abort from config import WEBHOOK_SECRET @@ -125,6 +126,8 @@ 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, @@ -132,4 +135,5 @@ def handle_pull_requests(data, installation_id): pull_request["number"], pull_request.get("title", ""), pull_request.get("body", ""), + pr_diff, )