From 99b21f996cde01446b13f4c7ec525e5a6bf3df1e Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 5 Jun 2018 19:59:07 +0100 Subject: [PATCH] Fix screenshot import being broken --- app/tasks/importtasks.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py index c2460d2..2d8ee8b 100644 --- a/app/tasks/importtasks.py +++ b/app/tasks/importtasks.py @@ -26,6 +26,39 @@ from app.models import * from app.tasks import celery, TaskError from app.utils import randomString + +class GithubURLMaker: + def __init__(self, url): + # Rewrite path + import re + m = re.search("^\/([^\/]+)\/([^\/]+)\/?$", url.path) + if m is None: + return + + user = m.group(1) + repo = m.group(2).replace(".git", "") + self.baseUrl = "https://raw.githubusercontent.com/{}/{}/master" \ + .format(user, repo) + self.user = user + self.repo = repo + + def isValid(self): + return self.baseUrl is not None + + def getRepoURL(self): + return "https://github.com/{}/{}".format(self.user, self.repo) + + def getScreenshotURL(self): + return self.baseUrl + "/screenshot.png" + + def getCommitsURL(self, branch): + return "https://api.github.com/repos/{}/{}/commits?sha={}" \ + .format(self.user, self.repo, urllib.parse.quote_plus(branch)) + + def getCommitDownload(self, commit): + return "https://github.com/{}/{}/archive/{}.zip" \ + .format(self.user, self.repo, commit) + krock_list_cache = None krock_list_cache_by_name = None def getKrockList():