Create a new pull request.
(self, title: str, body: str, head: str, base: str = "main", draft: bool = False)
| 670 | return {"error": str(e)} |
| 671 | |
| 672 | async def create_pr(self, title: str, body: str, head: str, base: str = "main", draft: bool = False) -> dict: |
| 673 | """Create a new pull request.""" |
| 674 | if not self._has_auth(): |
| 675 | return {"error": "GitHub token not configured"} |
| 676 | |
| 677 | url = f"https://api.github.com/repos/{self.repo}/pulls" |
| 678 | payload = { |
| 679 | "title": title, |
| 680 | "body": body, |
| 681 | "head": head, |
| 682 | "base": base, |
| 683 | "draft": draft, |
| 684 | } |
| 685 | |
| 686 | try: |
| 687 | session = await self.get_session() |
| 688 | async with session.post(url, json=payload, headers=await self._get_headers()) as response: |
| 689 | if response.status == 201: |
| 690 | data = await response.json() |
| 691 | return { |
| 692 | "success": True, |
| 693 | "pr_number": data["number"], |
| 694 | "pr_url": data["html_url"], |
| 695 | "state": "draft" if draft else "open", |
| 696 | } |
| 697 | elif response.status == 422: |
| 698 | error_data = await response.json() |
| 699 | return {"error": f"Cannot create PR: {error_data.get('message', 'validation failed')}"} |
| 700 | else: |
| 701 | return {"error": f"GitHub API error: {response.status}"} |
| 702 | except Exception as e: |
| 703 | logger.error(f"Error creating PR: {e}") |
| 704 | return {"error": str(e)} |
| 705 | |
| 706 | async def convert_to_draft(self, pr_number: int) -> dict: |
| 707 | """Convert a PR to draft using GraphQL mutation.""" |
no test coverage detected