Commit 670ca3f8 authored by Peter Hutterer's avatar Peter Hutterer
Browse files

ci-fairy: extract the server URL from any URL

Don't just allow for gitlab.fdo, let's search for the server in any origin
Complained-about-by: Benjamin Tissoires's avatarBenjamin Tissoires <>
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <>
parent acda94e1
......@@ -85,9 +85,22 @@ def ci_fairy(ctx, verbose, gitlab_url, authfile):
gitlab_url = os.getenv('CI_SERVER_URL')
if not gitlab_url:
from urllib.parse import urlparse
repo = git.Repo(search_parent_directories=True)
if '' in repo.remotes.origin.url:
gitlab_url = ''
url = repo.remotes.origin.url
# urlparse doesn't work with ssh specifiers which are in the
# form user@host:path. Convert those into ssh://user@host so
# urlparse works.
if '//' not in url[:10]:
url = 'ssh://{}' + url
# split off the user@ component if it's there
server = urlparse(url).netloc.split('@')[-1]
# split off an ssh-like path component if it's there
server = server.split(':')[0]
# Force https because what else could it be
gitlab_url = 'https://' + server
except git.exc.InvalidGitRepositoryError:
except AttributeError: # origin does not exist
......@@ -2,6 +2,7 @@
from click.testing import CliRunner
from unittest.mock import patch, MagicMock
import git
import pytest
from pathlib import Path
......@@ -80,17 +81,30 @@ def test_missing_url(caplog, gitlab_default_env):
def test_fdo_url_fallback(gitlab, caplog, gitlab_default_env):
def test_url_extractor(gitlab, caplog, gitlab_default_env):
args = ['delete-image', '--all', '--dry-run'] # need one subcommand
# we can't delete them, but the empty string is good enough
env = gitlab_default_env
env['CI_SERVER_URL'] = ''
env['CI_JOB_TOKEN'] = ''
runner = CliRunner(env=env)
runner.invoke(ci_fairy.ci_fairy, args)
urls = [
for url in urls:
runner = CliRunner(env=env)
# Must not be run within our git repo, otherwise it'll default to fdo
with runner.isolated_filesystem():
repo = git.Repo.init()
repo.create_remote('origin', url)
runner.invoke(ci_fairy.ci_fairy, args)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment