diff --git a/src/ghstack/github.py b/src/ghstack/github.py index 31343ca..99c28cd 100644 --- a/src/ghstack/github.py +++ b/src/ghstack/github.py @@ -10,6 +10,10 @@ class NotFoundError(RuntimeError): pass +class LicenseError(RuntimeError): + pass + + class GitHubEndpoint(metaclass=ABCMeta): @abstractmethod def graphql(self, query: str, **kwargs: Any) -> Any: diff --git a/src/ghstack/github_real.py b/src/ghstack/github_real.py index 600fe64..ac074ee 100644 --- a/src/ghstack/github_real.py +++ b/src/ghstack/github_real.py @@ -187,6 +187,11 @@ def rest(self, method: str, path: str, **kwargs: Any) -> Any: # Per Github rate limiting: https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#exceeding-the-rate-limit if resp.status_code in (403, 429): + if resp.status_code == 403 and "Upgrade to GitHub Pro" in r.get( + "message", "" + ): + raise ghstack.github.LicenseError(pretty_json) + remaining_count = resp.headers.get("x-ratelimit-remaining") reset_time = resp.headers.get("x-ratelimit-reset") diff --git a/src/ghstack/land.py b/src/ghstack/land.py index 08adfb6..f804d8d 100644 --- a/src/ghstack/land.py +++ b/src/ghstack/land.py @@ -88,6 +88,10 @@ def main( needs_force = True except ghstack.github.NotFoundError: pass + except ghstack.github.LicenseError: + logging.warning( + "Failed to check branch protection (GitHub Pro required), skipping check." + ) orig_ref, closed = lookup_pr_to_orig_ref_and_closed( github,