nebius/SWE-bench-extra huggingface dataset:
Repository: repobee/repobee

Issue:
Add a check for GitHub base url
Check that the url is either `https://api.github.com`, or that it ends with `/api/v3`. There have been way too many user errors on incorrect urls, and the error messages can be cryptic.

Comments:

Patch:
diff --git a/src/_repobee/ext/github.py b/src/_repobee/ext/github.py
index 3bb248f..657a413 100644
--- a/src/_repobee/ext/github.py
+++ b/src/_repobee/ext/github.py
@@ -129,6 +129,17 @@ class GitHubAPI(plug.API):
         """
         if not user:
             raise TypeError("argument 'user' must not be empty")
+        if not (
+            base_url == "https://api.github.com"
+            or base_url.endswith("/api/v3")
+        ):
+            raise plug.PlugError(
+                "invalid base url, should either be https://api.github.com or "
+                "end with '/api/v3'. See the docs: "
+                "https://repobee.readthedocs.io/en/stable/"
+                "getting_started.html#configure-repobee-for-the-target"
+                "-organization-show-config-and-verify-settings"
+            )
         self._github = github.Github(login_or_token=token, base_url=base_url)
         self._org_name = org_name
         self._base_url = base_url


Test patch:
diff --git a/tests/unit_tests/plugin_tests/test_github.py b/tests/unit_tests/plugin_tests/test_github.py
index 959aafc..84ead19 100644
--- a/tests/unit_tests/plugin_tests/test_github.py
+++ b/tests/unit_tests/plugin_tests/test_github.py
@@ -317,6 +317,32 @@ def api(happy_github, organization, no_teams):
     return _repobee.ext.github.GitHubAPI(BASE_URL, TOKEN, ORG_NAME, USER)
 
 
+class TestInit:
+    def test_raises_on_empty_user_arg(self):
+        with pytest.raises(TypeError) as exc_info:
+            _repobee.ext.github.GitHubAPI(BASE_URL, TOKEN, ORG_NAME, "")
+
+        assert "argument 'user' must not be empty" in str(exc_info.value)
+
+    @pytest.mark.parametrize("url", ["https://github.com", constants.HOST_URL])
+    def test_raises_when_url_is_bad(self, url):
+        with pytest.raises(plug.PlugError) as exc_info:
+            _repobee.ext.github.GitHubAPI(url, TOKEN, ORG_NAME, USER)
+
+        assert (
+            "invalid base url, should either be https://api.github.com or "
+            "end with '/api/v3'" in str(exc_info.value)
+        )
+
+    @pytest.mark.parametrize(
+        "url", ["https://api.github.com", constants.BASE_URL]
+    )
+    def test_accepts_valid_urls(self, url):
+        api = _repobee.ext.github.GitHubAPI(url, TOKEN, ORG_NAME, USER)
+
+        assert isinstance(api, plug.API)
+
+
 class TestEnsureTeamsAndMembers:
     @staticmethod
     def assert_teams_equal(actual_teams, expected_teams):