Skip to content

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

//
//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
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
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
Collaborator

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

@gmlewis
Copy link
Collaborator

gmlewis commented Sep 22, 2025

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

Copy link

codecov bot commented Sep 22, 2025

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

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. waiting for reply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants