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

refactor!: Update package types to align with webhook event #3515

Merged
merged 6 commits into from
Mar 17, 2025

Conversation

adrian-saunders
Copy link
Contributor

@adrian-saunders adrian-saunders commented Mar 13, 2025

BREAKING CHANGE: PackageVersion.Body and PackageVersion.Metadata are both now json.RawMessage.

Hello,

Firstly, thank you for maintaining this project! It has made interacting with GitHub significantly easier. I know this is a little backward to raise a PR without even a comment on the original issue so sorry but I had to get some legal approval first. Anyway...

This PR is meant to better align the package types with the webhook event schema.

Fixes: #2033

Breaking changes:

  • PackageVersion.Body is now json.RawMessage - I'm not sure in what scenarios this is a string or object but it can be both.
  • PackageVersion.Metadata is now json.json.RawMessage - webhooks return an array here, rather than a PackageMetadata

I've added getters for both of these fields.

References:
Webhooks: https://github.com/octokit/webhooks/tree/main/payload-schemas/api.github.com/package
REST: https://docs.github.com/en/rest/packages/packages?apiVersion=2022-11-28

Please do let me know your comments and if there is anything I haven't thought of!

Update the types associated with GitHub packages to better align with the schema used by by the package event.
Copy link

codecov bot commented Mar 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.30%. Comparing base (d0976cc) to head (14a2d8c).
Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3515      +/-   ##
==========================================
+ Coverage   91.17%   91.30%   +0.12%     
==========================================
  Files         181      183       +2     
  Lines       15859    16094     +235     
==========================================
+ Hits        14460    14695     +235     
  Misses       1225     1225              
  Partials      174      174              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmlewis gmlewis added NeedsReview PR is awaiting a review before merging. Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). labels Mar 13, 2025
@gmlewis gmlewis changed the title refactor!: update package types to align with webhook event refactor!: Update package types to align with webhook event Mar 13, 2025
@gmlewis gmlewis mentioned this pull request Mar 13, 2025
@gmlewis
Copy link
Collaborator

gmlewis commented Mar 13, 2025

If you run ./script/lint.sh locally you should see the issues that need to be fixed. Thank you, @adrian-saunders!

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @adrian-saunders!
I'll continue my review after you address the current issues.

@@ -85,7 +157,6 @@ type PackageFile struct {
MD5 *string `json:"md5,omitempty"`
ContentType *string `json:"content_type,omitempty"`
State *string `json:"state,omitempty"`
Author *User `json:"author,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this field being removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can tell, PackageFiles only exist on a webhook event and the schema doesn't have it as a property

https://github.com/octokit/webhooks/blob/main/payload-schemas/api.github.com/package/published.schema.json#L227-L238

Should have mentioned as a breaking change though!

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, let's please leave the field in unless we can conclusively prove that it is no longer being used. Feel free to add a comment about your findings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK will add back

@adrian-saunders adrian-saunders requested a review from gmlewis March 14, 2025 00:21
@gmlewis
Copy link
Collaborator

gmlewis commented Mar 14, 2025

Oh, sorry, I see your responses now in email.
I'll continue the review.

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @adrian-saunders!
It is unfortunate that we have so many any, map and json.RawMessage in this PR, but it sounds like it is pretty unavoidable due to the wide variety of possible data.

Let's please add back in the removed Author field, and then we should be ready for a second LGTM+Approval from any other contributor to this repo before merging.

@@ -85,7 +157,6 @@ type PackageFile struct {
MD5 *string `json:"md5,omitempty"`
ContentType *string `json:"content_type,omitempty"`
State *string `json:"state,omitempty"`
Author *User `json:"author,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK will add back

@adrian-saunders adrian-saunders requested a review from gmlewis March 14, 2025 15:26
Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @adrian-saunders!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.

@stevehipwell - might you have time for a code review? Thank you!

@stevehipwell
Copy link
Contributor

@gmlewis I think this is another case where it's worth considering if json.RawMessage is the right solution or if we need an alternative such as to widen the struct field (e.g.single to array) or add a second field (object or string depending on the response)?

@gmlewis
Copy link
Collaborator

gmlewis commented Mar 14, 2025

@gmlewis I think this is another case where it's worth considering if json.RawMessage is the right solution or if we need an alternative such as to widen the struct field (e.g.single to array) or add a second field (object or string depending on the response)?

I think that is certainly a possibility. Are there examples of what you are proposing elsewhere in this repo that can be used as a guide for implementation?

If not, I think it may be too much to ask PR authors to try and understand what you are envisioning, as my personal understanding is a bit fuzzy and I would not be able to give guidance.

Maybe the best way to go about this is to open one or more new Issues with enhancement proposals to make the developer experience better for users of this client library by implementing what you are proposing. In fact, maybe we could start with one or two specific API collections (maybe the two you've already mentioned... this PR and the other one you commented on) and see if we want to expand this idea throughout the repo based on how the changes are received?

Copy link
Contributor

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

LGTM

@gmlewis
Copy link
Collaborator

gmlewis commented Mar 17, 2025

Thank you, @stevehipwell!
Merging.

@gmlewis gmlewis removed the NeedsReview PR is awaiting a review before merging. label Mar 17, 2025
@gmlewis gmlewis merged commit 7a89ae9 into google:master Mar 17, 2025
7 checks passed
@adrian-saunders
Copy link
Contributor Author

Thank you both for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

package event outdated
3 participants