Skip to content

refactor!: Refactor GistsService to use value parameters #3680

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sarthakw7
Copy link

@sarthakw7 sarthakw7 commented Aug 16, 2025

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

@gmlewis gmlewis changed the title refactor GistsService to use value parameters Refactor GistsService to use value parameters Aug 16, 2025
@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 Aug 16, 2025
@gmlewis gmlewis changed the title Refactor GistsService to use value parameters feat!: Refactor GistsService to use value parameters Aug 16, 2025
@gmlewis gmlewis changed the title feat!: Refactor GistsService to use value parameters refactor!: Refactor GistsService to use value parameters Aug 16, 2025
Copy link
Contributor

@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, @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!

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.

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

// Edit a gist.
//
// GitHub API docs: https://docs.github.com/rest/gists/gists#update-a-gist
//
//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
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, id string, gist UpdateGistRequest) (*Gist, *Response, error) {
func (s *GistsService) Update(ctx context.Context, id string, gist UpdateGistRequest) (*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
Contributor

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

Copy link
Contributor

@gmlewis gmlewis Aug 18, 2025

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
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)

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). NeedsReview PR is awaiting a review before merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants