Skip to content

Commit ae30c7c

Browse files
committed
Improve GitHub API/repo interactions in manage-cookie
- Use repo HTTP URL for repo clone - Only attempt to delete existing manage-cookie branch if it exists
1 parent 9cedf76 commit ae30c7c

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

cookie_python/manage/repo.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from typing import Any
1313

1414
import loguru
15+
from github import GithubException
1516

1617
from .github import GithubRepo
1718

@@ -78,12 +79,19 @@ def cachedir(self) -> Path:
7879
@cached_property
7980
def clone_path(self) -> Path:
8081
subprocess.run(
81-
["git", "clone", self.repo.ssh_url, "repo"],
82+
["git", "clone", self.repo.html_url, "repo"],
8283
cwd=self.tempdir,
8384
check=True,
8485
)
8586
clone_path = self.tempdir / "repo"
8687
for cmd in (
88+
[
89+
"git",
90+
"config",
91+
"--local",
92+
"remote.origin.pushurl",
93+
self.repo.ssh_url,
94+
],
8795
["git", "checkout", "-b", self.branch],
8896
["git", "reset", "--hard", "origin/main"],
8997
):
@@ -154,7 +162,16 @@ def close_existing_pr(self) -> None:
154162
else:
155163
pr.edit(state="closed")
156164
self.logger.info(f"Closed existing PR {pr.url}")
165+
try:
166+
self.repo.get_branch(self.branch)
167+
except GithubException as e:
168+
if e.status == 404:
169+
return
170+
raise
157171
if self.dry_run:
172+
self.logger.info(
173+
f"Would delete existing remote branch {self.branch}"
174+
)
158175
return
159176
# Delete existing branch
160177
delete_result = self.run(

0 commit comments

Comments
 (0)