]> git.lizzy.rs Git - cheatdb.git/commitdiff
Fail gracefully when given a bad git reference
authorrubenwardy <rw@rubenwardy.com>
Fri, 9 Aug 2019 10:25:16 +0000 (11:25 +0100)
committerrubenwardy <rw@rubenwardy.com>
Fri, 9 Aug 2019 10:25:19 +0000 (11:25 +0100)
app/tasks/importtasks.py

index 8c061d0d136d02fbbf58271986568ba0a70eaf80..465e3c2213430c0d3ba325dc9aa649c701a89db2 100644 (file)
@@ -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