change(rendercomment): converted to use aurweb.db ORM

- Added aurweb.util.git_search.
    - Decoupled away from rendercomment for easier testability.
- Added aurweb.testing.git.GitRepository.
- Added templates/testing/{PKGBUILD,SRCINFO}.j2.
- Added aurweb.testing.git.GitRepository + `git` pytest fixture

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-17 06:20:50 -08:00
parent 4b0cb0721d
commit 2d0e09cd63
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
9 changed files with 398 additions and 195 deletions

View file

@ -13,6 +13,7 @@ from urllib.parse import urlencode, urlparse
from zoneinfo import ZoneInfo
import fastapi
import pygit2
from email_validator import EmailNotValidError, EmailUndeliverableError, validate_email
from jinja2 import pass_context
@ -193,3 +194,19 @@ def file_hash(filepath: str, hash_function: Callable) -> str:
with open(filepath, "rb") as f:
hash_ = hash_function(f.read())
return hash_.hexdigest()
def git_search(repo: pygit2.Repository, commit_hash: str) -> int:
"""
Return the shortest prefix length matching `commit_hash` found.
:param repo: pygit2.Repository instance
:param commit_hash: Full length commit hash
:return: Shortest unique prefix length found
"""
prefixlen = 12
while prefixlen < len(commit_hash):
if commit_hash[:prefixlen] in repo:
break
prefixlen += 1
return prefixlen