-
Notifications
You must be signed in to change notification settings - Fork 2.2k
refactor!: Pass GistsService required params by value
#4320
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
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,22 @@ func (g Gist) String() string { | |||||||||
| return Stringify(g) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // CreateGistRequest represents the input for creating a gist. | ||||||||||
| type CreateGistRequest struct { | ||||||||||
| Description *string `json:"description,omitempty"` | ||||||||||
| Public *bool `json:"public,omitempty"` | ||||||||||
| // Files is the set of files that make up the gist, keyed by filename. (Required.) | ||||||||||
| Files map[GistFilename]*CreateGistFile `json:"files"` | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // UpdateGistRequest represents the input for updating a gist. | ||||||||||
| type UpdateGistRequest struct { | ||||||||||
| Description *string `json:"description,omitempty"` | ||||||||||
| // Files is the set of files to add, change or rename, keyed by filename. | ||||||||||
| // Mapping a filename to a nil value deletes that file from the gist. | ||||||||||
| Files map[GistFilename]*UpdateGistFile `json:"files,omitempty"` | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // GistFilename represents filename on a gist. | ||||||||||
| type GistFilename string | ||||||||||
|
|
||||||||||
|
|
@@ -54,6 +70,23 @@ func (g GistFile) String() string { | |||||||||
| return Stringify(g) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // CreateGistFile represents a file within a CreateGistRequest, keyed by filename | ||||||||||
| // in the request's Files map. | ||||||||||
| type CreateGistFile struct { | ||||||||||
| // Content is the contents of the file. (Required.) | ||||||||||
| Content *string `json:"content,omitempty"` | ||||||||||
|
Comment on lines
+76
to
+77
Contributor
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
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| // UpdateGistFile represents a file within an UpdateGistRequest, keyed by filename | ||||||||||
| // in the request's Files map. Mapping a filename to a nil *UpdateGistFile deletes | ||||||||||
| // that file from the gist. | ||||||||||
| type UpdateGistFile struct { | ||||||||||
| // Content is the new contents of the file. | ||||||||||
| Content *string `json:"content,omitempty"` | ||||||||||
| // Filename, if set, renames the file. | ||||||||||
| Filename *string `json:"filename,omitempty"` | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // GistCommit represents a commit on a gist. | ||||||||||
| type GistCommit struct { | ||||||||||
| URL *string `json:"url,omitempty"` | ||||||||||
|
|
@@ -225,7 +258,7 @@ func (s *GistsService) GetRevision(ctx context.Context, id, sha string) (*Gist, | |||||||||
| // GitHub API docs: https://docs.github.com/rest/gists/gists?apiVersion=2022-11-28#create-a-gist | ||||||||||
| // | ||||||||||
| //meta:operation POST /gists | ||||||||||
| func (s *GistsService) Create(ctx context.Context, body *Gist) (*Gist, *Response, error) { | ||||||||||
| func (s *GistsService) Create(ctx context.Context, body CreateGistRequest) (*Gist, *Response, error) { | ||||||||||
| u := "gists" | ||||||||||
| req, err := s.client.NewRequest(ctx, "POST", u, body) | ||||||||||
| if err != nil { | ||||||||||
|
|
@@ -241,12 +274,12 @@ func (s *GistsService) Create(ctx context.Context, body *Gist) (*Gist, *Response | |||||||||
| return g, resp, nil | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Edit a gist. | ||||||||||
| // Update a gist. | ||||||||||
| // | ||||||||||
| // GitHub API docs: https://docs.github.com/rest/gists/gists?apiVersion=2022-11-28#update-a-gist | ||||||||||
| // | ||||||||||
| //meta:operation PATCH /gists/{gist_id} | ||||||||||
| func (s *GistsService) Edit(ctx context.Context, id string, body *Gist) (*Gist, *Response, error) { | ||||||||||
| func (s *GistsService) Update(ctx context.Context, id string, body UpdateGistRequest) (*Gist, *Response, error) { | ||||||||||
| u := fmt.Sprintf("gists/%v", id) | ||||||||||
| req, err := s.client.NewRequest(ctx, "PATCH", u, body) | ||||||||||
| if err != nil { | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,16 @@ func (g GistComment) String() string { | |||||||
| return Stringify(g) | ||||||||
| } | ||||||||
|
|
||||||||
| // CreateGistCommentRequest represents the input for creating a gist comment. | ||||||||
| type CreateGistCommentRequest struct { | ||||||||
| Body *string `json:"body,omitempty"` | ||||||||
|
Contributor
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
|
||||||||
| } | ||||||||
|
|
||||||||
| // UpdateGistCommentRequest represents the input for updating a gist comment. | ||||||||
| type UpdateGistCommentRequest struct { | ||||||||
| Body *string `json:"body,omitempty"` | ||||||||
|
Contributor
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
|
||||||||
| } | ||||||||
|
|
||||||||
| // ListComments lists all comments for a gist. | ||||||||
| // | ||||||||
| // GitHub API docs: https://docs.github.com/rest/gists/comments?apiVersion=2022-11-28#list-gist-comments | ||||||||
|
|
@@ -75,7 +85,7 @@ func (s *GistsService) GetComment(ctx context.Context, gistID string, commentID | |||||||
| // GitHub API docs: https://docs.github.com/rest/gists/comments?apiVersion=2022-11-28#create-a-gist-comment | ||||||||
| // | ||||||||
| //meta:operation POST /gists/{gist_id}/comments | ||||||||
| func (s *GistsService) CreateComment(ctx context.Context, gistID string, body *GistComment) (*GistComment, *Response, error) { | ||||||||
| func (s *GistsService) CreateComment(ctx context.Context, gistID string, body CreateGistCommentRequest) (*GistComment, *Response, error) { | ||||||||
| u := fmt.Sprintf("gists/%v/comments", gistID) | ||||||||
| req, err := s.client.NewRequest(ctx, "POST", u, body) | ||||||||
| if err != nil { | ||||||||
|
|
@@ -91,12 +101,12 @@ func (s *GistsService) CreateComment(ctx context.Context, gistID string, body *G | |||||||
| return c, resp, nil | ||||||||
| } | ||||||||
|
|
||||||||
| // EditComment edits an existing gist comment. | ||||||||
| // UpdateComment updates an existing gist comment. | ||||||||
| // | ||||||||
| // GitHub API docs: https://docs.github.com/rest/gists/comments?apiVersion=2022-11-28#update-a-gist-comment | ||||||||
| // | ||||||||
| //meta:operation PATCH /gists/{gist_id}/comments/{comment_id} | ||||||||
| func (s *GistsService) EditComment(ctx context.Context, gistID string, commentID int64, body *GistComment) (*GistComment, *Response, error) { | ||||||||
| func (s *GistsService) UpdateComment(ctx context.Context, gistID string, commentID int64, body UpdateGistCommentRequest) (*GistComment, *Response, error) { | ||||||||
| u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID) | ||||||||
| req, err := s.client.NewRequest(ctx, "PATCH", u, body) | ||||||||
| if err != nil { | ||||||||
|
|
||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.