fdroiddata/tools/rewrite-git-redirects.py
Hans-Christoph Steiner 9f80bf2a9e
tools/rewrite-git-redirects.py: use canonical gitlab URLs for Repo:
```console
$ git clone https://gitlab.com/fdroid/ci-images-base.git
Cloning into 'ci-images-base'...
remote: Enumerating objects: 89, done.
remote: Counting objects: 100% (89/89), done.
remote: Compressing objects: 100% (50/50), done.
remote: Total 89 (delta 51), reused 68 (delta 39)
Unpacking objects: 100% (89/89), done.
$ rm -rf ci-images-base/
$ git clone https://gitlab.com/fdroid/ci-images-base
Cloning into 'ci-images-base'...
warning: redirecting to https://gitlab.com/fdroid/ci-images-base.git/
remote: Enumerating objects: 89, done.
remote: Counting objects: 100% (89/89), done.
remote: Compressing objects: 100% (50/50), done.
remote: Total 89 (delta 51), reused 68 (delta 39)
Unpacking objects: 100% (89/89), done.
```
2019-10-03 13:58:55 +02:00

34 lines
908 B
Python
Executable file

#!/usr/bin/env python3
#
#
# GitLab gives a warning every time if the git URL is redirected. So this
# rewrites all GitLab URLs so they are no longer a redirect.
import glob
import os
import re
import sys
import yaml
os.chdir(os.path.dirname(__file__) + '/../')
if len(sys.argv) > 1:
files = sys.argv[1:]
else:
files = sorted(glob.glob('metadata/*.yml'))
pattern = re.compile(r'Repo: .*')
for f in files:
with open(f) as fp:
data = yaml.load(fp)
repo_url = None
if 'Repo' in data:
repo_url = data['Repo'].strip().rstrip('/')
if repo_url and not repo_url.endswith('.git') and repo_url.startswith('https://gitlab'):
new_url = repo_url + '.git'
print("Repo:", data['Repo'], "\n --> " + new_url + "'")
with open(f) as fp:
raw = fp.read()
with open(f, 'w') as fp:
fp.write(pattern.sub('Repo: ' + new_url, raw))