diff --git a/github/issues.go b/github/issues.go index ee2a7a0..6b3256c 100644 --- a/github/issues.go +++ b/github/issues.go @@ -37,15 +37,6 @@ type Issue struct { // TODO(willnorris): labels and milestone } -// IssueComment represents a comment left on an issue. -type IssueComment struct { - ID int `json:"id,omitempty"` - Body string `json:"body,omitempty"` - User *User `json:"user,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` -} - // IssueListOptions specifies the optional parameters to the IssuesService.List // and IssuesService.ListByOrg methods. type IssueListOptions struct { @@ -237,132 +228,3 @@ func (s *IssuesService) Edit(owner string, repo string, number int, issue *Issue _, err = s.client.Do(req, i) return i, err } - -// ListAssignees fetches all available assignees (owners and collaborators) to -// which issues may be assigned. -// -// GitHub API docs: http://developer.github.com/v3/issues/assignees/#list-assignees -func (s *IssuesService) ListAssignees(owner string, repo string) ([]User, error) { - u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo) - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, err - } - assignees := new([]User) - _, err = s.client.Do(req, assignees) - return *assignees, err -} - -// CheckAssignee checks if a user is an assignee for the specified repository. -// -// GitHub API docs: http://developer.github.com/v3/issues/assignees/#check-assignee -func (s *IssuesService) CheckAssignee(owner string, repo string, user string) (bool, error) { - u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user) - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return false, err - } - _, err = s.client.Do(req, nil) - return parseBoolResponse(err) -} - -// IssueListCommentsOptions specifies the optional parameters to the -// IssuesService.ListComments method. -type IssueListCommentsOptions struct { - // Sort specifies how to sort comments. Possible values are: created, updated. - Sort string - - // Direction in which to sort comments. Possible values are: asc, desc. - Direction string - - // Since filters comments by time. - Since time.Time -} - -// ListComments lists all comments on the specified issue. Specifying an issue -// number of 0 will return all comments on all issues for the repository. -// -// GitHub API docs: http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue -func (s *IssuesService) ListComments(owner string, repo string, number int, opt *IssueListCommentsOptions) ([]IssueComment, error) { - var u string - if number == 0 { - u = fmt.Sprintf("repos/%v/%v/issues/comments", owner, repo) - } else { - u = fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number) - } - - if opt != nil { - params := url.Values{ - "sort": {opt.Sort}, - "direction": {opt.Direction}, - } - if !opt.Since.IsZero() { - params.Add("since", opt.Since.Format(time.RFC3339)) - } - u += "?" + params.Encode() - } - - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, err - } - comments := new([]IssueComment) - _, err = s.client.Do(req, comments) - return *comments, err -} - -// GetComment fetches the specified issue comment. -// -// GitHub API docs: http://developer.github.com/v3/issues/comments/#get-a-single-comment -func (s *IssuesService) GetComment(owner string, repo string, id int) (*IssueComment, error) { - u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id) - - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, err - } - comment := new(IssueComment) - _, err = s.client.Do(req, comment) - return comment, err -} - -// CreateComment creates a new comment on the specified issue. -// -// GitHub API docs: http://developer.github.com/v3/issues/comments/#create-a-comment -func (s *IssuesService) CreateComment(owner string, repo string, number int, comment *IssueComment) (*IssueComment, error) { - u := fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number) - req, err := s.client.NewRequest("POST", u, comment) - if err != nil { - return nil, err - } - c := new(IssueComment) - _, err = s.client.Do(req, c) - return c, err -} - -// EditComment updates an issue comment. -// -// GitHub API docs: http://developer.github.com/v3/issues/comments/#edit-a-comment -func (s *IssuesService) EditComment(owner string, repo string, id int, comment *IssueComment) (*IssueComment, error) { - u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id) - req, err := s.client.NewRequest("PATCH", u, comment) - if err != nil { - return nil, err - } - c := new(IssueComment) - _, err = s.client.Do(req, c) - return c, err -} - -// DeleteComment deletes an issue comment. -// -// GitHub API docs: http://developer.github.com/v3/issues/comments/#delete-a-comment -func (s *IssuesService) DeleteComment(owner string, repo string, id int) error { - u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id) - req, err := s.client.NewRequest("DELETE", u, nil) - if err != nil { - return err - } - _, err = s.client.Do(req, nil) - return err -} diff --git a/github/issues_assignees.go b/github/issues_assignees.go new file mode 100644 index 0000000..49db306 --- /dev/null +++ b/github/issues_assignees.go @@ -0,0 +1,38 @@ +// Copyright 2013 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "fmt" +) + +// ListAssignees fetches all available assignees (owners and collaborators) to +// which issues may be assigned. +// +// GitHub API docs: http://developer.github.com/v3/issues/assignees/#list-assignees +func (s *IssuesService) ListAssignees(owner string, repo string) ([]User, error) { + u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, err + } + assignees := new([]User) + _, err = s.client.Do(req, assignees) + return *assignees, err +} + +// CheckAssignee checks if a user is an assignee for the specified repository. +// +// GitHub API docs: http://developer.github.com/v3/issues/assignees/#check-assignee +func (s *IssuesService) CheckAssignee(owner string, repo string, user string) (bool, error) { + u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return false, err + } + _, err = s.client.Do(req, nil) + return parseBoolResponse(err) +} diff --git a/github/issues_assignees_test.go b/github/issues_assignees_test.go new file mode 100644 index 0000000..f61037a --- /dev/null +++ b/github/issues_assignees_test.go @@ -0,0 +1,96 @@ +// Copyright 2013 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "fmt" + "net/http" + "reflect" + "testing" +) + +func TestIssuesService_ListAssignees(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/assignees", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{"id":1}]`) + }) + + assignees, err := client.Issues.ListAssignees("o", "r") + if err != nil { + t.Errorf("Issues.List returned error: %v", err) + } + + want := []User{User{ID: 1}} + if !reflect.DeepEqual(assignees, want) { + t.Errorf("Issues.ListAssignees returned %+v, want %+v", assignees, want) + } +} + +func TestIssuesService_ListAssignees_invalidOwner(t *testing.T) { + _, err := client.Issues.ListAssignees("%", "r") + testURLParseError(t, err) +} + +func TestIssuesService_CheckAssignee_true(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + }) + + assignee, err := client.Issues.CheckAssignee("o", "r", "u") + if err != nil { + t.Errorf("Issues.CheckAssignee returned error: %v", err) + } + if want := true; assignee != want { + t.Errorf("Issues.CheckAssignee returned %+v, want %+v", assignee, want) + } +} + +func TestIssuesService_CheckAssignee_false(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.WriteHeader(http.StatusNotFound) + }) + + assignee, err := client.Issues.CheckAssignee("o", "r", "u") + if err != nil { + t.Errorf("Issues.CheckAssignee returned error: %v", err) + } + if want := false; assignee != want { + t.Errorf("Issues.CheckAssignee returned %+v, want %+v", assignee, want) + } +} + +func TestIssuesService_CheckAssignee_error(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + http.Error(w, "BadRequest", http.StatusBadRequest) + }) + + assignee, err := client.Issues.CheckAssignee("o", "r", "u") + if err == nil { + t.Errorf("Expected HTTP 400 response") + } + if want := false; assignee != want { + t.Errorf("Issues.CheckAssignee returned %+v, want %+v", assignee, want) + } +} + +func TestIssuesService_CheckAssignee_invalidOwner(t *testing.T) { + _, err := client.Issues.CheckAssignee("%", "r", "u") + testURLParseError(t, err) +} diff --git a/github/issues_comments.go b/github/issues_comments.go new file mode 100644 index 0000000..a67f3eb --- /dev/null +++ b/github/issues_comments.go @@ -0,0 +1,122 @@ +// Copyright 2013 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "fmt" + "net/url" + "time" +) + +// IssueComment represents a comment left on an issue. +type IssueComment struct { + ID int `json:"id,omitempty"` + Body string `json:"body,omitempty"` + User *User `json:"user,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty"` + UpdatedAt *time.Time `json:"updated_at,omitempty"` +} + +// IssueListCommentsOptions specifies the optional parameters to the +// IssuesService.ListComments method. +type IssueListCommentsOptions struct { + // Sort specifies how to sort comments. Possible values are: created, updated. + Sort string + + // Direction in which to sort comments. Possible values are: asc, desc. + Direction string + + // Since filters comments by time. + Since time.Time +} + +// ListComments lists all comments on the specified issue. Specifying an issue +// number of 0 will return all comments on all issues for the repository. +// +// GitHub API docs: http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue +func (s *IssuesService) ListComments(owner string, repo string, number int, opt *IssueListCommentsOptions) ([]IssueComment, error) { + var u string + if number == 0 { + u = fmt.Sprintf("repos/%v/%v/issues/comments", owner, repo) + } else { + u = fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number) + } + + if opt != nil { + params := url.Values{ + "sort": {opt.Sort}, + "direction": {opt.Direction}, + } + if !opt.Since.IsZero() { + params.Add("since", opt.Since.Format(time.RFC3339)) + } + u += "?" + params.Encode() + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, err + } + comments := new([]IssueComment) + _, err = s.client.Do(req, comments) + return *comments, err +} + +// GetComment fetches the specified issue comment. +// +// GitHub API docs: http://developer.github.com/v3/issues/comments/#get-a-single-comment +func (s *IssuesService) GetComment(owner string, repo string, id int) (*IssueComment, error) { + u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id) + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, err + } + comment := new(IssueComment) + _, err = s.client.Do(req, comment) + return comment, err +} + +// CreateComment creates a new comment on the specified issue. +// +// GitHub API docs: http://developer.github.com/v3/issues/comments/#create-a-comment +func (s *IssuesService) CreateComment(owner string, repo string, number int, comment *IssueComment) (*IssueComment, error) { + u := fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number) + req, err := s.client.NewRequest("POST", u, comment) + if err != nil { + return nil, err + } + c := new(IssueComment) + _, err = s.client.Do(req, c) + return c, err +} + +// EditComment updates an issue comment. +// +// GitHub API docs: http://developer.github.com/v3/issues/comments/#edit-a-comment +func (s *IssuesService) EditComment(owner string, repo string, id int, comment *IssueComment) (*IssueComment, error) { + u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id) + req, err := s.client.NewRequest("PATCH", u, comment) + if err != nil { + return nil, err + } + c := new(IssueComment) + _, err = s.client.Do(req, c) + return c, err +} + +// DeleteComment deletes an issue comment. +// +// GitHub API docs: http://developer.github.com/v3/issues/comments/#delete-a-comment +func (s *IssuesService) DeleteComment(owner string, repo string, id int) error { + u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id) + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return err + } + _, err = s.client.Do(req, nil) + return err +} diff --git a/github/issues_comments_test.go b/github/issues_comments_test.go new file mode 100644 index 0000000..6d21cc4 --- /dev/null +++ b/github/issues_comments_test.go @@ -0,0 +1,180 @@ +// Copyright 2013 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "encoding/json" + "fmt" + "net/http" + "reflect" + "testing" + "time" +) + +func TestIssuesService_ListComments_allIssues(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/issues/comments", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "sort": "updated", + "direction": "desc", + "since": "2002-02-10T15:30:00Z", + }) + fmt.Fprint(w, `[{"id":1}]`) + }) + + opt := &IssueListCommentsOptions{"updated", "desc", + time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC), + } + comments, err := client.Issues.ListComments("o", "r", 0, opt) + if err != nil { + t.Errorf("Issues.ListComments returned error: %v", err) + } + + want := []IssueComment{IssueComment{ID: 1}} + if !reflect.DeepEqual(comments, want) { + t.Errorf("Issues.ListComments returned %+v, want %+v", comments, want) + } +} + +func TestIssuesService_ListComments_specificIssue(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/issues/1/comments", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{"id":1}]`) + }) + + comments, err := client.Issues.ListComments("o", "r", 1, nil) + if err != nil { + t.Errorf("Issues.ListComments returned error: %v", err) + } + + want := []IssueComment{IssueComment{ID: 1}} + if !reflect.DeepEqual(comments, want) { + t.Errorf("Issues.ListComments returned %+v, want %+v", comments, want) + } +} + +func TestIssuesService_ListComments_invalidOwner(t *testing.T) { + _, err := client.Issues.ListComments("%", "r", 1, nil) + testURLParseError(t, err) +} + +func TestIssuesService_GetComment(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/issues/comments/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{"id":1}`) + }) + + comment, err := client.Issues.GetComment("o", "r", 1) + if err != nil { + t.Errorf("Issues.GetComment returned error: %v", err) + } + + want := &IssueComment{ID: 1} + if !reflect.DeepEqual(comment, want) { + t.Errorf("Issues.GetComment returned %+v, want %+v", comment, want) + } +} + +func TestIssuesService_GetComment_invalidOrg(t *testing.T) { + _, err := client.Issues.GetComment("%", "r", 1) + testURLParseError(t, err) +} + +func TestIssuesService_CreateComment(t *testing.T) { + setup() + defer teardown() + + input := &IssueComment{Body: "b"} + + mux.HandleFunc("/repos/o/r/issues/1/comments", func(w http.ResponseWriter, r *http.Request) { + v := new(IssueComment) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "POST") + if !reflect.DeepEqual(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"id":1}`) + }) + + comment, err := client.Issues.CreateComment("o", "r", 1, input) + if err != nil { + t.Errorf("Issues.CreateComment returned error: %v", err) + } + + want := &IssueComment{ID: 1} + if !reflect.DeepEqual(comment, want) { + t.Errorf("Issues.CreateComment returned %+v, want %+v", comment, want) + } +} + +func TestIssuesService_CreateComment_invalidOrg(t *testing.T) { + _, err := client.Issues.CreateComment("%", "r", 1, nil) + testURLParseError(t, err) +} + +func TestIssuesService_EditComment(t *testing.T) { + setup() + defer teardown() + + input := &IssueComment{Body: "b"} + + mux.HandleFunc("/repos/o/r/issues/comments/1", func(w http.ResponseWriter, r *http.Request) { + v := new(IssueComment) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "PATCH") + if !reflect.DeepEqual(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"id":1}`) + }) + + comment, err := client.Issues.EditComment("o", "r", 1, input) + if err != nil { + t.Errorf("Issues.EditComment returned error: %v", err) + } + + want := &IssueComment{ID: 1} + if !reflect.DeepEqual(comment, want) { + t.Errorf("Issues.EditComment returned %+v, want %+v", comment, want) + } +} + +func TestIssuesService_EditComment_invalidOwner(t *testing.T) { + _, err := client.Issues.EditComment("%", "r", 1, nil) + testURLParseError(t, err) +} + +func TestIssuesService_DeleteComment(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/issues/comments/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + }) + + err := client.Issues.DeleteComment("o", "r", 1) + if err != nil { + t.Errorf("Issues.DeleteComments returned error: %v", err) + } +} + +func TestIssuesService_DeleteComment_invalidOwner(t *testing.T) { + err := client.Issues.DeleteComment("%", "r", 1) + testURLParseError(t, err) +} diff --git a/github/issues_test.go b/github/issues_test.go index 05c0d5c..14878bf 100644 --- a/github/issues_test.go +++ b/github/issues_test.go @@ -226,251 +226,3 @@ func TestIssuesService_Edit_invalidOwner(t *testing.T) { _, err := client.Issues.Edit("%", "r", 1, nil) testURLParseError(t, err) } - -func TestIssuesService_ListAssignees(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/repos/o/r/assignees", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `[{"id":1}]`) - }) - - assignees, err := client.Issues.ListAssignees("o", "r") - if err != nil { - t.Errorf("Issues.List returned error: %v", err) - } - - want := []User{User{ID: 1}} - if !reflect.DeepEqual(assignees, want) { - t.Errorf("Issues.ListAssignees returned %+v, want %+v", assignees, want) - } -} - -func TestIssuesService_ListAssignees_invalidOwner(t *testing.T) { - _, err := client.Issues.ListAssignees("%", "r") - testURLParseError(t, err) -} - -func TestIssuesService_CheckAssignee_true(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - }) - - assignee, err := client.Issues.CheckAssignee("o", "r", "u") - if err != nil { - t.Errorf("Issues.CheckAssignee returned error: %v", err) - } - if want := true; assignee != want { - t.Errorf("Issues.CheckAssignee returned %+v, want %+v", assignee, want) - } -} - -func TestIssuesService_CheckAssignee_false(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - w.WriteHeader(http.StatusNotFound) - }) - - assignee, err := client.Issues.CheckAssignee("o", "r", "u") - if err != nil { - t.Errorf("Issues.CheckAssignee returned error: %v", err) - } - if want := false; assignee != want { - t.Errorf("Issues.CheckAssignee returned %+v, want %+v", assignee, want) - } -} - -func TestIssuesService_CheckAssignee_error(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - http.Error(w, "BadRequest", http.StatusBadRequest) - }) - - assignee, err := client.Issues.CheckAssignee("o", "r", "u") - if err == nil { - t.Errorf("Expected HTTP 400 response") - } - if want := false; assignee != want { - t.Errorf("Issues.CheckAssignee returned %+v, want %+v", assignee, want) - } -} - -func TestIssuesService_CheckAssignee_invalidOwner(t *testing.T) { - _, err := client.Issues.CheckAssignee("%", "r", "u") - testURLParseError(t, err) -} - -func TestIssuesService_ListComments_allIssues(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/repos/o/r/issues/comments", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - testFormValues(t, r, values{ - "sort": "updated", - "direction": "desc", - "since": "2002-02-10T15:30:00Z", - }) - fmt.Fprint(w, `[{"id":1}]`) - }) - - opt := &IssueListCommentsOptions{"updated", "desc", - time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC), - } - comments, err := client.Issues.ListComments("o", "r", 0, opt) - if err != nil { - t.Errorf("Issues.ListComments returned error: %v", err) - } - - want := []IssueComment{IssueComment{ID: 1}} - if !reflect.DeepEqual(comments, want) { - t.Errorf("Issues.ListComments returned %+v, want %+v", comments, want) - } -} - -func TestIssuesService_ListComments_specificIssue(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/repos/o/r/issues/1/comments", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `[{"id":1}]`) - }) - - comments, err := client.Issues.ListComments("o", "r", 1, nil) - if err != nil { - t.Errorf("Issues.ListComments returned error: %v", err) - } - - want := []IssueComment{IssueComment{ID: 1}} - if !reflect.DeepEqual(comments, want) { - t.Errorf("Issues.ListComments returned %+v, want %+v", comments, want) - } -} - -func TestIssuesService_ListComments_invalidOwner(t *testing.T) { - _, err := client.Issues.ListComments("%", "r", 1, nil) - testURLParseError(t, err) -} - -func TestIssuesService_GetComment(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/repos/o/r/issues/comments/1", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `{"id":1}`) - }) - - comment, err := client.Issues.GetComment("o", "r", 1) - if err != nil { - t.Errorf("Issues.GetComment returned error: %v", err) - } - - want := &IssueComment{ID: 1} - if !reflect.DeepEqual(comment, want) { - t.Errorf("Issues.GetComment returned %+v, want %+v", comment, want) - } -} - -func TestIssuesService_GetComment_invalidOrg(t *testing.T) { - _, err := client.Issues.GetComment("%", "r", 1) - testURLParseError(t, err) -} - -func TestIssuesService_CreateComment(t *testing.T) { - setup() - defer teardown() - - input := &IssueComment{Body: "b"} - - mux.HandleFunc("/repos/o/r/issues/1/comments", func(w http.ResponseWriter, r *http.Request) { - v := new(IssueComment) - json.NewDecoder(r.Body).Decode(v) - - testMethod(t, r, "POST") - if !reflect.DeepEqual(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } - - fmt.Fprint(w, `{"id":1}`) - }) - - comment, err := client.Issues.CreateComment("o", "r", 1, input) - if err != nil { - t.Errorf("Issues.CreateComment returned error: %v", err) - } - - want := &IssueComment{ID: 1} - if !reflect.DeepEqual(comment, want) { - t.Errorf("Issues.CreateComment returned %+v, want %+v", comment, want) - } -} - -func TestIssuesService_CreateComment_invalidOrg(t *testing.T) { - _, err := client.Issues.CreateComment("%", "r", 1, nil) - testURLParseError(t, err) -} - -func TestIssuesService_EditComment(t *testing.T) { - setup() - defer teardown() - - input := &IssueComment{Body: "b"} - - mux.HandleFunc("/repos/o/r/issues/comments/1", func(w http.ResponseWriter, r *http.Request) { - v := new(IssueComment) - json.NewDecoder(r.Body).Decode(v) - - testMethod(t, r, "PATCH") - if !reflect.DeepEqual(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } - - fmt.Fprint(w, `{"id":1}`) - }) - - comment, err := client.Issues.EditComment("o", "r", 1, input) - if err != nil { - t.Errorf("Issues.EditComment returned error: %v", err) - } - - want := &IssueComment{ID: 1} - if !reflect.DeepEqual(comment, want) { - t.Errorf("Issues.EditComment returned %+v, want %+v", comment, want) - } -} - -func TestIssuesService_EditComment_invalidOwner(t *testing.T) { - _, err := client.Issues.EditComment("%", "r", 1, nil) - testURLParseError(t, err) -} - -func TestIssuesService_DeleteComment(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/repos/o/r/issues/comments/1", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "DELETE") - }) - - err := client.Issues.DeleteComment("o", "r", 1) - if err != nil { - t.Errorf("Issues.DeleteComments returned error: %v", err) - } -} - -func TestIssuesService_DeleteComment_invalidOwner(t *testing.T) { - err := client.Issues.DeleteComment("%", "r", 1) - testURLParseError(t, err) -}