Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tagbot/action/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ def merge_and_delete_branch(self, branch: str) -> None:
def time_of_commit(self, sha: str, repo: str = "") -> datetime:
"""Get the time that a commit was made."""
# The format %cI is "committer date, strict ISO 8601 format".
date = self.command("show", "-s", "--format=%cI", sha, repo=repo)
# Use git log with ^{commit} to dereference tags to their underlying commit,
# since git show on annotated tags outputs the tag message before the commit.
date = self.command("log", "-1", "--format=%cI", f"{sha}^{{commit}}", repo=repo)
parsed = parse_git_datetime(date)
if not parsed:
logger.warning(
Expand Down
2 changes: 1 addition & 1 deletion test/action/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_merge_and_delete_branch():
def test_time_of_commit():
g = _git(command="2019-12-22T12:49:26+07:00")
assert g.time_of_commit("a") == datetime(2019, 12, 22, 5, 49, 26)
g.command.assert_called_with("show", "-s", "--format=%cI", "a", repo="")
g.command.assert_called_with("log", "-1", "--format=%cI", "a^{commit}", repo="")


@patch("subprocess.run")
Expand Down