Skip to content

Commit a61f2c4

Browse files
committed
Restructured Issues Service files.
1 parent 1e532bd commit a61f2c4

File tree

6 files changed

+436
-386
lines changed

6 files changed

+436
-386
lines changed

github/issues.go

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ type Issue struct {
3737
// TODO(willnorris): labels and milestone
3838
}
3939

40-
// IssueComment represents a comment left on an issue.
41-
type IssueComment struct {
42-
ID int `json:"id,omitempty"`
43-
Body string `json:"body,omitempty"`
44-
User *User `json:"user,omitempty"`
45-
CreatedAt *time.Time `json:"created_at,omitempty"`
46-
UpdatedAt *time.Time `json:"updated_at,omitempty"`
47-
}
48-
4940
// IssueListOptions specifies the optional parameters to the IssuesService.List
5041
// and IssuesService.ListByOrg methods.
5142
type IssueListOptions struct {
@@ -237,132 +228,3 @@ func (s *IssuesService) Edit(owner string, repo string, number int, issue *Issue
237228
_, err = s.client.Do(req, i)
238229
return i, err
239230
}
240-
241-
// ListAssignees fetches all available assignees (owners and collaborators) to
242-
// which issues may be assigned.
243-
//
244-
// GitHub API docs: http://developer.github.com/v3/issues/assignees/#list-assignees
245-
func (s *IssuesService) ListAssignees(owner string, repo string) ([]User, error) {
246-
u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo)
247-
req, err := s.client.NewRequest("GET", u, nil)
248-
if err != nil {
249-
return nil, err
250-
}
251-
assignees := new([]User)
252-
_, err = s.client.Do(req, assignees)
253-
return *assignees, err
254-
}
255-
256-
// CheckAssignee checks if a user is an assignee for the specified repository.
257-
//
258-
// GitHub API docs: http://developer.github.com/v3/issues/assignees/#check-assignee
259-
func (s *IssuesService) CheckAssignee(owner string, repo string, user string) (bool, error) {
260-
u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user)
261-
req, err := s.client.NewRequest("GET", u, nil)
262-
if err != nil {
263-
return false, err
264-
}
265-
_, err = s.client.Do(req, nil)
266-
return parseBoolResponse(err)
267-
}
268-
269-
// IssueListCommentsOptions specifies the optional parameters to the
270-
// IssuesService.ListComments method.
271-
type IssueListCommentsOptions struct {
272-
// Sort specifies how to sort comments. Possible values are: created, updated.
273-
Sort string
274-
275-
// Direction in which to sort comments. Possible values are: asc, desc.
276-
Direction string
277-
278-
// Since filters comments by time.
279-
Since time.Time
280-
}
281-
282-
// ListComments lists all comments on the specified issue. Specifying an issue
283-
// number of 0 will return all comments on all issues for the repository.
284-
//
285-
// GitHub API docs: http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
286-
func (s *IssuesService) ListComments(owner string, repo string, number int, opt *IssueListCommentsOptions) ([]IssueComment, error) {
287-
var u string
288-
if number == 0 {
289-
u = fmt.Sprintf("repos/%v/%v/issues/comments", owner, repo)
290-
} else {
291-
u = fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
292-
}
293-
294-
if opt != nil {
295-
params := url.Values{
296-
"sort": {opt.Sort},
297-
"direction": {opt.Direction},
298-
}
299-
if !opt.Since.IsZero() {
300-
params.Add("since", opt.Since.Format(time.RFC3339))
301-
}
302-
u += "?" + params.Encode()
303-
}
304-
305-
req, err := s.client.NewRequest("GET", u, nil)
306-
if err != nil {
307-
return nil, err
308-
}
309-
comments := new([]IssueComment)
310-
_, err = s.client.Do(req, comments)
311-
return *comments, err
312-
}
313-
314-
// GetComment fetches the specified issue comment.
315-
//
316-
// GitHub API docs: http://developer.github.com/v3/issues/comments/#get-a-single-comment
317-
func (s *IssuesService) GetComment(owner string, repo string, id int) (*IssueComment, error) {
318-
u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id)
319-
320-
req, err := s.client.NewRequest("GET", u, nil)
321-
if err != nil {
322-
return nil, err
323-
}
324-
comment := new(IssueComment)
325-
_, err = s.client.Do(req, comment)
326-
return comment, err
327-
}
328-
329-
// CreateComment creates a new comment on the specified issue.
330-
//
331-
// GitHub API docs: http://developer.github.com/v3/issues/comments/#create-a-comment
332-
func (s *IssuesService) CreateComment(owner string, repo string, number int, comment *IssueComment) (*IssueComment, error) {
333-
u := fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
334-
req, err := s.client.NewRequest("POST", u, comment)
335-
if err != nil {
336-
return nil, err
337-
}
338-
c := new(IssueComment)
339-
_, err = s.client.Do(req, c)
340-
return c, err
341-
}
342-
343-
// EditComment updates an issue comment.
344-
//
345-
// GitHub API docs: http://developer.github.com/v3/issues/comments/#edit-a-comment
346-
func (s *IssuesService) EditComment(owner string, repo string, id int, comment *IssueComment) (*IssueComment, error) {
347-
u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id)
348-
req, err := s.client.NewRequest("PATCH", u, comment)
349-
if err != nil {
350-
return nil, err
351-
}
352-
c := new(IssueComment)
353-
_, err = s.client.Do(req, c)
354-
return c, err
355-
}
356-
357-
// DeleteComment deletes an issue comment.
358-
//
359-
// GitHub API docs: http://developer.github.com/v3/issues/comments/#delete-a-comment
360-
func (s *IssuesService) DeleteComment(owner string, repo string, id int) error {
361-
u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id)
362-
req, err := s.client.NewRequest("DELETE", u, nil)
363-
if err != nil {
364-
return err
365-
}
366-
_, err = s.client.Do(req, nil)
367-
return err
368-
}

github/issues_assignees.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2013 The go-github AUTHORS. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style
4+
// license that can be found in the LICENSE file.
5+
6+
package github
7+
8+
import (
9+
"fmt"
10+
)
11+
12+
// ListAssignees fetches all available assignees (owners and collaborators) to
13+
// which issues may be assigned.
14+
//
15+
// GitHub API docs: http://developer.github.com/v3/issues/assignees/#list-assignees
16+
func (s *IssuesService) ListAssignees(owner string, repo string) ([]User, error) {
17+
u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo)
18+
req, err := s.client.NewRequest("GET", u, nil)
19+
if err != nil {
20+
return nil, err
21+
}
22+
assignees := new([]User)
23+
_, err = s.client.Do(req, assignees)
24+
return *assignees, err
25+
}
26+
27+
// CheckAssignee checks if a user is an assignee for the specified repository.
28+
//
29+
// GitHub API docs: http://developer.github.com/v3/issues/assignees/#check-assignee
30+
func (s *IssuesService) CheckAssignee(owner string, repo string, user string) (bool, error) {
31+
u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user)
32+
req, err := s.client.NewRequest("GET", u, nil)
33+
if err != nil {
34+
return false, err
35+
}
36+
_, err = s.client.Do(req, nil)
37+
return parseBoolResponse(err)
38+
}

github/issues_assignees_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright 2013 The go-github AUTHORS. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style
4+
// license that can be found in the LICENSE file.
5+
6+
package github
7+
8+
import (
9+
"fmt"
10+
"net/http"
11+
"reflect"
12+
"testing"
13+
)
14+
15+
func TestIssuesService_ListAssignees(t *testing.T) {
16+
setup()
17+
defer teardown()
18+
19+
mux.HandleFunc("/repos/o/r/assignees", func(w http.ResponseWriter, r *http.Request) {
20+
testMethod(t, r, "GET")
21+
fmt.Fprint(w, `[{"id":1}]`)
22+
})
23+
24+
assignees, err := client.Issues.ListAssignees("o", "r")
25+
if err != nil {
26+
t.Errorf("Issues.List returned error: %v", err)
27+
}
28+
29+
want := []User{User{ID: 1}}
30+
if !reflect.DeepEqual(assignees, want) {
31+
t.Errorf("Issues.ListAssignees returned %+v, want %+v", assignees, want)
32+
}
33+
}
34+
35+
func TestIssuesService_ListAssignees_invalidOwner(t *testing.T) {
36+
_, err := client.Issues.ListAssignees("%", "r")
37+
testURLParseError(t, err)
38+
}
39+
40+
func TestIssuesService_CheckAssignee_true(t *testing.T) {
41+
setup()
42+
defer teardown()
43+
44+
mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) {
45+
testMethod(t, r, "GET")
46+
})
47+
48+
assignee, err := client.Issues.CheckAssignee("o", "r", "u")
49+
if err != nil {
50+
t.Errorf("Issues.CheckAssignee returned error: %v", err)
51+
}
52+
if want := true; assignee != want {
53+
t.Errorf("Issues.CheckAssignee returned %+v, want %+v", assignee, want)
54+
}
55+
}
56+
57+
func TestIssuesService_CheckAssignee_false(t *testing.T) {
58+
setup()
59+
defer teardown()
60+
61+
mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) {
62+
testMethod(t, r, "GET")
63+
w.WriteHeader(http.StatusNotFound)
64+
})
65+
66+
assignee, err := client.Issues.CheckAssignee("o", "r", "u")
67+
if err != nil {
68+
t.Errorf("Issues.CheckAssignee returned error: %v", err)
69+
}
70+
if want := false; assignee != want {
71+
t.Errorf("Issues.CheckAssignee returned %+v, want %+v", assignee, want)
72+
}
73+
}
74+
75+
func TestIssuesService_CheckAssignee_error(t *testing.T) {
76+
setup()
77+
defer teardown()
78+
79+
mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) {
80+
testMethod(t, r, "GET")
81+
http.Error(w, "BadRequest", http.StatusBadRequest)
82+
})
83+
84+
assignee, err := client.Issues.CheckAssignee("o", "r", "u")
85+
if err == nil {
86+
t.Errorf("Expected HTTP 400 response")
87+
}
88+
if want := false; assignee != want {
89+
t.Errorf("Issues.CheckAssignee returned %+v, want %+v", assignee, want)
90+
}
91+
}
92+
93+
func TestIssuesService_CheckAssignee_invalidOwner(t *testing.T) {
94+
_, err := client.Issues.CheckAssignee("%", "r", "u")
95+
testURLParseError(t, err)
96+
}

0 commit comments

Comments
 (0)