From ff01082c30a275fda4972235bfd1085605587574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sun, 6 Sep 2020 00:02:49 +0200 Subject: [PATCH] Move {git,hg}_new_GET into common handler; use correct origin for /~u/p/{git,hg}/new Ref: ~sircmpwn/hg.sr.ht/39 --- hubsrht/blueprints/sources.py | 30 +++++++++++---------------- hubsrht/templates/sources-select.html | 3 +-- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/hubsrht/blueprints/sources.py b/hubsrht/blueprints/sources.py index d0f8bba..f001a87 100644 --- a/hubsrht/blueprints/sources.py +++ b/hubsrht/blueprints/sources.py @@ -3,6 +3,7 @@ from hubsrht.projects import ProjectAccess, get_project from hubsrht.services import git, hg from hubsrht.types import Event, EventType from hubsrht.types import RepoType, SourceRepo, Visibility +from srht.config import get_origin from srht.database import db from srht.flask import paginate_query from srht.oauth import current_user, loginrequired @@ -42,35 +43,28 @@ def new_GET(owner, project_name): return render_template("sources-new.html", view="new-resource", owner=owner, project=project) -@sources.route("///git/new") -@loginrequired -def git_new_GET(owner, project_name): +def src_new_GET(owner, project_name, vcs, service, repo_type): owner, project = get_project(owner, project_name, ProjectAccess.write) # TODO: Pagination - repos = git.get_repos(owner) + repos = service.get_repos(owner) repos = sorted(repos, key=lambda r: r["updated"], reverse=True) existing = [r.remote_id for r in (SourceRepo.query .filter(SourceRepo.project_id == project.id) - .filter(SourceRepo.repo_type == RepoType.git)).all()] + .filter(SourceRepo.repo_type == repo_type)).all()] return render_template("sources-select.html", - view="new-resource", vcs="git", + view="new-resource", vcs=vcs, owner=owner, project=project, repos=repos, - existing=existing) + existing=existing, origin=get_origin(f"{vcs}.sr.ht", external=True)) + +@sources.route("///git/new") +@loginrequired +def git_new_GET(owner, project_name): + return src_new_GET(owner, project_name, "git", git, RepoType.git) @sources.route("///hg/new") @loginrequired def hg_new_GET(owner, project_name): - owner, project = get_project(owner, project_name, ProjectAccess.write) - # TODO: Pagination - repos = hg.get_repos(owner) - repos = sorted(repos, key=lambda r: r["updated"], reverse=True) - existing = [r.remote_id for r in (SourceRepo.query - .filter(SourceRepo.project_id == project.id) - .filter(SourceRepo.repo_type == RepoType.hg)).all()] - return render_template("sources-select.html", - view="new-resource", vcs="hg", - owner=owner, project=project, repos=repos, - existing=existing) + return src_new_GET(owner, project_name, "hg", hg, RepoType.hg) @sources.route("///git/new", methods=["POST"]) @loginrequired diff --git a/hubsrht/templates/sources-select.html b/hubsrht/templates/sources-select.html index e645f4b..2397020 100644 --- a/hubsrht/templates/sources-select.html +++ b/hubsrht/templates/sources-select.html @@ -74,8 +74,7 @@ >Select repo {{ icon("caret-right") }} {% endif %} {{ repo["name"] }}