From 347c6134807f5849716f12d628aa914cca3267d3 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 1 Oct 2018 16:50:59 -0400 Subject: [PATCH] Add refs page --- gitsrht/blueprints/repo.py | 47 +++++++++++++++++++++- gitsrht/templates/refs.html | 77 ++++++++++++++++++++++++++++++++++++ gitsrht/templates/repo.html | 4 +- gitsrht/templates/utils.html | 4 +- 4 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 gitsrht/templates/refs.html diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index 3a27320..fa6ca54 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -194,7 +194,7 @@ def archive(owner, repo, ref): "--git-dir", repo.path, "archive", "--format=tar.gz", - "--prefix", f"{repo.name}-{ref}" + "--prefix", f"{repo.name}-{ref}", "-o", path, ref ] print(args) @@ -327,3 +327,48 @@ def patch(owner, repo, ref): print(subp.stdout, subp.stderr) return "Error preparing patch", 500 return Response(subp.stdout, mimetype='text/plain') + +@repo.route("///refs") +def refs(owner, repo): + owner, repo = get_repo(owner, repo) + if not repo: + abort(404) + if not has_access(repo, UserAccess.read): + abort(401) + git_repo = CachedRepository(repo.path) + tags = [( + ref, + git_repo.get(git_repo.references[ref].target) + ) for ref in git_repo.references if ref.startswith("refs/tags/")] + def _tag_key(tag): + if isinstance(tag[1], pygit2.Commit): + return tag[1].commit_time + return tag[1].tagger.time + tags = sorted(tags, key=_tag_key, reverse=True) + branches = [( + branch, + git_repo.branches[branch], + git_repo.get(git_repo.branches[branch].target) + ) for branch in git_repo.branches] + branches = sorted(branches, key=lambda b: b[2].commit_time, reverse=True) + + results_per_page = 10 + page = request.args.get("page") + total_results = len(tags) + total_pages = total_results // results_per_page + 1 + if total_results % results_per_page == 0: + total_pages -= 1 + if page is not None: + try: + page = int(page) - 1 + tags = tags[page*results_per_page:page*results_per_page+results_per_page] + except: + page = 0 + else: + page = 0 + tags = tags[:results_per_page] + + return render_template("refs.html", view="refs", + owner=owner, repo=repo, tags=tags, branches=branches, + git_repo=git_repo, isinstance=isinstance, pygit2=pygit2, + page=page + 1, total_pages=total_pages) diff --git a/gitsrht/templates/refs.html b/gitsrht/templates/refs.html new file mode 100644 index 0000000..4a7c985 --- /dev/null +++ b/gitsrht/templates/refs.html @@ -0,0 +1,77 @@ +{% extends "repo.html" %} +{% import "utils.html" as utils %} +{% block title %} +{{repo.owner.canonical_name}}/{{repo.name}} refs - {{cfg("sr.ht", "site-name")}} git +{% endblock %} +{% block content %} +
+
+
+
+ {% for tag in tags %} + {% set ref = tag[0] %} + {% set tag = tag[1] %} + {% if isinstance(tag, pygit2.Commit) %} + {% set commit = tag %} + {% else %} + {% set commit = git_repo.get(tag.target) %} + {% endif %} +
+

+ {% if isinstance(tag, pygit2.Commit) %} + {{ref[len("refs/tags/"):]}} + {% else %} + + {{tag.name}} + + {% endif %} + + {{commit_time(tag) | date}} + .tar.gz {{icon("caret-right")}} + browse {{icon("caret-right")}} + +

+ {% if tag.message %} +
{{tag.message}}
+ {% endif %} +
+ {% endfor %} + {{ pagination() }} +
+
+
+

Branches

+
+ {% for branch in branches %} + {% set name = branch[0] %} + {% set commit = branch[2] %} + {% set branch = branch[1] %} +
+ {{name}} + {{ utils.commit_event(repo, commit, commit_time, + trim_commit, skip_body=True) }} + browse {{icon("caret-right")}} +
+ {% endfor %} +
+
+
+
+{% endblock %} diff --git a/gitsrht/templates/repo.html b/gitsrht/templates/repo.html index f0b1997..82e2014 100644 --- a/gitsrht/templates/repo.html +++ b/gitsrht/templates/repo.html @@ -31,7 +31,9 @@ repo=repo.name), "log")}}