Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c57bb02

Browse files
sona-tarwillnorris
authored andcommitted
Add ListOptions to ListWatched
1 parent abea5d2 commit c57bb02

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

github/activity_watching.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,18 @@ func (s *ActivityService) ListWatchers(owner, repo string, opt *ListOptions) ([]
5050
// the empty string will fetch watched repos for the authenticated user.
5151
//
5252
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
53-
func (s *ActivityService) ListWatched(user string) ([]Repository, *Response, error) {
53+
func (s *ActivityService) ListWatched(user string, opt *ListOptions) ([]Repository, *Response, error) {
5454
var u string
5555
if user != "" {
5656
u = fmt.Sprintf("users/%v/subscriptions", user)
5757
} else {
5858
u = "user/subscriptions"
5959
}
60+
u, err := addOptions(u, opt)
61+
if err != nil {
62+
return nil, nil, err
63+
}
64+
6065
req, err := s.client.NewRequest("GET", u, nil)
6166
if err != nil {
6267
return nil, nil, err

github/activity_watching_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ func TestActivityService_ListWatched_authenticatedUser(t *testing.T) {
4343

4444
mux.HandleFunc("/user/subscriptions", func(w http.ResponseWriter, r *http.Request) {
4545
testMethod(t, r, "GET")
46+
testFormValues(t, r, values{
47+
"page": "2",
48+
})
4649
fmt.Fprint(w, `[{"id":1}]`)
4750
})
4851

49-
watched, _, err := client.Activity.ListWatched("")
52+
watched, _, err := client.Activity.ListWatched("", &ListOptions{Page: 2})
5053
if err != nil {
5154
t.Errorf("Activity.ListWatched returned error: %v", err)
5255
}
@@ -63,10 +66,14 @@ func TestActivityService_ListWatched_specifiedUser(t *testing.T) {
6366

6467
mux.HandleFunc("/users/u/subscriptions", func(w http.ResponseWriter, r *http.Request) {
6568
testMethod(t, r, "GET")
69+
testFormValues(t, r, values{
70+
"page": "2",
71+
})
6672
fmt.Fprint(w, `[{"id":1}]`)
6773
})
6874

69-
watched, _, err := client.Activity.ListWatched("u")
75+
watched, _, err := client.Activity.ListWatched("u", &ListOptions{Page: 2})
76+
7077
if err != nil {
7178
t.Errorf("Activity.ListWatched returned error: %v", err)
7279
}

0 commit comments

Comments
 (0)