diff --git a/src/review_bot/open_ai_interface.py b/src/review_bot/open_ai_interface.py index 0682abc9..45a067f3 100644 --- a/src/review_bot/open_ai_interface.py +++ b/src/review_bot/open_ai_interface.py @@ -15,7 +15,9 @@ OPEN_AI_MODEL = "gpt-4" -def review_patch(owner, repo, pr, use_src=False, filter_filename=None): +def review_patch( + owner, repo, pr, use_src=False, filter_filename=None, gh_access_token=None +): """Review a patch in a pull request and generate suggestions for improvement. Parameters @@ -31,6 +33,9 @@ def review_patch(owner, repo, pr, use_src=False, filter_filename=None): not for large ones. filter_filename : str, optional If set, filters out all but the file matching this string. + gh_access_token : str, optional + GitHub token needed to communicate with the repository. By default, ``None``, + which means it will try to read an existing env variable named ``GITHUB_TOKEN``. Returns ------- @@ -38,7 +43,9 @@ def review_patch(owner, repo, pr, use_src=False, filter_filename=None): A dictionary containing suggestions for the reviewed patch. """ # Fetch changed files and contents - changed_files = get_changed_files_and_contents(owner, repo, pr) + changed_files = get_changed_files_and_contents( + owner, repo, pr, gh_access_token=gh_access_token + ) # assemble suggestions suggestions = [] diff --git a/tests/test_gh_interface.py b/tests/test_gh_interface.py index e373dc4b..0a4acf77 100644 --- a/tests/test_gh_interface.py +++ b/tests/test_gh_interface.py @@ -5,6 +5,7 @@ > Make this a pytest compatible test, and make it just a function test, do not make it a class. """ +import os import pytest @@ -28,6 +29,20 @@ def test_get_changed_files_and_contents(): assert "file_text" in files[0] +def test_get_changed_files_and_contents_with_input_token(): + pull_number = 4 + + access_token = os.environ.get("GITHUB_TOKEN") + files = get_changed_files_and_contents(OWNER, REPO, pull_number, access_token) + + assert isinstance(files, list) + assert len(files) > 0 + assert isinstance(files[0], dict) + assert "filename" in files[0] + assert "status" in files[0] + assert "file_text" in files[0] + + def test_get_changed_files_and_contents_raises_runtime_error(): pull_number = 999999 # this is an issue