diff options
author | rubenwardy <rw@rubenwardy.com> | 2019-08-09 11:25:16 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2019-08-09 11:25:19 +0100 |
commit | 776a3eff2aa9b06262e417c30f97dfda5af2a5b0 (patch) | |
tree | af6e7d4d78518720d6b68400cc7172f1e1d2b756 /app/tasks/importtasks.py | |
parent | 04e8ae5bdd73f6a939c51ef7993935afd2e576f2 (diff) | |
download | cheatdb-776a3eff2aa9b06262e417c30f97dfda5af2a5b0.tar.xz |
Fail gracefully when given a bad git reference
Diffstat (limited to 'app/tasks/importtasks.py')
-rw-r--r-- | app/tasks/importtasks.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py index 8c061d0..465e3c2 100644 --- a/app/tasks/importtasks.py +++ b/app/tasks/importtasks.py @@ -343,8 +343,11 @@ def makeVCSReleaseFromGithub(id, branch, release, url): raise TaskError("Invalid github repo URL") commitsURL = urlmaker.getCommitsURL(branch) - contents = urllib.request.urlopen(commitsURL).read().decode("utf-8") - commits = json.loads(contents) + try: + 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]: raise TaskError("No commits found") @@ -353,7 +356,6 @@ def makeVCSReleaseFromGithub(id, branch, release, url): release.task_id = None release.commit_hash = commits[0]["sha"] release.approve(release.package.author) - print(release.url) db.session.commit() return release.url |