From: Hans-Christoph Steiner Date: Tue, 11 Apr 2017 10:28:36 +0000 (+0200) Subject: support git@gitlab.com: style URLs in servergitmirrors X-Git-Tag: 0.8~78^2~7 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5cc15d0fa9f70057b05ae6429cf1e683eeddfd09;p=fdroidserver.git support git@gitlab.com: style URLs in servergitmirrors This converts the git@gitlab.com SSH URLs to the proper HTTPS URLs that fdroidclient can directly use. --- diff --git a/fdroidserver/index.py b/fdroidserver/index.py index 44b1a1b9..0035c3ed 100644 --- a/fdroidserver/index.py +++ b/fdroidserver/index.py @@ -519,30 +519,38 @@ def extract_pubkey(): return hexlify(pubkey), repo_pubkey_fingerprint -# Get raw URL from git service for mirroring def get_raw_mirror(url): - # Divide urls in parts - url = url.split("/") + '''Get direct URL from git service for use by fdroidclient - # Get the hostname - hostname = url[2] + Via 'servergitmirrors', fdroidserver can create and push a mirror + to certain well known git services like gitlab or github. This + will always use the 'master' branch since that is the default + branch in git. - # fdroidserver will use always 'master' branch for git-mirroring + ''' + + if url.startswith('git@'): + url = re.sub(r'^git@(.*):(.*)', r'https://\1/\2', url) + + segments = url.split("/") + hostname = segments[2] branch = "master" folder = "fdroid" if hostname == "github.com": - # Github like RAW url "https://raw.githubusercontent.com/user/repo/master/fdroid" - url[2] = "raw.githubusercontent.com" - url.extend([branch, folder]) + # Github like RAW segments "https://raw.githubusercontent.com/user/repo/master/fdroid" + segments[2] = "raw.githubusercontent.com" + segments.extend([branch, folder]) elif hostname == "gitlab.com": - # Gitlab like RAW url "https://gitlab.com/user/repo/raw/master/fdroid" - url.extend(["raw", branch, folder]) + # Gitlab like RAW segments "https://gitlab.com/user/repo/raw/master/fdroid" + segments.extend(["raw", branch, folder]) else: return None - url = "/".join(url) - return url + if segments[4].endswith('.git'): + segments[4] = segments[4][:-4] + + return '/'.join(segments) class VerificationException(Exception): diff --git a/fdroidserver/server.py b/fdroidserver/server.py index 70e9938f..5bd14661 100644 --- a/fdroidserver/server.py +++ b/fdroidserver/server.py @@ -22,6 +22,7 @@ import hashlib import os import paramiko import pwd +import re import subprocess from argparse import ArgumentParser import logging @@ -235,9 +236,8 @@ def update_servergitmirrors(servergitmirrors, repo_section): repo = git.Repo.init(repo_dir) - # take care of each mirror for mirror in servergitmirrors: - hostname = mirror.split("/")[2] + hostname = re.sub(r'\W*\w+\W+(\w+).*', r'\1', mirror) repo.create_remote(hostname, mirror) logging.info('Mirroring to: ' + mirror)