mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +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:
parent
c8642bedcd
commit
7955d1f579
@ -2,6 +2,7 @@
|
||||
|
||||
import inspect
|
||||
import logging
|
||||
import os
|
||||
import pathlib
|
||||
import pkgutil
|
||||
import sysconfig
|
||||
@ -116,25 +117,26 @@ def get_git_log(path):
|
||||
from InvenTree.ready import isInTestMode
|
||||
|
||||
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
|
||||
if not isInTestMode(): # pragma: no cover
|
||||
|
||||
try:
|
||||
walker = Repo.discover(path).get_walker(paths=[path.encode()], max_entries=1)
|
||||
try:
|
||||
commit = next(iter(walker)).commit
|
||||
except StopIteration:
|
||||
pass
|
||||
else:
|
||||
output = [
|
||||
commit.sha().hexdigest(),
|
||||
commit.author.decode().split('<')[0][:-1],
|
||||
commit.author.decode().split('<')[1][:-1],
|
||||
datetime.datetime.fromtimestamp(commit.author_time, ).isoformat(),
|
||||
commit.message.decode().split('\n')[0],
|
||||
]
|
||||
repo = Repo(path)
|
||||
head = repo.head()
|
||||
commit = repo[head]
|
||||
|
||||
output = [
|
||||
head.decode(),
|
||||
commit.author.decode().split('<')[0][:-1],
|
||||
commit.author.decode().split('<')[1][:-1],
|
||||
datetime.datetime.fromtimestamp(commit.author_time, ).isoformat(),
|
||||
commit.message.decode().split('\n')[0],
|
||||
]
|
||||
except NotGitRepository:
|
||||
pass
|
||||
|
||||
|
@ -348,6 +348,7 @@ class InvenTreePlugin(VersionMixin, MixinBase, MetaBase):
|
||||
# region package info
|
||||
def _get_package_commit(self):
|
||||
"""Get last git commit for the plugin."""
|
||||
|
||||
return get_git_log(str(self.file()))
|
||||
|
||||
@classmethod
|
||||
|
Loading…
Reference in New Issue
Block a user