Skip to content

Commit

Permalink
Gracefully handle errors fetching GitHub data ARCHBOM-1310 (#28)
Browse files Browse the repository at this point in the history
We're hitting GitHub internal errors trying to fetch data from the edx-blog repository. I've submitted a ticket to GitHub, but we should handle such cases gracefully without causing the entire health check to fail.
  • Loading branch information
jmbowman authored Jul 21, 2020
1 parent 4d718b5 commit b37ca9f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Unreleased

*

[1.1.1] - 2020-07-21
~~~~~~~~~~~~~~~~~~~~

Fixed
_____

* Gracefully handle errors in fetching data from GitHub

[1.1.0] - 2020-07-16
~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion pytest_repo_health/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""


__version__ = "1.1.0"
__version__ = "1.1.1"


def health_metadata(parent_path, output_keys):
Expand Down
13 changes: 9 additions & 4 deletions pytest_repo_health/fixtures/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import os
import re

import github
import pytest
from github import GitHub
from github.errors import GitHubError

URL_PATTERN = r"github.com[/:](?P<org_name>[^/]+)/(?P<repo_name>[^/\.]+)"

Expand All @@ -21,15 +22,16 @@ def github_client():
except KeyError:
raise Exception("To use any of the GitHub fixtures, you must set the GITHUB_TOKEN environment variable "
"to contain a GitHub personal access token.")
return github.GitHub(token)
return GitHub(token)


@pytest.fixture
async def github_repo(git_origin_url, github_client, loop): # pylint: disable=redefined-outer-name, unused-argument
"""
A fixture to fetch information from the GitHub API about the examined repository.
Because github.py uses aiohttp, any checks using this fixture must be declared
via ``async def``.
via ``async def``. Returns ``None`` if there is an error fetching data from
GitHub (such as a network failure or GitHub internal error).
"""
if git_origin_url is None:
# There isn't an origin for this repository or directory
Expand All @@ -40,4 +42,7 @@ async def github_repo(git_origin_url, github_client, loop): # pylint: disable=r
return None
org_name = match.group("org_name")
repo_name = match.group("repo_name")
return await github_client.fetch_repository(org_name, repo_name)
try:
return await github_client.fetch_repository(org_name, repo_name)
except GitHubError:
return None

0 comments on commit b37ca9f

Please sign in to comment.