【发布时间】:2022-01-10 21:22:57
【问题描述】:
此代码用于获取文件夹中 GitHub 文件的最新提交日期。这在我的本地机器上工作,但在 Github 操作中不起作用。在 Github 操作中,它为所有文件提供相同的日期。有什么办法可以解决吗?
import git
from datetime import datetime
from git.objects.commit import Commit
def get_date(epoch_time):
return datetime.fromtimestamp(epoch_time)
submissionDate_fileName = {}
dir_path = os.path.dirname(os.path.realpath(__file__))
repo = git.Repo(dir_path)
tree = repo.tree()
for blob in tree.trees[1]:
commit = next(repo.iter_commits(paths=blob.path, max_count=1))
date = str(get_date(commit.committed_date))[:10]
submissionDate_fileName[blob.name] = date
【问题讨论】:
标签: python github github-actions gitpython