From 1a045af24ecea64cc6276753bc7c16411e25ebd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Sat, 18 Jan 2020 15:42:54 +0100 Subject: [PATCH] Parse git user from dispatch string --- gitsrht-update-hook/submitter.go | 7 ++++++- gitsrht/blueprints/repo.py | 3 ++- gitsrht/urls.py | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/gitsrht-update-hook/submitter.go b/gitsrht-update-hook/submitter.go index d98d3b6..254de41 100644 --- a/gitsrht-update-hook/submitter.go +++ b/gitsrht-update-hook/submitter.go @@ -171,7 +171,12 @@ func (submitter GitBuildSubmitter) GetCloneUrl() string { origin := strings.ReplaceAll(submitter.GitOrigin, "http://", "") origin = strings.ReplaceAll(origin, "https://", "") // Use SSH URL - return fmt.Sprintf("git+ssh://git@%s/~%s/%s", origin, + git_user, ok := config.Get("git.sr.ht::dispatch", "/usr/bin/gitsrht-keys") + if !ok { + git_user = "git:git" + } + git_user = strings.Split(git_user, ":")[0] + return fmt.Sprintf("git+ssh://%s@%s/~%s/%s", git_user, origin, submitter.OwnerName, submitter.RepoName) } else { // Use HTTP(s) URL diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index 71813df..b0f9b3e 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -64,7 +64,8 @@ def _highlight_file(repo, ref, name, data, blob_id): def render_empty_repo(owner, repo): origin = cfg("git.sr.ht", "origin") - urls = get_clone_urls(origin, owner, repo, 'git@{origin}:{user}/{repo}') + git_user = cfg("git.sr.ht::dispatch", "/usr/bin/gitsrht-keys", "git:git").split(":")[0] + urls = get_clone_urls(origin, owner, repo, '{git_user}@{origin}:{user}/{repo}') return render_template("empty-repo.html", owner=owner, repo=repo, clone_urls=urls) diff --git a/gitsrht/urls.py b/gitsrht/urls.py index 2eca81f..b3384e7 100644 --- a/gitsrht/urls.py +++ b/gitsrht/urls.py @@ -1,14 +1,15 @@ from flask import url_for -from srht.config import get_origin +from srht.config import cfg, get_origin def clone_urls(repo): """Returns the readonly and read/write URL for a given repo.""" + git_user = cfg("git.sr.ht::dispatch", "/usr/bin/gitsrht-keys", "git:git").split(":")[0] base = (get_origin("git.sr.ht", external=True) .replace("http://", "") .replace("https://", "")) return [ url.format(base, repo.owner.canonical_name, repo.name) - for url in ["https://{}/{}/{}", "git@{}:{}/{}"] + for url in ["https://{}/{}/{}", git_user+"@{}:{}/{}"] ] def log_rss_url(repo, ref=None): -- 2.38.4