Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fallback commit_date to author date and current date #477

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion __mocks__/@actions/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,22 @@ 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,
const commit = await toolkit.github.octokit.request('GET /repos/{owner}/{repo}/commits/{ref}', {
ref: sha,
owner: GitHub.context.repo.owner,
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