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.

Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/repobee/repobee/pull/202?src=pr&el=h1) Report
> Merging [#202](https://codecov.io/gh/repobee/repobee/pull/202?src=pr&el=desc) into [master](https://codecov.io/gh/repobee/repobee/commit/aa6378f691bd96d39bb4f8d307368654a0e065fe?src=pr&el=desc) will **decrease** coverage by `0.17%`.
> The diff coverage is `85.71%`.

[![Impacted file tree graph](https://codecov.io/gh/repobee/repobee/pull/202/graphs/tree.svg?width=650&token=5vOKgkphZe&height=150&src=pr)](https://codecov.io/gh/repobee/repobee/pull/202?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #202      +/-   ##
==========================================
- Coverage   92.89%   92.72%   -0.18%     
==========================================
  Files          18       18              
  Lines        1183     1182       -1     
  Branches      203      203              
==========================================
- Hits         1099     1096       -3     
- Misses         68       70       +2     
  Partials       16       16
```


| [Impacted Files](https://codecov.io/gh/repobee/repobee/pull/202?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [repobee/cli.py](https://codecov.io/gh/repobee/repobee/pull/202/diff?src=pr&el=tree#diff-cmVwb2JlZS9jbGkucHk=) | `97.4% <ø> (-0.87%)` | :arrow_down: |
| [repobee/exception.py](https://codecov.io/gh/repobee/repobee/pull/202/diff?src=pr&el=tree#diff-cmVwb2JlZS9leGNlcHRpb24ucHk=) | `100% <100%> (ø)` | :arrow_up: |
| [repobee/github\_api.py](https://codecov.io/gh/repobee/repobee/pull/202/diff?src=pr&el=tree#diff-cmVwb2JlZS9naXRodWJfYXBpLnB5) | `92.4% <50%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/repobee/repobee/pull/202?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/repobee/repobee/pull/202?src=pr&el=footer). Last update [aa6378f...2674993](https://codecov.io/gh/repobee/repobee/pull/202?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-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):