From dbbbad542b74bcdab378a51b91283281ad4f4eb7 Mon Sep 17 00:00:00 2001 From: harjani Date: Wed, 4 Sep 2024 19:18:57 +0000 Subject: [PATCH] pw_cli: Add in option to retrieve commit date MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding in a function to get a datetime object of the commit author time. Test: Passes presubmit checks Change-Id: I1818e2f8453fe4dd0c687d7c8e83f8992f08ca69 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/216275 Reviewed-by: Erik Gilling Reviewed-by: Samuel Liu Lint: Lint 🤖 Commit-Queue: Auto-Submit Reviewed-by: Anthony DiGirolamo Pigweed-Auto-Submit: Armando Montanez --- pw_cli/py/pw_cli/git_repo.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pw_cli/py/pw_cli/git_repo.py b/pw_cli/py/pw_cli/git_repo.py index 57773fb189..84138f2aa2 100644 --- a/pw_cli/py/pw_cli/git_repo.py +++ b/pw_cli/py/pw_cli/git_repo.py @@ -13,6 +13,7 @@ # the License. """Helpful commands for working with a Git repository.""" +from datetime import datetime import logging from pathlib import Path import re @@ -276,6 +277,18 @@ def commit_author(self, commit: str = 'HEAD') -> str: """ return self._git('log', '--format=%ae', '-n1', commit) + def commit_date(self, commit: str = 'HEAD') -> datetime: + """Returns the datetime of the specified commit. + + Defaults to ``HEAD`` if no commit specified. + + Returns: + Commit datetime as a datetime object. + """ + return datetime.fromisoformat( + self._git('log', '--format=%aI', '-n1', commit) + ) + def commit_hash( self, commit: str = 'HEAD',