-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
base: master
Are you sure you want to change the base?
Changes from all commits
f8becc6
aac4a7a
112844f
e1af3f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -33,6 +33,19 @@ type Gist struct { | |||||
NodeID *string `json:"node_id,omitempty"` | ||||||
} | ||||||
|
||||||
// CreateGistRequest represents the input for creating a gist. | ||||||
type CreateGistRequest struct { | ||||||
Description *string `json:"description,omitempty"` | ||||||
Public *bool `json:"public,omitempty"` | ||||||
Files map[GistFilename]GistFile `json:"files,omitempty"` | ||||||
} | ||||||
|
||||||
// UpdateGistRequest represents the input for updating a gist. | ||||||
type UpdateGistRequest struct { | ||||||
Description *string `json:"description,omitempty"` | ||||||
Files map[GistFilename]GistFile `json:"files,omitempty"` | ||||||
} | ||||||
|
||||||
func (g Gist) String() string { | ||||||
return Stringify(g) | ||||||
} | ||||||
|
@@ -224,7 +237,7 @@ func (s *GistsService) GetRevision(ctx context.Context, id, sha string) (*Gist, | |||||
// GitHub API docs: https://docs.github.com/rest/gists/gists#create-a-gist | ||||||
// | ||||||
//meta:operation POST /gists | ||||||
func (s *GistsService) Create(ctx context.Context, gist *Gist) (*Gist, *Response, error) { | ||||||
func (s *GistsService) Create(ctx context.Context, gist CreateGistRequest) (*Gist, *Response, error) { | ||||||
u := "gists" | ||||||
req, err := s.client.NewRequest("POST", u, gist) | ||||||
if err != nil { | ||||||
|
@@ -240,12 +253,33 @@ func (s *GistsService) Create(ctx context.Context, gist *Gist) (*Gist, *Response | |||||
return g, resp, nil | ||||||
} | ||||||
|
||||||
// CreateFromGist creates a gist for the authenticated user using a Gist struct. | ||||||
// | ||||||
// Deprecated: Use Create with CreateGistRequest instead. | ||||||
// | ||||||
// GitHub API docs: https://docs.github.com/rest/gists/gists#create-a-gist | ||||||
// | ||||||
//meta:operation POST /gists | ||||||
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) | ||||||
} | ||||||
|
||||||
// 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) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think the API consistency would be improved if we replaced There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree. Thank you, @stevehipwell. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
u := fmt.Sprintf("gists/%v", id) | ||||||
req, err := s.client.NewRequest("PATCH", u, gist) | ||||||
if err != nil { | ||||||
|
@@ -261,6 +295,26 @@ func (s *GistsService) Edit(ctx context.Context, id string, gist *Gist) (*Gist, | |||||
return g, resp, nil | ||||||
} | ||||||
|
||||||
// EditFromGist updates a gist using a Gist struct. | ||||||
// | ||||||
// Deprecated: Use Edit with UpdateGistRequest instead. | ||||||
// | ||||||
// GitHub API docs: https://docs.github.com/rest/gists/gists#update-a-gist | ||||||
// | ||||||
//meta:operation PATCH /gists/{gist_id} | ||||||
func (s *GistsService) EditFromGist(ctx context.Context, id string, gist *Gist) (*Gist, *Response, error) { | ||||||
var req UpdateGistRequest | ||||||
|
||||||
if gist != nil { | ||||||
req = UpdateGistRequest{ | ||||||
Description: gist.Description, | ||||||
Files: gist.Files, | ||||||
} | ||||||
} | ||||||
|
||||||
return s.Edit(ctx, id, req) | ||||||
} | ||||||
|
||||||
// ListCommits lists commits of a gist. | ||||||
// | ||||||
// GitHub API docs: https://docs.github.com/rest/gists/gists#list-gist-commits | ||||||
|
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)