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

FEAT: exposing access to GH token input #18

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions src/review_bot/open_ai_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,14 +33,19 @@ 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
-------
list[dict]
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 = []
Expand Down
15 changes: 15 additions & 0 deletions tests/test_gh_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down