@@ -735,79 +735,6 @@ def git_push(self, *args, **kwargs) -> PushInfoList:
735735 """Git push."""
736736 return self ._op .push_changes (* args , ** kwargs )
737737
738- @noapidoc
739- def make_pr (self , title : str , body : str , branch : str | None = None ) -> dict [str , str ]:
740- """Creates a pull request or returns a URL to create one.
741-
742- If the repository operator has GitHub API access, creates the PR directly.
743- Otherwise, returns a URL that can be used to create the PR manually.
744-
745- If branch is provided, checks out that branch (creating if needed) and pushes current changes to it.
746- If no branch is provided and on default branch, creates a new branch based on the PR title.
747-
748- TODO(CG-10339): This is a temporary solution to create a PR. We should use the GitHub API to create a PR instead.
749-
750- Args:
751- title: The title for the pull request
752- body: The description/body for the pull request
753- branch: Optional branch name to create PR from. If provided, will checkout/create branch and push to it.
754-
755- Returns:
756- A dictionary containing either:
757- - On success: {"status": "success", "url": "<pr_url>", "number": pr_number}
758- - On manual URL: {"status": "manual", "url": "<url_to_create_pr>"}
759- - On error: {"error": "<error_message>"}
760- """
761- # Get current branch
762- current = self ._op .get_active_branch_or_commit ()
763- if isinstance (current , str ) and len (current ) == 40 :
764- # We're in detached HEAD state (a commit hash is 40 chars)
765- return {"error" : "Cannot create PR from detached HEAD state. Please checkout a branch first." }
766-
767- # Get base branch (default branch)
768- base = self .default_branch
769-
770- # Handle branch selection/creation
771- if branch is not None :
772- # Use provided branch name
773- result = self ._op .checkout_branch (branch , create_if_missing = True )
774- if result != CheckoutResult .SUCCESS :
775- return {"error" : f"Failed to create and checkout branch { branch } " }
776- # Stage and commit any changes
777- if self ._op .git_cli .is_dirty ():
778- self ._op .stage_and_commit_all_changes (f"feat: { title } " )
779- # Push the changes
780- self ._op .push_changes (force = True )
781- current = branch
782- elif current == base :
783- # Create a branch name from the PR title
784- # Replace spaces and special chars with dashes, lowercase everything
785- branch_name = title .lower ()
786- branch_name = "" .join (c if c .isalnum () else "-" for c in branch_name )
787- branch_name = "-" .join (filter (None , branch_name .split ("-" ))) # Remove empty segments
788- branch_name = f"feature/{ branch_name } "
789-
790- # Create and checkout the new branch
791- result = self ._op .checkout_branch (branch_name , create_if_missing = True )
792- if result != CheckoutResult .SUCCESS :
793- return {"error" : f"Failed to create and checkout branch { branch_name } " }
794- current = branch_name
795-
796- # Get the repo URL
797- base_url = self ._op .base_url ()
798- if not base_url :
799- return {"error" : "Could not determine repository URL" }
800-
801- # Remove .git suffix if present
802- if base_url .endswith (".git" ):
803- base_url = base_url [:- 4 ]
804-
805- # Create compare URL that pre-fills PR details
806- params = f"?title={ title } &body={ body } "
807- url = f"{ base_url } /compare/{ base } ...{ current } { params } "
808-
809- return {"status" : "manual" , "url" : url }
810-
811738 @property
812739 def default_branch (self ) -> str :
813740 """The default branch of this repository.
0 commit comments