3
0
Fork 0
mirror of https://gitea.com/docker/metadata-action.git synced 2024-11-24 21:19:33 +01:00

Merge pull request #478 from crazy-max/commit-date-request

commiter_date: fix github api request fallback
This commit is contained in:
CrazyMax 2024-11-19 17:54:49 +01:00 committed by GitHub
commit 8cb0002d6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 10 deletions

View file

@ -205,5 +205,19 @@ export const context = {
}; };
export const getOctokit = jest.fn(() => ({ export const getOctokit = jest.fn(() => ({
request: () => Promise.resolve({data: {committer: {date: '2024-11-13T13:42:28Z'}}}) rest: {
repos: {
getCommit: jest.fn(() =>
Promise.resolve({
data: {
commit: {
committer: {
date: '2024-11-13T13:42:28Z'
}
}
}
})
)
}
}
})); }));

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -119,11 +119,18 @@ async function getCommitDateFromWorkflow(sha: string, toolkit: Toolkit): Promise
} }
// fallback to github api for commit date // fallback to github api for commit date
const commit = await toolkit.github.octokit.request('GET /repos/{owner}/{repo}/commits/{commit_sha}', { try {
commit_sha: sha, const commit = await toolkit.github.octokit.rest.repos.getCommit({
owner: GitHub.context.repo.owner, owner: GitHub.context.repo.owner,
repo: GitHub.context.repo.repo repo: GitHub.context.repo.repo,
}); ref: sha
});
return new Date(commit.data.committer.date); if (commit.data.commit.committer?.date) {
return new Date(commit.data.commit.committer.date);
}
throw new Error('Committer date not found');
} catch (error) {
core.debug(`Failed to get commit date from GitHub API: ${error.message}`);
return new Date();
}
} }