From 94b05b8fd8bd8a8e4a6b315a8f64c327164f4a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Thu, 15 Feb 2024 23:46:12 +0100 Subject: [PATCH] Handle cases with already existing branch / commit --- autoupdate_app_sources/autoupdate_app_sources.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/autoupdate_app_sources/autoupdate_app_sources.py b/autoupdate_app_sources/autoupdate_app_sources.py index 2cf0612..aa65352 100755 --- a/autoupdate_app_sources/autoupdate_app_sources.py +++ b/autoupdate_app_sources/autoupdate_app_sources.py @@ -145,6 +145,7 @@ class LocalOrRemoteRepo: self.pr_branch = name 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()]: + print("already existing") return False self.repo.create_git_ref(ref=f"refs/heads/{name}", sha=commit_sha) return True @@ -156,7 +157,7 @@ class LocalOrRemoteRepo: pr = self.repo.create_pull( 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") return None @@ -223,8 +224,17 @@ class AppAutoUpdater: try: if pr: self.repo.new_branch(branch_name) + except github.GithubException as e: + if e.status == 409: + print("Branch already exists!") + + try: if commit: self.repo.commit(commit_msg) + except github.GithubException as e: + if e.status == 409: + print("Commits were already commited on branch!") + try: if pr: pr_url = self.repo.create_pr(branch_name, pr_title, commit_msg) or "" except github.GithubException as e: