示例#1
0
 async def merge(
     self,
     merge_method: str,
     commit_title: Optional[str],
     commit_message: Optional[str],
 ) -> None:
     self.log.info("merge", method=merge_method)
     async with self.client(
         installation_id=self.install, owner=self.owner, repo=self.repo
     ) as api_client:
         res = await api_client.merge_pull_request(
             number=self.number,
             merge_method=merge_method,
             commit_title=commit_title,
             commit_message=commit_message,
         )
         try:
             res.raise_for_status()
         except HTTPError as e:
             if e.response is not None and e.response.status_code == 405:
                 self.log.info(
                     "branch is not mergeable. PR likely already merged.", res=res
                 )
             else:
                 self.log.exception("failed to merge pull request", res=res)
             if e.response is not None and e.response.status_code == 500:
                 raise GitHubApiInternalServerError
             # we raise an exception to retry this request.
             raise ApiCallException(
                 method="pull_request/merge",
                 http_status_code=res.status_code,
                 response=res.content,
             )
示例#2
0
 async def update_branch(self) -> None:
     self.log.info("update_branch")
     async with self.client(installation_id=self.install,
                            owner=self.owner,
                            repo=self.repo) as api_client:
         res = await api_client.update_branch(pull_number=self.number)
         try:
             res.raise_for_status()
         except HTTPError:
             self.log.exception("failed to update branch", res=res)
             # we raise an exception to retry this request.
             raise ApiCallException("update branch")
示例#3
0
 async def add_label(self, label: str) -> None:
     """
     add label to pull request
     """
     self.log.info("add_label", label=label)
     async with self.client(installation_id=self.install,
                            owner=self.owner,
                            repo=self.repo) as api_client:
         res = await api_client.add_label(label, pull_number=self.number)
         try:
             res.raise_for_status()
         except HTTPError:
             self.log.exception("failed to add label", label=label, res=res)
             raise ApiCallException("add label")
示例#4
0
 async def remove_label(self, label: str) -> None:
     """
     remove the PR label specified by `label_id` for a given `pr_number`
     """
     self.log.info("remove_label", label=label)
     async with self.client(
         installation_id=self.install, owner=self.owner, repo=self.repo
     ) as api_client:
         res = await api_client.delete_label(label, pull_number=self.number)
         try:
             res.raise_for_status()
         except HTTPError:
             self.log.exception("failed to delete label", label=label, res=res)
             # we raise an exception to retry this request.
             raise ApiCallException("delete label")
示例#5
0
 async def update_branch(self) -> None:
     self.log.info("update_branch")
     async with self.client(
         installation_id=self.install, owner=self.owner, repo=self.repo
     ) as api_client:
         res = await api_client.update_branch(pull_number=self.number)
         try:
             res.raise_for_status()
         except HTTPError:
             self.log.warning("failed to update branch", res=res, exc_info=True)
             # we raise an exception to retry this request.
             raise ApiCallException(
                 method="pull_request/update_branch",
                 http_status_code=res.status_code,
                 response=res.content,
             )
示例#6
0
 async def update_ref(self, ref: str, sha: str) -> None:
     self.log.info("update_ref", ref=ref, sha=sha)
     async with self.client(
         installation_id=self.install, owner=self.owner, repo=self.repo
     ) as api_client:
         res = await api_client.update_ref(ref=ref, sha=sha)
         try:
             res.raise_for_status()
         except HTTPError as e:
             if e.response is not None and e.response.status_code == 422:
                 self.log.info("fast forward update not possible.", res=res)
             else:
                 self.log.exception("failed to update ref", res=res)
             # we raise an exception to retry this request.
             raise ApiCallException(
                 method="pull_request/update_ref",
                 http_status_code=res.status_code,
                 response=res.content,
             )
示例#7
0
 async def add_label(self, label: str) -> None:
     """
     add label to pull request
     """
     self.log.info("add_label", label=label)
     async with self.client(
         installation_id=self.install, owner=self.owner, repo=self.repo
     ) as api_client:
         res = await api_client.add_label(label, pull_number=self.number)
         try:
             res.raise_for_status()
         except HTTPError:
             self.log.warning(
                 "failed to add label", label=label, res=res, exc_info=True
             )
             raise ApiCallException(
                 method="pull_request/add_label",
                 http_status_code=res.status_code,
                 response=res.content,
             )