Handle cases with already existing branch / commit
This commit is contained in:
parent
0953331355
commit
94b05b8fd8
1 changed files with 11 additions and 1 deletions
|
@ -145,6 +145,7 @@ class LocalOrRemoteRepo:
|
||||||
self.pr_branch = name
|
self.pr_branch = name
|
||||||
commit_sha = self.repo.get_branch(self.base_branch).commit.sha
|
commit_sha = self.repo.get_branch(self.base_branch).commit.sha
|
||||||
if self.pr_branch in [branch.name for branch in self.repo.get_branches()]:
|
if self.pr_branch in [branch.name for branch in self.repo.get_branches()]:
|
||||||
|
print("already existing")
|
||||||
return False
|
return False
|
||||||
self.repo.create_git_ref(ref=f"refs/heads/{name}", sha=commit_sha)
|
self.repo.create_git_ref(ref=f"refs/heads/{name}", sha=commit_sha)
|
||||||
return True
|
return True
|
||||||
|
@ -156,7 +157,7 @@ class LocalOrRemoteRepo:
|
||||||
pr = self.repo.create_pull(
|
pr = self.repo.create_pull(
|
||||||
title=title, body=message, head=branch, base=self.base_branch
|
title=title, body=message, head=branch, base=self.base_branch
|
||||||
)
|
)
|
||||||
return pr.url
|
return pr.html_url
|
||||||
logging.warning("Can't create pull requests for local repositories")
|
logging.warning("Can't create pull requests for local repositories")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -223,8 +224,17 @@ class AppAutoUpdater:
|
||||||
try:
|
try:
|
||||||
if pr:
|
if pr:
|
||||||
self.repo.new_branch(branch_name)
|
self.repo.new_branch(branch_name)
|
||||||
|
except github.GithubException as e:
|
||||||
|
if e.status == 409:
|
||||||
|
print("Branch already exists!")
|
||||||
|
|
||||||
|
try:
|
||||||
if commit:
|
if commit:
|
||||||
self.repo.commit(commit_msg)
|
self.repo.commit(commit_msg)
|
||||||
|
except github.GithubException as e:
|
||||||
|
if e.status == 409:
|
||||||
|
print("Commits were already commited on branch!")
|
||||||
|
try:
|
||||||
if pr:
|
if pr:
|
||||||
pr_url = self.repo.create_pr(branch_name, pr_title, commit_msg) or ""
|
pr_url = self.repo.create_pr(branch_name, pr_title, commit_msg) or ""
|
||||||
except github.GithubException as e:
|
except github.GithubException as e:
|
||||||
|
|
Loading…
Reference in a new issue