diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index a0801d4..a29c18f 100644 --- a/davtelepot/__init__.py +++ b/davtelepot/__init__.py @@ -11,7 +11,7 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __license__ = "GNU General Public License v3.0" -__version__ = "2.10.10" +__version__ = "2.10.11" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/davtelepot/administration_tools.py b/davtelepot/administration_tools.py index 0bd653c..acd12c5 100644 --- a/davtelepot/administration_tools.py +++ b/davtelepot/administration_tools.py @@ -836,7 +836,8 @@ def get_maintenance_exception_criterion(bot, allowed_command): async def get_last_commit(): - """Get last commit hash and davtelepot version.""" + """Get last commit hash and message.""" + last_commit_message = None try: _subprocess = await asyncio.create_subprocess_exec( 'git', 'rev-parse', 'HEAD', @@ -844,12 +845,22 @@ async def get_last_commit(): stderr=asyncio.subprocess.STDOUT ) stdout, _ = await _subprocess.communicate() - last_commit = stdout.decode().strip() + last_commit_hash = stdout.decode().strip() except Exception as e: - last_commit = f"{e}" - if last_commit.startswith("fatal: not a git repository"): - last_commit = "-" - return last_commit + last_commit_hash = f"{e}" + try: + _subprocess = await asyncio.create_subprocess_exec( + 'git', 'log', '--pretty=%B', "-n", "1", last_commit_hash, + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.STDOUT + ) + stdout, _ = await _subprocess.communicate() + last_commit_message = stdout.decode().strip() + except Exception: + pass + if last_commit_hash.startswith("fatal: not a git repository"): + last_commit_hash = "-" + return last_commit_hash, last_commit_message async def get_new_versions(bot: Bot, @@ -899,12 +910,15 @@ async def get_new_versions(bot: Bot, async def version_command(bot: Bot, update: dict, user_record: OrderedDict, language: str): - last_commit = await get_last_commit() + last_commit_hash, last_commit_message = await get_last_commit() text = bot.get_message( 'admin', 'version_command', 'header', - last_commit=last_commit, + last_commit=last_commit_hash, update=update, user_record=user_record - ) + '\n\n' + ) + if last_commit_message: + text += "\n" + last_commit_message + "" + text += "\n\n" text += f'Python: {platform.python_version()}\n' text += '\n'.join( f"{package.__name__}: " @@ -947,7 +961,7 @@ async def notify_new_version(bot: Bot): Notify admins when last commit and/or davtelepot version change. """ - last_commit = await get_last_commit() + last_commit_hash, last_commit_message = await get_last_commit() old_record = bot.db['version_history'].find_one( order_by=['-id'] ) @@ -955,7 +969,7 @@ async def notify_new_version(bot: Bot): f"{package.__name__}_version": get_package_version(package) for package in bot.packages } - current_versions['last_commit'] = last_commit + current_versions['last_commit'] = last_commit_hash if old_record is None: old_record = dict( updated_at=datetime.datetime.min, @@ -978,13 +992,16 @@ async def notify_new_version(bot: Bot): 'admin', 'new_version', 'title', user_record=admin ) + '\n\n' - if last_commit != old_record['last_commit']: + if last_commit_hash != old_record['last_commit']: text += bot.get_message( 'admin', 'new_version', 'last_commit', old_record=old_record, new_record=current_versions, user_record=admin - ) + '\n\n' + ) + if last_commit_message: + text += f"\n{last_commit_message}" + text += "\n\n" text += '\n'.join( f"{name[:-len('_version')]}: " f"{old_record[name]} —> "