2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 19:46:46 +00:00

Get git log fix (#5113)

* Simplify extraction of git repo

- Replace Repo.discover() with Repo()
- Ensure provided path is directory

* Remove profiling code
This commit is contained in:
Oliver 2023-06-30 13:43:54 +10:00 committed by GitHub
parent c8642bedcd
commit 7955d1f579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 14 deletions

View File

@ -2,6 +2,7 @@
import inspect import inspect
import logging import logging
import os
import pathlib import pathlib
import pkgutil import pkgutil
import sysconfig import sysconfig
@ -116,25 +117,26 @@ def get_git_log(path):
from InvenTree.ready import isInTestMode from InvenTree.ready import isInTestMode
output = None output = None
path = path.replace(str(settings.BASE_DIR.parent), '')[1:] path = os.path.abspath(path)
if os.path.exists(path) and os.path.isfile(path):
path = os.path.dirname(path)
# only do this if we are not in test mode # only do this if we are not in test mode
if not isInTestMode(): # pragma: no cover if not isInTestMode(): # pragma: no cover
try: try:
walker = Repo.discover(path).get_walker(paths=[path.encode()], max_entries=1) repo = Repo(path)
try: head = repo.head()
commit = next(iter(walker)).commit commit = repo[head]
except StopIteration:
pass output = [
else: head.decode(),
output = [ commit.author.decode().split('<')[0][:-1],
commit.sha().hexdigest(), commit.author.decode().split('<')[1][:-1],
commit.author.decode().split('<')[0][:-1], datetime.datetime.fromtimestamp(commit.author_time, ).isoformat(),
commit.author.decode().split('<')[1][:-1], commit.message.decode().split('\n')[0],
datetime.datetime.fromtimestamp(commit.author_time, ).isoformat(), ]
commit.message.decode().split('\n')[0],
]
except NotGitRepository: except NotGitRepository:
pass pass

View File

@ -348,6 +348,7 @@ class InvenTreePlugin(VersionMixin, MixinBase, MetaBase):
# region package info # region package info
def _get_package_commit(self): def _get_package_commit(self):
"""Get last git commit for the plugin.""" """Get last git commit for the plugin."""
return get_git_log(str(self.file())) return get_git_log(str(self.file()))
@classmethod @classmethod