@@ -100,6 +100,10 @@ def update_demo(
100100 git ("commit" , "-m" , f"chore: { last_update_commit } -> { template_commit } " , "--no-verify" )
101101 git ("push" , "-u" , "origin" , desired_branch_name )
102102 if desired_branch_name != "develop" :
103+ pr_url : Optional [str ] = _get_pr_url (branch = desired_branch_name )
104+ if pr_url is not None :
105+ typer .secho (f"PR already found at `{ pr_url } `, skipping PR creation." )
106+ return
103107 _create_demo_pr (demo_path = demo_path , branch = desired_branch_name , commit_start = last_update_commit )
104108
105109
@@ -149,12 +153,9 @@ def _validate_template_main_not_checked_out(branch: str) -> None:
149153def _create_demo_pr (demo_path : Path , branch : str , commit_start : str ) -> None :
150154 """Creates a PR to merge the given branch into develop."""
151155 gh ("repo" , "set-default" , f"{ DEMO .app_author } /{ DEMO .app_name } " )
152- search_results : subprocess .CompletedProcess = gh ("pr" , "list" , "--state" , "open" , "--search" , branch )
153-
154- if search_results .returncode == 0 :
155- url : str = _get_pr_url (branch = branch )
156- typer .secho (f"Skipping PR creation due to existing PR found for branch { branch } at { url } " )
157- return
156+ pr_url : Optional [str ] = _get_pr_url (branch = branch )
157+ if pr_url is not None :
158+ raise ValueError (f"Attempting to create a PR that already exists at { pr_url } ." )
158159
159160 body : str = _get_demo_feature_pr_body (demo_path = demo_path , commit_start = commit_start )
160161
@@ -166,17 +167,19 @@ def _create_demo_pr(demo_path: Path, branch: str, commit_start: str) -> None:
166167 "--repo" : f"{ DEMO .app_author } /{ DEMO .app_name } " ,
167168 }
168169 gh ("pr" , "create" , * itertools .chain .from_iterable (pr_kwargs .items ()))
169- url : str = _get_pr_url (branch = branch )
170+ url : Optional [str ] = _get_pr_url (branch = branch )
171+ if url is None :
172+ raise ValueError (f"Unable to find url for the PR just created for branch { branch } ." )
170173 typer .secho (f"Created PR for branch '{ branch } ' at '{ url } '." )
171174
172175
173- def _get_pr_url (branch : str ) -> str :
176+ def _get_pr_url (branch : str ) -> Optional [ str ] :
174177 """Returns the url of the current branch's PR."""
175178 result : Optional [subprocess .CompletedProcess ] = gh (
176179 "pr" , "view" , branch , "--json" , "url" , "--jq" , ".url" , ignore_error = True
177180 )
178181 if result is None :
179- raise ValueError ( f"Failed to find a PR URL for branch { branch } ." )
182+ return None
180183 return result .stdout .strip ()
181184
182185
0 commit comments