diff --git a/snapshot_manager/snapshot_manager/github_util.py b/snapshot_manager/snapshot_manager/github_util.py index f054f6a9..c34a4e39 100644 --- a/snapshot_manager/snapshot_manager/github_util.py +++ b/snapshot_manager/snapshot_manager/github_util.py @@ -38,6 +38,10 @@ class Reaction(enum.StrEnum): EYES = "EYES" # Represents the :eyes: emoji. +class MissingToken(Exception): + """Could not retrieve a Github token.""" + + class GithubClient: dirname = pathlib.Path(os.path.dirname(__file__)) @@ -52,6 +56,10 @@ def __init__(self, config: config.Config, github_token: str = None, **kwargs): f"Reading Github token from this environment variable: {self.config.github_token_env}" ) github_token = os.getenv(self.config.github_token_env) + if github_token is None or len(github_token) == 0: + # We can't proceed without a Github token, otherwise we'll trigger + # an assertion failure. + raise MissingToken("Could not retrieve the token") auth = github.Auth.Token(github_token) self.github = github.Github(auth=auth) self.gql = github_graphql.GithubGraphQL(token=github_token, raise_on_error=True) diff --git a/snapshot_manager/tests/github_util_test.py b/snapshot_manager/tests/github_util_test.py index d8f212fa..749d110d 100644 --- a/snapshot_manager/tests/github_util_test.py +++ b/snapshot_manager/tests/github_util_test.py @@ -48,7 +48,13 @@ def test_get_todays_issue(self): cfg = self.config cfg.datetime = datetime.datetime(year=2024, month=2, day=27) self.assertEqual("20240227", cfg.yyyymmdd) - gh = github_util.GithubClient(config=cfg) + + try: + gh = github_util.GithubClient(config=cfg) + except github_util.MissingToken: + pytest.skip( + "Skip test because this execution doesn't have access to a Github token" + ) issue = gh.get_todays_github_issue( strategy="big-merge", github_repo="fedora-llvm-team/llvm-snapshots" @@ -104,7 +110,13 @@ def test_flip_test_label(self): pass def test_get_workflow(self): - gh = github_util.GithubClient(config=self.config) + try: + gh = github_util.GithubClient(config=self.config) + except github_util.MissingToken: + pytest.skip( + "Skip test because this execution doesn't have access to a Github token" + ) + repo = gh.github.get_repo("fedora-llvm-team/llvm-snapshots") workflow = repo.get_workflow("check-snapshots.yml") self.assertIsNotNone(workflow) diff --git a/snapshot_manager/tests/testing_farm_util_test.py b/snapshot_manager/tests/testing_farm_util_test.py index c9067608..5cbd1f41 100644 --- a/snapshot_manager/tests/testing_farm_util_test.py +++ b/snapshot_manager/tests/testing_farm_util_test.py @@ -2,6 +2,7 @@ import datetime +import pytest import tests.base_test as base_test import snapshot_manager.github_util as github_util @@ -13,7 +14,13 @@ def test_make_with_missing_compose(self): cfg = self.config cfg.datetime = datetime.datetime(year=2024, month=2, day=27) self.assertEqual("20240227", cfg.yyyymmdd) - gh = github_util.GithubClient(config=cfg) + + try: + gh = github_util.GithubClient(config=cfg) + except github_util.MissingToken: + pytest.skip( + "Skip test because this execution doesn't have access to a Github token" + ) issue = gh.get_todays_github_issue( strategy="big-merge", github_repo="fedora-llvm-team/llvm-snapshots"