From ed118f6653c714cb2f8a8c6f4f43e9a1e4de919c Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 23 Aug 2021 11:27:40 +0200 Subject: [PATCH] refs: include strip_pgp_signature in template --- gitsrht/blueprints/artifacts.py | 4 +++- gitsrht/blueprints/repo.py | 10 +--------- gitsrht/git.py | 8 ++++++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/gitsrht/blueprints/artifacts.py b/gitsrht/blueprints/artifacts.py index b35fb3f..a5c2e79 100644 --- a/gitsrht/blueprints/artifacts.py +++ b/gitsrht/blueprints/artifacts.py @@ -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", diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index 9066544..a043c02 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -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("///refs") def refs(owner, repo): owner, repo = get_repo_or_redir(owner, repo) diff --git a/gitsrht/git.py b/gitsrht/git.py index 9d7b77e..e32bcfe 100644 --- a/gitsrht/git.py +++ b/gitsrht/git.py @@ -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 -- 2.38.4