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

feat: add variable commit_date #471

Merged
merged 1 commit into from
Nov 18, 2024
Merged

Conversation

trim21
Copy link
Contributor

@trim21 trim21 commented Nov 13, 2024

No description provided.

@crazy-max
Copy link
Member

#470 has been merged, can you rebase please?

@trim21
Copy link
Contributor Author

trim21 commented Nov 13, 2024

I find a problem, we add Git.commitDate as async function but everything in Meta is synchronously...

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/meta.ts Outdated Show resolved Hide resolved
src/meta.ts Outdated Show resolved Hide resolved
src/meta.ts Outdated Show resolved Hide resolved
src/meta.ts Outdated Show resolved Hide resolved
@trim21 trim21 force-pushed the commit-date branch 3 times, most recently from 25df83a to 02b92e6 Compare November 13, 2024 14:11
@trim21 trim21 marked this pull request as ready for review November 13, 2024 14:13
@trim21 trim21 changed the title add variable commit_date feat: add variable commit_date Nov 13, 2024
@trim21
Copy link
Contributor Author

trim21 commented Nov 13, 2024

it will use local event data file for push event, and fallback to github api for PR.

@trim21 trim21 force-pushed the commit-date branch 2 times, most recently from 1434e0e to b63fcf7 Compare November 13, 2024 15:39
@trim21

This comment was marked as outdated.

@trim21
Copy link
Contributor Author

trim21 commented Nov 13, 2024

I may need to update GitHub mocking logic for better code style

@trim21 trim21 force-pushed the commit-date branch 2 times, most recently from 9968536 to 1c7e57e Compare November 13, 2024 16:29
@trim21
Copy link
Contributor Author

trim21 commented Nov 13, 2024

done

@trim21
Copy link
Contributor Author

trim21 commented Nov 14, 2024

review applied

src/context.ts Outdated Show resolved Hide resolved
src/context.ts Show resolved Hide resolved
@trim21
Copy link
Contributor Author

trim21 commented Nov 14, 2024

forget to run eslint 😅

@crazy-max
Copy link
Member

crazy-max commented Nov 14, 2024

Can you add

core.info(`commitDate: ${context.commitDate}`);

to:

await core.group(`Context info`, async () => {

@trim21
Copy link
Contributor Author

trim21 commented Nov 14, 2024

done

@trim21 trim21 force-pushed the commit-date branch 2 times, most recently from 40465f6 to 69486da Compare November 14, 2024 07:27
Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just merged #472 to check the behavior for git context, can you rebase?

src/meta.ts Show resolved Hide resolved
Comment on lines +122 to +126
const commit = await toolkit.github.octokit.request('GET /repos/{owner}/{repo}/commits/{commit_sha}', {
commit_sha: sha,
owner: GitHub.context.repo.owner,
repo: GitHub.context.repo.repo
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would work for pull requests from a fork

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see this: trim21#2

Copy link
Member

@crazy-max crazy-max Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#get-a-commit--parameters I think we can just pass the full ref like:

Suggested change
const commit = await toolkit.github.octokit.request('GET /repos/{owner}/{repo}/commits/{commit_sha}', {
commit_sha: sha,
owner: GitHub.context.repo.owner,
repo: GitHub.context.repo.repo
});
const commit = await toolkit.github.octokit.request('GET /repos/{owner}/{repo}/commits/{GitHub.context.ref}', {
owner: GitHub.context.repo.owner,
repo: GitHub.context.repo.repo
});

In case of a pull request it would be smth like 'GET /repos/{owner}/{repo}/commits/pull/471/merge' for your pr.

Copy link
Contributor Author

@trim21 trim21 Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, a commit in a fork will also always exists in any forks. we do not need to handle this

for example: trim21@4a4aa3e

https://api.github.com/repos/trim21/metadata-action/commits/4a4aa3e4cba597bb90d7342e9a2da7891cb822eb

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see this: trim21#2

I meant for a pull request from a fork but seems GitHub handles that: https://github.com/docker/metadata-action/actions/runs/11832905758/job/32970605385?pr=471#step:3:18

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in anyway, if sha is correct, we will get a commit. even if we send request to head repo not base repo

@trim21 trim21 force-pushed the commit-date branch 2 times, most recently from 27580b6 to ce0e6b3 Compare November 14, 2024 07:50
Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM thanks!

Can we have more test cases in meta.test.ts to cover other kind of events:

__tests__/context.test.ts Show resolved Hide resolved
__tests__/context.test.ts Show resolved Hide resolved
@trim21 trim21 force-pushed the commit-date branch 4 times, most recently from 750c474 to b74a4a7 Compare November 16, 2024 17:00
@trim21
Copy link
Contributor Author

trim21 commented Nov 16, 2024

done

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

@crazy-max crazy-max merged commit c85c22a into docker:master Nov 18, 2024
35 checks passed
@trim21
Copy link
Contributor Author

trim21 commented Nov 18, 2024

is there a release cycle?

@crazy-max
Copy link
Member

is there a release cycle?

Yes probably this week

@trim21
Copy link
Contributor Author

trim21 commented Nov 18, 2024

I forget to add this to toc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants