此代碼用于獲取檔案夾中 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
uj5u.com熱心網友回復:
默認情況下,GitHub Actions 使用僅包含最新提交的淺層克隆進行克隆。如果您想進行任何型別的歷史探索,或者需要存盤庫中的標簽或其他提交,那么您需要使用完整的歷史進行克隆,如下所示:
- uses: actions/checkout@v2
with:
fetch-depth: 0
這在 README 中有記錄actions/checkout。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/409336.html
標籤:
