summaryrefslogtreecommitdiffstats
path: root/gitsrht
diff options
context:
space:
mode:
authorIvan Habunek <ivan@habunek.com>2018-11-29 12:26:39 +0100
committerDrew DeVault <sir@cmpwn.com>2018-11-30 07:49:49 -0500
commitbef092a7098f3746d8039946270d976f0a579750 (patch)
tree1762d30f29c84d54bdb7685cc93c7af80add27d0 /gitsrht
parent4f6d1a5283b5282c99aa13f08ab1ef49ca6763a3 (diff)
Extract clone_urls to a filter
Diffstat (limited to 'gitsrht')
-rw-r--r--gitsrht/app.py1
-rw-r--r--gitsrht/blueprints/repo.py15
-rw-r--r--gitsrht/templates/empty-repo.html6
-rw-r--r--gitsrht/templates/summary.html6
-rw-r--r--gitsrht/urls.py12
5 files changed, 25 insertions, 15 deletions
diff --git a/gitsrht/app.py b/gitsrht/app.py
index d1e165e..1cea729 100644
--- a/gitsrht/app.py
+++ b/gitsrht/app.py
@@ -38,6 +38,7 @@ class GitApp(SrhtFlask):
self.register_blueprint(stats)
self.register_blueprint(manage)
+ self.add_template_filter(urls.clone_urls)
self.add_template_filter(urls.log_rss_url)
self.add_template_filter(urls.refs_rss_url)
diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py
index 2648b2b..d2ca21c 100644
--- a/gitsrht/blueprints/repo.py
+++ b/gitsrht/blueprints/repo.py
@@ -108,17 +108,11 @@ def get_last_3_commits(commit):
@repo.route("/<owner>/<repo>")
def summary(owner, repo):
owner, repo = get_repo_or_redir(owner, repo)
+
with GitRepository(repo.path) as git_repo:
- base = (cfg("git.sr.ht", "origin")
- .replace("http://", "")
- .replace("https://", ""))
- clone_urls = [
- url.format(base, owner.canonical_name, repo.name)
- for url in ["https://{}/{}/{}", "git@{}:{}/{}"]
- ]
if git_repo.is_empty:
- return render_template("empty-repo.html", owner=owner, repo=repo,
- clone_urls=clone_urls)
+ return render_template("empty-repo.html", owner=owner, repo=repo)
+
default_branch = git_repo.default_branch()
tip = git_repo.get(default_branch.target)
commits = get_last_3_commits(tip)
@@ -130,8 +124,7 @@ def summary(owner, repo):
latest_tag = tags[0] if len(tags) else None
return render_template("summary.html", view="summary",
owner=owner, repo=repo, readme=readme, commits=commits,
- clone_urls=clone_urls, latest_tag=latest_tag,
- default_branch=default_branch)
+ latest_tag=latest_tag, default_branch=default_branch)
def lookup_ref(git_repo, ref):
ref = ref or git_repo.default_branch().name[len("refs/heads/"):]
diff --git a/gitsrht/templates/empty-repo.html b/gitsrht/templates/empty-repo.html
index 3a500a0..ac88cef 100644
--- a/gitsrht/templates/empty-repo.html
+++ b/gitsrht/templates/empty-repo.html
@@ -21,12 +21,14 @@
<div class="row" style="margin-bottom: 1rem">
<div class="col-md-4">
<h3>clone</h3>
+ {% with read_only, read_write = repo|clone_urls %}
<dl>
<dt>read-only</dt>
- <dd><a href="{{clone_urls[0]}}">{{clone_urls[0]}}</a></dd>
+ <dd><a href="{{read_only}}">{{read_only}}</a></dd>
<dt>read/write</dt>
- <dd>{{clone_urls[1]}}</dd>
+ <dd>{{read_write}}</dd>
</dl>
+ {% endwith %}
</div>
<div class="col-md-8">
<p>
diff --git a/gitsrht/templates/summary.html b/gitsrht/templates/summary.html
index aec08cc..fb4273e 100644
--- a/gitsrht/templates/summary.html
+++ b/gitsrht/templates/summary.html
@@ -51,12 +51,14 @@
</div>
<div class="col-md-4">
<h3>clone</h3>
+ {% with read_only, read_write = repo|clone_urls %}
<dl>
<dt>read-only</dt>
- <dd><a href="{{clone_urls[0]}}">{{clone_urls[0]}}</a></dd>
+ <dd><a href="{{read_only}}">{{read_only}}</a></dd>
<dt>read/write</dt>
- <dd>{{clone_urls[1]}}</dd>
+ <dd>{{read_write}}</dd>
</dl>
+ {% endwith %}
</div>
</div>
{% if readme %}
diff --git a/gitsrht/urls.py b/gitsrht/urls.py
index 24b4df8..d6ba6bd 100644
--- a/gitsrht/urls.py
+++ b/gitsrht/urls.py
@@ -1,4 +1,16 @@
from flask import url_for
+from srht.config import cfg
+
+def clone_urls(repo):
+ """Returns the readonly and read/write URL for a given repo."""
+ base = (cfg("git.sr.ht", "origin")
+ .replace("http://", "")
+ .replace("https://", ""))
+
+ return [
+ url.format(base, repo.owner.canonical_name, repo.name)
+ for url in ["https://{}/{}/{}", "git@{}:{}/{}"]
+ ]
def log_rss_url(repo, ref=None):
ref = ref if ref != "master" else None