How to use the gidgethub.HTTPException function in gidgethub

To help you get started, we’ve selected a few gidgethub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hail-is / hail / ci / ci / github.py View on Github external
async def merge(self, gh):
        try:
            await gh.put(f'/repos/{self.target_branch.branch.repo.short_str()}/pulls/{self.number}/merge',
                         data={
                             'merge_method': 'squash',
                             'sha': self.source_sha
                         })
            return True
        except (gidgethub.HTTPException, aiohttp.client_exceptions.ClientResponseError) as e:
            log.info(f'merge {self.target_branch.branch.short_str()} {self.number} failed due to exception: {e}')
        return False
github brettcannon / gidgethub / gidgethub / sansio.py View on Github external
if status_code == 403:
                rate_limit = RateLimit.from_http(headers)
                if rate_limit and not rate_limit.remaining:
                    raise RateLimitExceeded(rate_limit, message)
            elif status_code == 422:
                errors = data.get("errors", None)
                if errors:
                    fields = ", ".join(repr(e["field"]) for e in errors)
                    message = f"{message} for {fields}"
                else:
                    message = data["message"]
                raise InvalidField(errors, message)
        elif status_code >= 300:
            exc_type = RedirectionException
        else:
            exc_type = HTTPException
        status_code_enum = http.HTTPStatus(status_code)
        args: Union[Tuple[http.HTTPStatus, str], Tuple[http.HTTPStatus]]
        if message:
            args = status_code_enum, message
        else:
            args = status_code_enum,
        raise exc_type(*args)
github bioconda / bioconda-utils / bioconda_utils / githubhandler.py View on Github external
async def pr_update_branch(self, number) -> bool:
        """Updates PR branch

        Merges changes to "base" into "head"
        """
        var_data = copy(self.var_default)
        var_data['number'] = str(number)
        accept = "application/vnd.github.lydian-preview+json"
        try:
            await self.api.put(self.PULL_UPDATE, var_data, accept=accept, data={})
            return True
        except gidgethub.HTTPException as exc:
            if exc.status_code == 202:
                # Usually, we will get our "true" result via this exception.
                # GitHub sends 202 "Accepted" for this API call. Gidgethub raises
                # on anything but 200, 201, 204 (see sansio.py:decipher_response).
                # So we catch and check the status code.
                return True
            logger.exception("pr_update_branch_failed (2). status_code=%s, args=%s",
                             exc.status_code, exc.args)
            return False
github brettcannon / gidgethub / gidgethub / sansio.py View on Github external
part of results. If there are no more results then None is
    returned. Do be aware that the URL can be a URI template and so
    may need to be expanded.

    If the status code is anything other than 200, 201, or 204, then
    an HTTPException is raised.
    """
    data = _decode_body(headers.get("content-type"), body)
    if status_code in {200, 201, 204}:
        return data, RateLimit.from_http(headers), _next_link(headers.get("link"))
    else:
        try:
            message = data["message"]
        except (TypeError, KeyError):
            message = None
        exc_type: Type[HTTPException]
        if status_code >= 500:
            exc_type = GitHubBroken
        elif status_code >= 400:
            exc_type = BadRequest
            if status_code == 403:
                rate_limit = RateLimit.from_http(headers)
                if rate_limit and not rate_limit.remaining:
                    raise RateLimitExceeded(rate_limit, message)
            elif status_code == 422:
                errors = data.get("errors", None)
                if errors:
                    fields = ", ".join(repr(e["field"]) for e in errors)
                    message = f"{message} for {fields}"
                else:
                    message = data["message"]
                raise InvalidField(errors, message)