~edwargix/git.sr.ht

ed118f6653c714cb2f8a8c6f4f43e9a1e4de919c — Drew DeVault 3 years ago 33df248
refs: include strip_pgp_signature in template
3 files changed, 12 insertions(+), 10 deletions(-)

M gitsrht/blueprints/artifacts.py
M gitsrht/blueprints/repo.py
M gitsrht/git.py
M gitsrht/blueprints/artifacts.py => gitsrht/blueprints/artifacts.py +3 -1
@@ 3,7 3,7 @@ import os
import pygit2
from flask import Blueprint, redirect, render_template, request, redirect
from flask import abort, url_for, send_file
from gitsrht.git import Repository as GitRepository
from gitsrht.git import Repository as GitRepository, strip_pgp_signature
from gitsrht.repos import delete_artifact, upload_artifact
from gitsrht.types import Artifact
from minio import Minio


@@ 44,11 44,13 @@ def ref_upload(owner, repo, ref):
        if not valid.ok:
            return render_template("ref.html", view="refs",
                    owner=owner, repo=repo, git_repo=git_repo, tag=tag,
                    strip_pgp_signature=strip_pgp_signature,
                    default_branch=default_branch, **valid.kwargs)
        artifact = upload_artifact(valid, repo, target, f, f.filename)
        if not valid.ok:
            return render_template("ref.html", view="refs",
                    owner=owner, repo=repo, git_repo=git_repo, tag=tag,
                    strip_pgp_signature=strip_pgp_signature,
                    default_branch=default_branch, **valid.kwargs)
        db.session.commit()
        return redirect(url_for("repo.ref",

M gitsrht/blueprints/repo.py => gitsrht/blueprints/repo.py +1 -9
@@ 10,7 10,7 @@ from flask import Blueprint, render_template, abort, current_app, send_file, req
from flask import Response, url_for, session, redirect
from gitsrht.editorconfig import EditorConfig
from gitsrht.git import Repository as GitRepository, commit_time, annotate_tree
from gitsrht.git import diffstat, get_log, diff_for_commit
from gitsrht.git import diffstat, get_log, diff_for_commit, strip_pgp_signature
from gitsrht.rss import generate_feed
from gitsrht.types import Artifact
from io import BytesIO


@@ 495,14 495,6 @@ def patch(owner, repo, ref):
            return "Error preparing patch", 500
        return Response(subp.stdout, mimetype='text/plain')

def strip_pgp_signature(text):
    if not text.strip().endswith("-----END PGP SIGNATURE-----"):
        return text
    i = text.rindex('-----BEGIN PGP SIGNATURE-----')
    if i < 0:
        return text
    return text[:i]

@repo.route("/<owner>/<repo>/refs")
def refs(owner, repo):
    owner, repo = get_repo_or_redir(owner, repo)

M gitsrht/git.py => gitsrht/git.py +8 -0
@@ 6,6 6,14 @@ from stat import filemode
import pygit2
import json

def strip_pgp_signature(text):
    if not text.strip().endswith("-----END PGP SIGNATURE-----"):
        return text
    i = text.rindex('-----BEGIN PGP SIGNATURE-----')
    if i < 0:
        return text
    return text[:i]

def trim_commit(msg):
    if "\n" not in msg:
        return msg