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.
This commit is contained in:
Hans-Christoph Steiner 2017-04-11 12:28:36 +02:00
parent 183ce9541b
commit 5cc15d0fa9
2 changed files with 23 additions and 15 deletions

View file

@ -519,30 +519,38 @@ def extract_pubkey():
return hexlify(pubkey), repo_pubkey_fingerprint return hexlify(pubkey), repo_pubkey_fingerprint
# Get raw URL from git service for mirroring
def get_raw_mirror(url): def get_raw_mirror(url):
# Divide urls in parts '''Get direct URL from git service for use by fdroidclient
url = url.split("/")
# Get the hostname Via 'servergitmirrors', fdroidserver can create and push a mirror
hostname = url[2] 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" branch = "master"
folder = "fdroid" folder = "fdroid"
if hostname == "github.com": if hostname == "github.com":
# Github like RAW url "https://raw.githubusercontent.com/user/repo/master/fdroid" # Github like RAW segments "https://raw.githubusercontent.com/user/repo/master/fdroid"
url[2] = "raw.githubusercontent.com" segments[2] = "raw.githubusercontent.com"
url.extend([branch, folder]) segments.extend([branch, folder])
elif hostname == "gitlab.com": elif hostname == "gitlab.com":
# Gitlab like RAW url "https://gitlab.com/user/repo/raw/master/fdroid" # Gitlab like RAW segments "https://gitlab.com/user/repo/raw/master/fdroid"
url.extend(["raw", branch, folder]) segments.extend(["raw", branch, folder])
else: else:
return None return None
url = "/".join(url) if segments[4].endswith('.git'):
return url segments[4] = segments[4][:-4]
return '/'.join(segments)
class VerificationException(Exception): class VerificationException(Exception):

View file

@ -22,6 +22,7 @@ import hashlib
import os import os
import paramiko import paramiko
import pwd import pwd
import re
import subprocess import subprocess
from argparse import ArgumentParser from argparse import ArgumentParser
import logging import logging
@ -235,9 +236,8 @@ def update_servergitmirrors(servergitmirrors, repo_section):
repo = git.Repo.init(repo_dir) repo = git.Repo.init(repo_dir)
# take care of each mirror
for mirror in servergitmirrors: for mirror in servergitmirrors:
hostname = mirror.split("/")[2] hostname = re.sub(r'\W*\w+\W+(\w+).*', r'\1', mirror)
repo.create_remote(hostname, mirror) repo.create_remote(hostname, mirror)
logging.info('Mirroring to: ' + mirror) logging.info('Mirroring to: ' + mirror)