Repository: repobee/repobee

Issue:
Adapt github_api.GitHubAPI to make use of the apimeta.API class

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

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

```diff
@@            Coverage Diff             @@
##           master     #201      +/-   ##
==========================================
- Coverage   92.89%   92.73%   -0.17%     
==========================================
  Files          18       18              
  Lines        1182     1183       +1     
  Branches      203      203              
==========================================
- Hits         1098     1097       -1     
- Misses         68       70       +2     
  Partials       16       16
```


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

------

[Continue to review full report at Codecov](https://codecov.io/gh/repobee/repobee/pull/201?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/201?src=pr&el=footer). Last update [771ab4e...c1c9346](https://codecov.io/gh/repobee/repobee/pull/201?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/repobee/github_api.py b/repobee/github_api.py
index 5a698af..a1d4585 100644
--- a/repobee/github_api.py
+++ b/repobee/github_api.py
@@ -21,6 +21,7 @@ import github
 from repobee import exception
 from repobee import tuples
 from repobee import util
+from repobee import apimeta
 
 REQUIRED_OAUTH_SCOPES = {"admin:org", "repo"}
 
@@ -95,7 +96,7 @@ def _try_api_request(ignore_statuses: Optional[Iterable[int]] = None):
         )
 
 
-class GitHubAPI:
+class GitHubAPI(apimeta.API):
     """A highly specialized GitHub API class for repobee. The API is
     affiliated both with an organization, and with the whole GitHub
     instance. Almost all operations take place on the target
@@ -136,7 +137,7 @@ class GitHubAPI:
     def token(self):
         return self._token
 
-    def get_teams_in(
+    def _get_teams_in(
         self, team_names: Iterable[str]
     ) -> Generator[github.Team.Team, None, None]:
         """Get all teams that match any team name in the team_names iterable.
@@ -163,7 +164,7 @@ class GitHubAPI:
             team_names: A list of team names for teams to be deleted.
         """
         deleted = set()  # only for logging
-        for team in self.get_teams_in(team_names):
+        for team in self._get_teams_in(team_names):
             team.delete()
             deleted.add(team.name)
             LOGGER.info("deleted team {}".format(team.name))
@@ -220,7 +221,7 @@ class GitHubAPI:
         for team in [team for team in teams if member_lists[team.name]]:
             self._ensure_members_in_team(team, member_lists[team.name])
 
-        return list(self.get_teams_in(set(member_lists.keys())))
+        return list(self._get_teams_in(set(member_lists.keys())))
 
     def _ensure_teams_exist(
         self, team_names: Iterable[str], permission: str = "push"
@@ -280,9 +281,9 @@ class GitHubAPI:
                     ", ".join(existing_members), team.name
                 )
             )
-        self.add_to_team(missing_members, team)
+        self._add_to_team(missing_members, team)
 
-    def add_to_team(self, members: Iterable[str], team: github.Team.Team):
+    def _add_to_team(self, members: Iterable[str], team: github.Team.Team):
         """Add members to a team.
 
         Args:
@@ -294,18 +295,18 @@ class GitHubAPI:
             for user in users:
                 team.add_membership(user)
 
-    def create_repos(self, repo_infos: Iterable[tuples.Repo]):
+    def create_repos(self, repos: Iterable[tuples.Repo]):
         """Create repositories in the given organization according to the Repos.
         Repos that already exist are skipped.
 
         Args:
-            repo_infos: An iterable of Repo namedtuples.
+            repos: An iterable of Repo namedtuples.
 
         Returns:
             A list of urls to all repos corresponding to the Repos.
         """
         repo_urls = []
-        for info in repo_infos:
+        for info in repos:
             created = False
             with _try_api_request(ignore_statuses=[422]):
                 kwargs = dict(
@@ -489,7 +490,7 @@ class GitHubAPI:
             issue: An an optional Issue tuple to override the default issue.
         """
         issue = issue or DEFAULT_REVIEW_ISSUE
-        for team, repo in self.add_repos_to_teams(team_to_repos):
+        for team, repo in self._add_repos_to_teams(team_to_repos):
             # TODO team.get_members() api request is a bit redundant, it
             # can be solved in a more efficient way by passing in the
             # allocations
@@ -527,7 +528,7 @@ class GitHubAPI:
             assigned_repos is a :py:class:`~repobee.tuples.Review`.
         """
         reviews = collections.defaultdict(list)
-        teams = self.get_teams_in(review_team_names)
+        teams = self._get_teams_in(review_team_names)
         for team in teams:
             with _try_api_request():
                 LOGGER.info("processing {}".format(team.name))
@@ -557,7 +558,7 @@ class GitHubAPI:
 
         return reviews
 
-    def add_repos_to_teams(
+    def _add_repos_to_teams(
         self, team_to_repos: Mapping[str, Iterable[str]]
     ) -> Generator[
         Tuple[github.Team.Team, github.Repository.Repository], None, None


Test patch:
diff --git a/tests/test_github_api.py b/tests/test_github_api.py
index f03a05a..9976d19 100644
--- a/tests/test_github_api.py
+++ b/tests/test_github_api.py
@@ -668,7 +668,7 @@ class TestGetIssues:
 
 @pytest.fixture
 def team_to_repos(api, no_repos, organization):
-    """Create a team_to_repos mapping for use in add_repos_to_teams, anc create
+    """Create a team_to_repos mapping for use in _add_repos_to_teams, anc create
     each team and repo. Return the team_to_repos mapping.
     """
     num_teams = 10
@@ -718,7 +718,7 @@ class TestAddReposToTeams:
         expected_tups = sorted(team_to_repos.items())
 
         # act
-        result = list(api.add_repos_to_teams(team_to_repos))
+        result = list(api._add_repos_to_teams(team_to_repos))
         result.sort(key=lambda tup: tup[0].name)
 
         # assert