Repository: repobee/repobee

Issue:
Generalize exception.GitHubError to exception.APIError
Such that it makes sense for both GitLab and GitHub. Probably don't need to change any of the internals other than class names.

Comments:

Patch:
diff --git a/repobee/cli.py b/repobee/cli.py
index b63c37b..d54ea61 100644
--- a/repobee/cli.py
+++ b/repobee/cli.py
@@ -760,7 +760,6 @@ def _create_base_parsers():
 
 @contextmanager
 def _sys_exit_on_expected_error():
-    """Expect either git.GitError or github_api.APIError."""
     try:
         yield
     except exception.PushFailedError as exc:
diff --git a/repobee/exception.py b/repobee/exception.py
index 15e6e06..6b1163e 100644
--- a/repobee/exception.py
+++ b/repobee/exception.py
@@ -40,7 +40,7 @@ class FileError(RepoBeeException):
     """Raise when reading or writing to a file errors out."""
 
 
-class GitHubError(RepoBeeException):
+class APIError(RepoBeeException):
     """An exception raised when the API responds with an error code."""
 
     def __init__(self, msg="", status=None):
@@ -48,30 +48,24 @@ class GitHubError(RepoBeeException):
         self.status = status
 
 
-class NotFoundError(GitHubError):
+class NotFoundError(APIError):
     """An exception raised when the API responds with a 404."""
 
 
-class ServiceNotFoundError(GitHubError):
+class ServiceNotFoundError(APIError):
     """Raise if the base url can't be located."""
 
 
-class BadCredentials(GitHubError):
+class BadCredentials(APIError):
     """Raise when credentials are rejected."""
 
 
-class UnexpectedException(GitHubError):
+class UnexpectedException(APIError):
     """An exception raised when an API request raises an unexpected
     exception.
     """
 
 
-class APIError(RepoBeeException):
-    """Raise when something unexpected happens when interacting with the
-    API.
-    """
-
-
 class GitError(RepoBeeException):
     """A generic error to raise when a git command exits with a non-zero exit
     status.
diff --git a/repobee/github_api.py b/repobee/github_api.py
index a1d4585..5089d7e 100644
--- a/repobee/github_api.py
+++ b/repobee/github_api.py
@@ -67,7 +67,7 @@ def _try_api_request(ignore_statuses: Optional[Iterable[int]] = None):
     Raises:
         exception.NotFoundError
         exception.BadCredentials
-        exception.GitHubError
+        exception.APIError
         exception.ServiceNotFoundError
         exception.UnexpectedException
     """
@@ -85,7 +85,7 @@ def _try_api_request(ignore_statuses: Optional[Iterable[int]] = None):
                 status=401,
             )
         else:
-            raise exception.GitHubError(str(e), status=e.status)
+            raise exception.APIError(str(e), status=e.status)
     except gaierror:
         raise exception.ServiceNotFoundError(
             "GitHub service could not be found, check the url"
@@ -191,7 +191,7 @@ class GitHubAPI(apimeta.API):
                 existing_users.append(self._github.get_user(name))
             except github.GithubException as exc:
                 if exc.status != 404:
-                    raise exception.GitHubError(
+                    raise exception.APIError(
                         "Got unexpected response code from the GitHub API",
                         status=exc.status,
                     )


Test patch:
diff --git a/tests/test_github_api.py b/tests/test_github_api.py
index 9976d19..df8729b 100644
--- a/tests/test_github_api.py
+++ b/tests/test_github_api.py
@@ -338,9 +338,9 @@ class TestEnsureTeamsAndMembers:
     @pytest.mark.parametrize(
         "unexpected_exc",
         [
-            exception.GitHubError("", 404),
-            exception.GitHubError("", 400),
-            exception.GitHubError("", 500),
+            exception.APIError("", 404),
+            exception.APIError("", 400),
+            exception.APIError("", 500),
         ],
     )
     def test_raises_on_non_422_exception(
@@ -421,7 +421,7 @@ class TestCreateRepos:
         side_effect_github_exception = [unexpected_exception] + side_effect[1:]
 
         create_repo_mock.side_effect = side_effect_github_exception
-        with pytest.raises(exception.GitHubError):
+        with pytest.raises(exception.APIError):
             api.create_repos(repo_infos)
 
     def test_returns_all_urls(self, mocker, repos, repo_infos, api):