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. ```
This commit is contained in:
parent
c03e631097
commit
9f80bf2a9e
33
tools/rewrite-git-redirects.py
Executable file
33
tools/rewrite-git-redirects.py
Executable file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/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))
|
Loading…
Reference in a new issue