Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ linters:
- PullRequestReviewsEnforcementUpdate
- Repository
- RepositoryAddCollaboratorOptions
- RepositoryComment
- RepositoryContentFileOptions
- RepositoryCreateForkOptions
- RequiredStatusChecksRequest
Expand Down
56 changes: 56 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions github/github-stringify_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 35 additions & 22 deletions github/repos_comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,40 @@ import (

// RepositoryComment represents a comment for a commit, file, or line in a repository.
type RepositoryComment struct {
HTMLURL *string `json:"html_url,omitempty"`
URL *string `json:"url,omitempty"`
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
CommitID *string `json:"commit_id,omitempty"`
User *User `json:"user,omitempty"`
Reactions *Reactions `json:"reactions,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`

// User-mutable fields
Body *string `json:"body"`
// User-initialized fields
Path *string `json:"path,omitempty"`
Position *int `json:"position,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
URL *string `json:"url,omitempty"`
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
CommitID *string `json:"commit_id,omitempty"`
User *User `json:"user,omitempty"`
AuthorAssociation *string `json:"author_association,omitempty"`
Reactions *Reactions `json:"reactions,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
Body *string `json:"body,omitempty"`
Path *string `json:"path,omitempty"`
Position *int `json:"position,omitempty"`
Line *int `json:"line,omitempty"`
}

func (r RepositoryComment) String() string {
return Stringify(r)
}

// CreateCommitCommentRequest represents a request to create a commit comment.
type CreateCommitCommentRequest struct {
Body string `json:"body"`
Path *string `json:"path,omitempty"`
Position *int `json:"position,omitempty"`
// Deprecated: Use Position instead.
Line *int `json:"line,omitempty"`
}

// UpdateCommitCommentRequest represents a request to update a commit comment.
type UpdateCommitCommentRequest struct {
Body string `json:"body"`
}

// ListComments lists all the comments for the repository.
//
// GitHub API docs: https://docs.github.com/rest/commits/comments?apiVersion=2022-11-28#list-commit-comments-for-a-repository
Expand Down Expand Up @@ -95,7 +108,7 @@ func (s *RepositoriesService) ListCommitComments(ctx context.Context, owner, rep
// GitHub API docs: https://docs.github.com/rest/commits/comments?apiVersion=2022-11-28#create-a-commit-comment
//
//meta:operation POST /repos/{owner}/{repo}/commits/{commit_sha}/comments
func (s *RepositoriesService) CreateComment(ctx context.Context, owner, repo, sha string, body *RepositoryComment) (*RepositoryComment, *Response, error) {
func (s *RepositoriesService) CreateComment(ctx context.Context, owner, repo, sha string, body CreateCommitCommentRequest) (*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/comments", owner, repo, sha)
req, err := s.client.NewRequest(ctx, "POST", u, body)
if err != nil {
Expand All @@ -116,8 +129,8 @@ func (s *RepositoriesService) CreateComment(ctx context.Context, owner, repo, sh
// GitHub API docs: https://docs.github.com/rest/commits/comments?apiVersion=2022-11-28#get-a-commit-comment
//
//meta:operation GET /repos/{owner}/{repo}/comments/{comment_id}
func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string, id int64) (*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id)
func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string, commentID int64) (*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, commentID)
req, err := s.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
Expand All @@ -139,8 +152,8 @@ func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string
// GitHub API docs: https://docs.github.com/rest/commits/comments?apiVersion=2022-11-28#update-a-commit-comment
//
//meta:operation PATCH /repos/{owner}/{repo}/comments/{comment_id}
func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo string, id int64, body *RepositoryComment) (*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id)
func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo string, commentID int64, body UpdateCommitCommentRequest) (*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, commentID)
req, err := s.client.NewRequest(ctx, "PATCH", u, body)
if err != nil {
return nil, nil, err
Expand All @@ -160,8 +173,8 @@ func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo str
// GitHub API docs: https://docs.github.com/rest/commits/comments?apiVersion=2022-11-28#delete-a-commit-comment
//
//meta:operation DELETE /repos/{owner}/{repo}/comments/{comment_id}
func (s *RepositoriesService) DeleteComment(ctx context.Context, owner, repo string, id int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id)
func (s *RepositoriesService) DeleteComment(ctx context.Context, owner, repo string, commentID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, commentID)
req, err := s.client.NewRequest(ctx, "DELETE", u, nil)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions github/repos_comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestRepositoriesService_CreateComment(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

input := &RepositoryComment{Body: new("b")}
input := CreateCommitCommentRequest{Body: "b"}

mux.HandleFunc("/repos/o/r/commits/s/comments", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestRepositoriesService_CreateComment_invalidOwner(t *testing.T) {
client, _, _ := setup(t)

ctx := t.Context()
_, _, err := client.Repositories.CreateComment(ctx, "%", "%", "%", nil)
_, _, err := client.Repositories.CreateComment(ctx, "%", "%", "%", CreateCommitCommentRequest{})
testURLParseError(t, err)
}

Expand Down Expand Up @@ -203,7 +203,7 @@ func TestRepositoriesService_UpdateComment(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

input := &RepositoryComment{Body: new("b")}
input := UpdateCommitCommentRequest{Body: "b"}

mux.HandleFunc("/repos/o/r/comments/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PATCH")
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestRepositoriesService_UpdateComment_invalidOwner(t *testing.T) {
client, _, _ := setup(t)

ctx := t.Context()
_, _, err := client.Repositories.UpdateComment(ctx, "%", "%", 1, nil)
_, _, err := client.Repositories.UpdateComment(ctx, "%", "%", 1, UpdateCommitCommentRequest{})
testURLParseError(t, err)
}

Expand Down
Loading