mirror of
https://github.com/docker/metadata-action.git
synced 2025-03-13 12:50:15 +08:00
fix: fallback to author date and current date
Signed-off-by: Trim21 <trim21.me@gmail.com>
This commit is contained in:
parent
359e915ab3
commit
c8b97615be
@ -205,5 +205,5 @@ export const context = {
|
||||
};
|
||||
|
||||
export const getOctokit = jest.fn(() => ({
|
||||
request: () => Promise.resolve({data: {committer: {date: '2024-11-13T13:42:28Z'}}})
|
||||
request: () => Promise.resolve({data: {commit: {committer: {date: '2024-11-13T13:42:28Z'}}}})
|
||||
}));
|
||||
|
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -118,6 +118,8 @@ async function getCommitDateFromWorkflow(sha: string, toolkit: Toolkit): Promise
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(`fetch commit ${sha} metadata from ${GitHub.context.repo.owner}/${GitHub.context.repo.repo}`);
|
||||
|
||||
// fallback to github api for commit date
|
||||
const commit = await toolkit.github.octokit.request('GET /repos/{owner}/{repo}/commits/{commit_sha}', {
|
||||
commit_sha: sha,
|
||||
@ -125,5 +127,13 @@ async function getCommitDateFromWorkflow(sha: string, toolkit: Toolkit): Promise
|
||||
repo: GitHub.context.repo.repo
|
||||
});
|
||||
|
||||
return new Date(commit.data.committer.date);
|
||||
const apiCommitDate = commit.data.commit.committer?.date ?? commit.data.commit.author?.date;
|
||||
if (apiCommitDate) {
|
||||
return new Date(apiCommitDate);
|
||||
}
|
||||
|
||||
core.debug(`failed to find commit date, ${JSON.stringify(commit.data)}`);
|
||||
|
||||
core.warning(`failed to get commit date for ${sha}, fallback to current date`);
|
||||
return new Date();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user