chiark / gitweb /
support git@gitlab.com: style URLs in servergitmirrors
authorHans-Christoph Steiner <hans@eds.org>
Tue, 11 Apr 2017 10:28:36 +0000 (12:28 +0200)
committerHans-Christoph Steiner <hans@eds.org>
Tue, 11 Apr 2017 22:45:22 +0000 (00:45 +0200)
This converts the git@gitlab.com SSH URLs to the proper HTTPS URLs that
fdroidclient can directly use.

fdroidserver/index.py
fdroidserver/server.py

index 44b1a1b9b4140b5db6d7813a1523328a2a240bd6..0035c3ed73bde66871a258e111f7f66383f0c325 100644 (file)
@@ -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):
index 70e9938fa9635835ef81fde4da37f2ae9ec1265f..5bd146610b155d345fc652a9d75ab09f5ad7b680 100644 (file)
@@ -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)