Fail gracefully when given a bad git reference

This commit is contained in:
rubenwardy 2019-08-09 11:25:16 +01:00
parent 04e8ae5bdd
commit 776a3eff2a
1 changed files with 5 additions and 3 deletions

View File

@ -343,8 +343,11 @@ def makeVCSReleaseFromGithub(id, branch, release, url):
raise TaskError("Invalid github repo URL") raise TaskError("Invalid github repo URL")
commitsURL = urlmaker.getCommitsURL(branch) commitsURL = urlmaker.getCommitsURL(branch)
contents = urllib.request.urlopen(commitsURL).read().decode("utf-8") try:
commits = json.loads(contents) contents = urllib.request.urlopen(commitsURL).read().decode("utf-8")
commits = json.loads(contents)
except urllib.error.HTTPError:
raise TaskError("Unable to get commits for Github repository. Either the repository or reference doesn't exist.")
if len(commits) == 0 or not "sha" in commits[0]: if len(commits) == 0 or not "sha" in commits[0]:
raise TaskError("No commits found") raise TaskError("No commits found")
@ -353,7 +356,6 @@ def makeVCSReleaseFromGithub(id, branch, release, url):
release.task_id = None release.task_id = None
release.commit_hash = commits[0]["sha"] release.commit_hash = commits[0]["sha"]
release.approve(release.package.author) release.approve(release.package.author)
print(release.url)
db.session.commit() db.session.commit()
return release.url return release.url