summaryrefslogtreecommitdiffstats
path: root/gitsrht
diff options
context:
space:
mode:
authorLudovic Chabant <ludovic@chabant.com>2019-01-16 05:32:03 +0000
committerLudovic Chabant <ludovic@chabant.com>2019-01-22 05:51:21 +0000
commit74503fc2188c4978c4baf92b29389ccde9d89376 (patch)
tree76b1db7619d43f5fa7ae3d0a2bde14045fb948d4 /gitsrht
parent97248eae33e8a3d921a247b8bf11282c4e884eb8 (diff)
Remove templates and formatting code available in scmsrht
Diffstat (limited to 'gitsrht')
-rw-r--r--gitsrht/blueprints/repo.py75
-rw-r--r--gitsrht/templates/create.html89
-rw-r--r--gitsrht/templates/empty-repo.html40
-rw-r--r--gitsrht/templates/oauth-error.html7
-rw-r--r--gitsrht/templates/settings.html22
-rw-r--r--gitsrht/templates/settings_access.html94
-rw-r--r--gitsrht/templates/settings_delete.html22
-rw-r--r--gitsrht/templates/settings_info.html83
-rw-r--r--gitsrht/templates/settings_rename.html31
-rw-r--r--gitsrht/templates/user.html80
10 files changed, 25 insertions, 518 deletions
diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py
index 205304a..701ec5f 100644
--- a/gitsrht/blueprints/repo.py
+++ b/gitsrht/blueprints/repo.py
@@ -17,7 +17,9 @@ from pygments import highlight
from pygments.lexers import guess_lexer, guess_lexer_for_filename, TextLexer
from pygments.formatters import HtmlFormatter
from scmsrht.access import get_repo, get_repo_or_redir, has_access, UserAccess
+from scmsrht.formatting import get_formatted_readme, get_highlighted_file
from scmsrht.redis import redis
+from scmsrht.urls import get_clone_urls
from srht.config import cfg
from srht.markdown import markdown
@@ -36,59 +38,32 @@ def authorize_http_access():
return "authorized", 200
def get_readme(repo, tip):
- if not tip or not "README.md" in tip.tree:
- return None
- readme = tip.tree["README.md"]
- if readme.type != "blob":
- return None
- key = f"git.sr.ht:git:markdown:{readme.id.hex}:v3"
- html = redis.get(key)
- if html:
- return Markup(html.decode())
- try:
- md = repo.get(readme.id).data.decode()
- except:
- md = "Error decoding readme - is it valid UTF-8?"
- html = markdown(md, ["h1", "h2", "h3", "h4", "h5"])
- redis.setex(key, timedelta(days=7), html)
- return Markup(html)
-
-def _get_shebang(data):
- if not data.startswith('#!'):
+ if not tip:
return None
- endline = data.find('\n')
- if endline == -1:
- shebang = data
- else:
- shebang = data[:endline]
+ def file_finder(name):
+ try:
+ blob = tip.tree[name]
+ except KeyError:
+ return None
- return shebang
+ if blob and blob.type == "blob":
+ return blob.id.hex, blob
+ return None
-def _get_lexer(name, data):
- try:
- return guess_lexer_for_filename(name, data)
- except pygments.util.ClassNotFound:
- try:
- shebang = _get_shebang(data)
- if not shebang:
- return TextLexer()
+ def content_getter(blob):
+ return repo.get(blob.id).data.decode()
- return guess_lexer(shebang)
- except pygments.util.ClassNotFound:
- return TextLexer()
+ return get_formatted_readme("git.sr.ht:git", file_finder, content_getter)
def _highlight_file(name, data, blob_id):
- key = f"git.sr.ht:git:highlight:{blob_id}"
- html = redis.get(key)
- if html:
- return Markup(html.decode())
- lexer = _get_lexer(name, data)
- formatter = HtmlFormatter()
- style = formatter.get_style_defs('.highlight')
- html = f"<style>{style}</style>" + highlight(data, lexer, formatter)
- redis.setex(key, timedelta(days=7), html)
- return Markup(html)
+ return get_highlighted_file("git.sr.ht:git", name, blob_id, data)
+
+def render_empty_repo(owner, repo):
+ origin = cfg("git.sr.ht", "origin")
+ urls = get_clone_urls(origin, owner, repo, 'git@{origin}:{user}/{repo}')
+ return render_template("empty-repo.html", owner=owner, repo=repo,
+ clone_urls=urls)
def get_last_3_commits(commit):
commits = [commit]
@@ -106,7 +81,7 @@ def summary(owner, repo):
with GitRepository(repo.path) as git_repo:
if git_repo.is_empty:
- return render_template("empty-repo.html", owner=owner, repo=repo)
+ return render_empty_repo(owner, repo)
default_branch = git_repo.default_branch()
tip = git_repo.get(default_branch.target)
@@ -157,7 +132,7 @@ def tree(owner, repo, ref, path):
owner, repo = get_repo_or_redir(owner, repo)
with GitRepository(repo.path) as git_repo:
if git_repo.is_empty:
- return render_template("empty-repo.html", owner=owner, repo=repo)
+ return render_empty_repo(owner, repo)
commit, ref, path = lookup_ref(git_repo, ref, path)
@@ -313,7 +288,7 @@ def log(owner, repo, ref, path):
owner, repo = get_repo_or_redir(owner, repo)
with GitRepository(repo.path) as git_repo:
if git_repo.is_empty:
- return render_template("empty-repo.html", owner=owner, repo=repo)
+ return render_empty_repo(owner, repo)
commit, ref, path = lookup_ref(git_repo, ref, path)
refs = collect_refs(git_repo)
@@ -392,7 +367,7 @@ def refs(owner, repo):
owner, repo = get_repo_or_redir(owner, repo)
with GitRepository(repo.path) as git_repo:
if git_repo.is_empty:
- return render_template("empty-repo.html", owner=owner, repo=repo)
+ return render_empty_repo(owner, repo)
tags = [(
ref,
diff --git a/gitsrht/templates/create.html b/gitsrht/templates/create.html
deleted file mode 100644
index bf468a2..0000000
--- a/gitsrht/templates/create.html
+++ /dev/null
@@ -1,89 +0,0 @@
-{% extends "git.html" %}
-{% block content %}
-<div class="container">
- <div class="row">
- <section class="col-md-6">
- <h3 id="create">Create new repository</h3>
- <form method="POST" action="/create">
- {{csrf_token()}}
- <div class="form-group">
- <label for="name">Name</label>
- <input
- {% if another %}
- autofocus
- {% endif %}
- type="text"
- name="name"
- id="name"
- class="form-control {{valid.cls("name")}}"
- value="{{ repo_name or "" }}" />
- {{valid.summary("name")}}
- </div>
- <div class="form-group">
- <label for="description">Description</label>
- <input
- type="text"
- name="description"
- id="description"
- class="form-control {{valid.cls("description")}}"
- value="{{ repo_description or "" }}" />
- {{valid.summary("description")}}
- </div>
- <fieldset class="form-group">
- <legend>Visibility</legend>
- <div class="form-check form-check-inline">
- <label
- class="form-check-label"
- title="Publically visible and listed on your profile"
- >
- <input
- class="form-check-input"
- type="radio"
- name="visibility"
- value="public"
- checked> Public
- </label>
- </div>
- <div class="form-check form-check-inline">
- <label
- class="form-check-label"
- title="Visible to anyone with the link, but not shown on your profile"
- >
- <input
- class="form-check-input"
- type="radio"
- name="visibility"
- value="unlisted"> Unlisted
- </label>
- </div>
- <div class="form-check form-check-inline">
- <label
- class="form-check-label"
- title="Only visible to you and your collaborators"
- >
- <input
- class="form-check-input"
- type="radio"
- name="visibility"
- value="private"> Private
- </label>
- </div>
- </fieldset>
- <button type="submit" class="btn btn-primary">
- Create {{icon("caret-right")}}
- </button>
- <label class="form-check-label" style="margin-left: 2rem">
- <input
- class="form-check-input"
- type="checkbox"
- name="another"
- style="position: relative; top: 2px;"
- {% if another %}
- checked
- {% endif %}> Create another?
- </label>
- </form>
- </section>
- </div>
-</div>
-{% endblock %}
diff --git a/gitsrht/templates/empty-repo.html b/gitsrht/templates/empty-repo.html
deleted file mode 100644
index ac88cef..0000000
--- a/gitsrht/templates/empty-repo.html
+++ /dev/null
@@ -1,40 +0,0 @@
-{% extends "repo.html" %}
-{% block tabs %}
-<ul class="nav nav-tabs">
- <li class="nav-item">
- <a class="nav-link active">summary</a>
- </li>
- {% if current_user.id == repo.owner_id %}
- <li class="nav-item">
- <a
- class="nav-link"
- href="{{url_for("manage.settings_info",
- owner_name=repo.owner.canonical_name,
- repo_name=repo.name)}}"
- >settings</a>
- </li>
- {% endif %}
-</ul>
-{% endblock %}
-{% block content %}
-<div class="container">
- <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="{{read_only}}">{{read_only}}</a></dd>
- <dt>read/write</dt>
- <dd>{{read_write}}</dd>
- </dl>
- {% endwith %}
- </div>
- <div class="col-md-8">
- <p>
- Nothing here yet!
- </p>
- </div>
- </div>
-</div>
-{% endblock %}
diff --git a/gitsrht/templates/oauth-error.html b/gitsrht/templates/oauth-error.html
deleted file mode 100644
index 5cb7f38..0000000
--- a/gitsrht/templates/oauth-error.html
+++ /dev/null
@@ -1,7 +0,0 @@
-{% extends "git.html" %}
-{% block content %}
-<div class="container">
- <h2>Error logging in</h2>
- <p>{{ details }}</p>
-</div>
-{% endblock %}
diff --git a/gitsrht/templates/settings.html b/gitsrht/templates/settings.html
deleted file mode 100644
index b76a48b..0000000
--- a/gitsrht/templates/settings.html
+++ /dev/null
@@ -1,22 +0,0 @@
-{% extends "layout.html" %}
-{% block body %}
-<div class="container-fluid">
- <div class="row">
- <div class="col-md-12 header-tabbed">
- <h2>
- <a
- href="/{{ owner.canonical_name }}"
- >{{ owner.canonical_name }}</a>/{{ repo.name }}
- </h2>
- <ul class="nav nav-tabs">
- {% block tabs %}
- {% include "tabs.html" %}
- {% endblock %}
- </ul>
- </div>
- </div>
-</div>
-<div class="container">
- {% block content %}{% endblock %}
-</div>
-{% endblock %}
diff --git a/gitsrht/templates/settings_access.html b/gitsrht/templates/settings_access.html
deleted file mode 100644
index edee2bf..0000000
--- a/gitsrht/templates/settings_access.html
+++ /dev/null
@@ -1,94 +0,0 @@
-{% extends "settings.html" %}
-{% block content %}
-<div class="row">
- <div class="col-md-8">
- {% if len(repo.access_grants) > 0 %}
- <table class="table">
- <thead>
- <tr>
- <th>user</th>
- <th>granted</th>
- <th>last used</th>
- <th>access</th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- {% for grant in repo.access_grants %}
- <tr>
- <td>
- <a href="/~{{ grant.user.username }}">~{{grant.user.username}}</a>
- </td>
- <td>{{ grant.created | date }}</td>
- <td>{{ grant.created | date }}</td>
- <td>{{ grant.mode.value }}</td>
- <td style="width: 6rem">
- <form
- method="POST"
- action="/~{{owner.username}}/{{
- repo.name
- }}/settings/access/revoke/{{ grant.id }}"
- >
- {{csrf_token()}}
- <button type="submit" class="btn btn-danger btn-fill">Revoke</button>
- </form>
- </td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
- <h4>Grant Access</h4>
- {% endif %}
- <form method="POST">
- {{csrf_token()}}
- <div class="form-group">
- <label for="user">User</label>
- <input
- type="text"
- class="form-control {{valid.cls("user")}}"
- id="user"
- name="user"
- placeholder="~{{ current_user.username }}"
- value="{{user or ""}}"
- />
- {{valid.summary("user")}}
- </div>
- <fieldset class="form-group">
- <legend>Access</legend>
- <!-- This is in a weird spot cause it looks better over here -->
- <button type="submit" class="btn btn-primary pull-right">
- Grant access {{icon("caret-right")}}
- </button>
- <div class="form-check form-check-inline">
- <label
- class="form-check-label"
- title="Can view on the web and clone the repository"
- >
- <input
- class="form-check-input"
- type="radio"
- name="access"
- value="ro"
- {{ "checked" if not access or access.value == "ro" else "" }}
- > Read only
- </label>
- </div>
- <div class="form-check form-check-inline">
- <label
- class="form-check-label"
- title="Can push commits to the repository"
- >
- <input
- class="form-check-input"
- type="radio"
- name="access"
- value="rw"
- {{ "checked" if access and access.value == "rw" else "" }}
- > Read/write
- </label>
- </div>
- </fieldset>
- </form>
- </div>
-</div>
-{% endblock %}
diff --git a/gitsrht/templates/settings_delete.html b/gitsrht/templates/settings_delete.html
deleted file mode 100644
index 3105acc..0000000
--- a/gitsrht/templates/settings_delete.html
+++ /dev/null
@@ -1,22 +0,0 @@
-{% extends "settings.html" %}
-{% block content %}
-<div class="row">
- <div class="col-md-12">
- <p>
- This will permanently delete your repository,
- <strong>{{ owner.canonical_name }}/{{ repo.name }}</strong>.
- This cannot be undone.
- </p>
- <form method="POST">
- {{csrf_token()}}
- <button type="submit" class="btn btn-danger">
- Proceed and delete {{icon("caret-right")}}
- </button>
- <a
- href="/{{ owner.canonical_name }}/{{ repo.name }}"
- class="btn btn-default"
- >Nevermind</a>
- </form>
- </div>
-</div>
-{% endblock %}
diff --git a/gitsrht/templates/settings_info.html b/gitsrht/templates/settings_info.html
deleted file mode 100644
index cda7286..0000000
--- a/gitsrht/templates/settings_info.html
+++ /dev/null
@@ -1,83 +0,0 @@
-{% extends "settings.html" %}
-{% block content %}
-<div class="row">
- <div class="col-md-6">
- <form method="POST">
- {{csrf_token()}}
- <div class="form-group">
- <label for="name" style="display: block">
- Repository name
- <a
- href="/{{ owner.canonical_name }}/{{ repo.name }}/settings/rename"
- class="pull-right"
- >Rename?</a>
- </label>
- <input
- type="text"
- class="form-control"
- id="name"
- value="{{repo.name}}"
- readonly />
- </div>
- <div class="form-group">
- <label for="description">
- Description
- </label>
- <input
- type="text"
- class="form-control"
- id="description"
- name="description"
- value="{{repo.description}}" />
- </div>
- <fieldset class="form-group">
- <div class="form-check form-check-inline">
- <label
- class="form-check-label"
- title="Publically visible and listed on your profile"
- >
- <input
- class="form-check-input"
- type="radio"
- name="visibility"
- value="public"
- {{ "checked" if repo.visibility.value == "public" else "" }}
- > Public
- </label>
- </div>
- <div class="form-check form-check-inline">
- <label
- class="form-check-label"
- title="Visible to anyone with the link, but not shown on your profile"
- >
- <input
- class="form-check-input"
- type="radio"
- name="visibility"
- value="unlisted"
- {{ "checked" if repo.visibility.value == "unlisted" else "" }}
- > Unlisted
- </label>
- </div>
- <div class="form-check form-check-inline">
- <label
- class="form-check-label"
- title="Only visible to you and your collaborators"
- >
- <input
- class="form-check-input"
- type="radio"
- name="visibility"
- value="private"
- {{ "checked" if repo.visibility.value == "private" else "" }}
- > Private
- </label>
- </div>
- </fieldset>
- <button type="submit" class="btn btn-primary pull-right">
- Save {{icon("caret-right")}}
- </button>
- </form>
- </div>
-</div>
-{% endblock %}
diff --git a/gitsrht/templates/settings_rename.html b/gitsrht/templates/settings_rename.html
deleted file mode 100644
index 613be55..0000000
--- a/gitsrht/templates/settings_rename.html
+++ /dev/null
@@ -1,31 +0,0 @@
-{% extends "settings.html" %}
-{% block content %}
-<div class="row">
- <div class="col-md-6">
- <h3>Rename Repository</h3>
- <form method="POST">
- {{csrf_token()}}
- <div class="form-group">
- <label for="name" style="display: block">
- New repository name:
- </label>
- <input
- type="text"
- class="form-control {{valid.cls('name')}}"
- id="name"
- name="name"
- value="{{name or repo.name}}" />
- {{valid.summary('name')}}
- </div>
- <p>
- This will change the canonical URL of your repository. A redirect from
- the old URL to the new one will be in place until you create another
- repository with the same name.
- </p>
- <button type="submit" class="btn btn-primary pull-right">
- Rename repository {{icon("caret-right")}}
- </button>
- </form>
- </div>
-</div>
-{% endblock %}
diff --git a/gitsrht/templates/user.html b/gitsrht/templates/user.html
deleted file mode 100644
index 8a0c0d1..0000000
--- a/gitsrht/templates/user.html
+++ /dev/null
@@ -1,80 +0,0 @@
-{% extends "git.html" %}
-{% block content %}
-<div class="container">
- <div class="row">
- <section class="col-md-4">
- <h2>
- ~{{ user.username }}
- </h2>
- {% if profile %}
- {% if profile.get("location") %}
- <p>{{profile["location"]}}</p>
- {% endif %}
- {% if profile.get("url") %}
- <p>
- <a href="{{profile["url"]}}" target="_blank">
- {{profile["url"]}}
- </a>
- </p>
- {% endif %}
- {% if profile.get("bio") %}
- {{profile["bio"] | md}}
- {% endif %}
- {% endif %}
- {% if notice %}
- <div class="alert alert-success">
- {{ notice }}
- </div>
- {% endif %}
- </section>
- <section class="col-md-8">
- {% if len(repos) == 0 %}
- {% if search %}
- <form>
- <input
- name="search"
- type="text"
- placeholder="Search"
- class="form-control"
- value="{{ search if search else "" }}" />
- </form>
- <p>Nothing found.</p>
- {% else %}
- <p>This user has no repositories.</p>
- {% endif %}
- {% else %}
- <form>
- <input
- name="search"
- type="text"
- placeholder="Search"
- class="form-control"
- value="{{ search if search else "" }}" />
- </form>
- <div class="event-list">
- {% for repo in repos %}
- <div class="event">
- <h4>
- <a href="/~{{user.username}}/{{repo.name}}">
- ~{{user.username}}/{{repo.name}}
- </a>
- {% if repo.visibility.value != 'public' %}
- <small class="pull-right">
- {{ repo.visibility.value }}
- </small>
- {% endif %}
- </h4>
- {% if repo.description %}
- <p>{{ repo.description }}</p>
- {% endif %}
- <p>
- </p>
- </div>
- {% endfor %}
- </div>
- {% endif %}
- {{ pagination() }}
- </section>
- </div>
-</div>
-{% endblock %}