Skip to content

refactor!: Refactor GistsService to use value parameters - #3680

Closed
sarthakw7 wants to merge 4 commits into
google:masterfrom
sarthakw7:feature/gists-value-parameters
Closed

refactor!: Refactor GistsService to use value parameters#3680
sarthakw7 wants to merge 4 commits into
google:masterfrom
sarthakw7:feature/gists-value-parameters

Conversation

@sarthakw7

@sarthakw7sarthakw7 commented Aug 16, 2025

Copy link
Copy Markdown

BREAKING CHANGE: GistsService methods now pass required params by-value instead of by-ref.

Summary

This PR refactors the GistsService to use value parameters instead of pointer parameters where appropriate, addressing issue #3644. This is the first service in a planned series of PRs to improve API design consistency across the entire library.

Changes

New Input Structs

  • CreateGistRequest - Input for creating gists (3 fields)
  • UpdateGistRequest - Input for updating gists (2 fields)
  • CreateGistCommentRequest - Input for creating gist comments (1 field)
  • UpdateGistCommentRequest - Input for updating gist comments (1 field)

Refactored Methods (New API)

  • Create(ctx, CreateGistRequest) - Uses value parameter
  • Edit(ctx, id, UpdateGistRequest) - Uses value parameter
  • CreateComment(ctx, gistID, CreateGistCommentRequest) - Uses value parameter
  • EditComment(ctx, gistID, commentID, UpdateGistCommentRequest) - Uses value parameter

Backward Compatibility (Deprecated API)

  • CreateFromGist(ctx, *Gist) - Wrapper for backward compatibility
  • EditFromGist(ctx, id, *Gist) - Wrapper for backward compatibility
  • CreateCommentFromGistComment(ctx, gistID, *GistComment) - Wrapper for backward compatibility
  • EditCommentFromGistComment(ctx, gistID, commentID, *GistComment) - Wrapper for backward compatibility

@gmlewisgmlewis changed the title refactor GistsService to use value parametersRefactor GistsService to use value parametersAug 16, 2025
@gmlewisgmlewis 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 Aug 16, 2025
@gmlewisgmlewis changed the title Refactor GistsService to use value parametersfeat!: Refactor GistsService to use value parametersAug 16, 2025
@gmlewisgmlewis changed the title feat!: Refactor GistsService to use value parametersrefactor!: Refactor GistsService to use value parametersAug 16, 2025

@gmlewisgmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

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

@stevehipwellstevehipwell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR looks good @sarthakw7 but I'd like to hear back from @gmlewis about the API design before approving.

Comment threadgithub/gists.go
//
//meta:operation PATCH /gists/{gist_id}
func (s *GistsService) Edit(ctx context.Context, id string, gist *Gist) (*Gist, *Response, error) {
func (s *GistsService) Edit(ctx context.Context, id string, gist UpdateGistRequest) (*Gist, *Response, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (s*GistsService) Edit(ctx context.Context, idstring, gistUpdateGistRequest) (*Gist, *Response, error) {
func (s*GistsService) Update(ctx context.Context, idstring, gistUpdateGistRequest) (*Gist, *Response, error) {

I think the API consistency would be improved if we replaced Edit with Update and if we're changing the method signature that seems like a good time to make this change? @gmlewis what do you think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, I agree. Thank you, @stevehipwell.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I’ll go ahead and replace Edit → Update and EditComment → UpdateComment to keep things consistent

Comment threadgithub/gists.go
Comment on lines +263 to +275
func (s *GistsService) CreateFromGist(ctx context.Context, gist *Gist) (*Gist, *Response, error) {
var req CreateGistRequest

if gist != nil {
req = CreateGistRequest{
Description: gist.Description,
Public: gist.Public,
Files: gist.Files,
}
}

return s.Create(ctx, req)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need this wrapper?

In this PR #3654 we didn't introduce any wrappers, but it breaks API in a similar way.

@gmlewisgmlewisAug 18, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I agree that we don't need the wrappers. I was trying to decide, but I think you are correct, @alexandear.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Got it.
Since wrappers aren’t needed, I’ll go ahead and remove the four deprecated methods (CreateFromGist, EditFromGist, CreateCommentFromGistComment, and EditCommentFromGistComment)

@gmlewis

Copy link
Copy Markdown
Collaborator

@stevehipwell and/or @alexandear - do you approve this PR now?

@codecov

codecovBot commented Sep 22, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.15%. Comparing base (ffc5df8) to head (e1af3f5).

Additional details and impacted files
@@ Coverage Diff @@## master #3680 +/- ##
==========================================
+ Coverage 91.12% 91.15% +0.02% 
==========================================
Files 187 187 Lines 16640 16679 +39 ==========================================
+ Hits 15164 15203 +39 
Misses 1291 1291 Partials 185 185 

☔ 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.

@stevehipwell

Copy link
Copy Markdown
Contributor

@gmlewis I don't think the agreed actions from the review conversations have been completed yet. @sarthakw7 are you still planning on making the changes?

JamBalaya56562 added a commit to JamBalaya56562/go-github that referenced this pull request Jun 23, 2026
BREAKING CHANGE: GistsService.Create / Update / CreateComment / UpdateComment
now take dedicated request structs by value (CreateGistRequest, UpdateGistRequest,
CreateGistCommentRequest, UpdateGistCommentRequest) instead of *Gist / *GistComment.
Edit is renamed to Update and EditComment is renamed to UpdateComment.
This completes the stalled PR google#3680, applying the maintainer-agreed review
feedback that was never addressed: drop the deprecated wrappers entirely and
rename Edit/EditComment to Update/UpdateComment for API consistency.
The now-obsolete Gist and GistComment entries are removed from the paramcheck
body-allowed-pointer-types allow-list in .golangci.yml.
Relates to google#3644.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
JamBalaya56562 added a commit to JamBalaya56562/go-github that referenced this pull request Jun 23, 2026
BREAKING CHANGE: GistsService.Create / Update / CreateComment / UpdateComment
now take dedicated request structs by value (CreateGistRequest, UpdateGistRequest,
CreateGistCommentRequest, UpdateGistCommentRequest) instead of *Gist / *GistComment.
Edit is renamed to Update and EditComment is renamed to UpdateComment.
This completes the stalled PR google#3680, applying the maintainer-agreed review
feedback that was never addressed: drop the deprecated wrappers entirely and
rename Edit/EditComment to Update/UpdateComment for API consistency.
The now-obsolete Gist and GistComment entries are removed from the paramcheck
body-allowed-pointer-types allow-list in .golangci.yml.
Relates to google#3644.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking API ChangePR will require a bump to the major version num in next release. Look here to see the change(s).NeedsReviewPR is awaiting a review before merging.waiting for reply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@sarthakw7@gmlewis@stevehipwell@alexandear