Skip to content

Commit

Permalink
Merge pull request #21 from ghinks/bug/unit-test-gh-token
Browse files Browse the repository at this point in the history
bug fix gh token
  • Loading branch information
ghinks authored Dec 23, 2024
2 parents 9cc4975 + 3c89289 commit 09463f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pr_reviews/queries/get_repos_gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
from pr_reviews.queries import TIMEOUT
from pr_reviews.queries.local_exceptions import GitHubTokenNotDefinedError

GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")

# exceptions.py


def get_repos_by_language(org: str, languages: list[str]) -> list[str]:
# check for github_token and raise an exception if it
# is not defined
if GITHUB_TOKEN is None:

github_token = os.getenv("GITHUB_TOKEN")

if github_token is None:
raise GitHubTokenNotDefinedError
url = "https://api.github.com/graphql"
headers = {
"Authorization": f"Bearer {GITHUB_TOKEN}",
"Authorization": f"Bearer {github_token}",
"Content-Type": "application/json",
}
query = """
Expand Down
2 changes: 2 additions & 0 deletions tests/test_get_repos_gql.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import unittest
from unittest.mock import Mock, patch

Expand All @@ -6,6 +7,7 @@

class TestGetReposByLanguage(unittest.TestCase):
@patch("pr_reviews.queries.get_repos_gql.requests.post")
@patch.dict(os.environ, {"GITHUB_TOKEN": "test_token"})
def test_get_repos_by_language(self, mock_post) -> None: # noqa: ANN001
# Mock the response from the GitHub API
mock_response = Mock()
Expand Down

0 comments on commit 09463f8

Please sign in to comment.