From b4885541b18634555a0e34df8b8a545bd5258250 Mon Sep 17 00:00:00 2001 From: Amey Sakhadeo Date: Sat, 19 Oct 2013 19:05:40 +0530 Subject: [PATCH] Add support for listing watchers --- github/activity_watching.go | 23 +++++++++++++++++++++++ github/activity_watching_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 github/activity_watching.go create mode 100644 github/activity_watching_test.go diff --git a/github/activity_watching.go b/github/activity_watching.go new file mode 100644 index 0000000..25f2929 --- /dev/null +++ b/github/activity_watching.go @@ -0,0 +1,23 @@ +package github + +import "fmt" + +// ListWatchers lists watchers of a particular repo. +// +// GitHub API Docs: http://developer.github.com/v3/activity/watching/#list-watchers +func (s *ActivityService) ListWatchers(owner, repo string) ([]User, *Response, error) { + url := fmt.Sprintf("repos/%s/%s/subscribers", owner, repo) + + req, err := s.client.NewRequest("GET", url, nil) + if err != nil { + return nil, nil, err + } + + watchers := new([]User) + resp, err := s.client.Do(req, watchers) + if err != nil { + return nil, resp, err + } + + return *watchers, resp, err +} diff --git a/github/activity_watching_test.go b/github/activity_watching_test.go new file mode 100644 index 0000000..72f1b51 --- /dev/null +++ b/github/activity_watching_test.go @@ -0,0 +1,28 @@ +package github + +import ( + "fmt" + "net/http" + "reflect" + "testing" +) + +func TestActivityService_ListWatchers(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/subscribers", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{"id":1}]`) + }) + + watchers, _, err := client.Activity.ListWatchers("o", "r") + if err != nil { + t.Errorf("Activity.ListWatchers returned error: %v", err) + } + + want := []User{{ID: Int(1)}} + if !reflect.DeepEqual(watchers, want) { + t.Errorf("Activity.ListWatchers returned %+v, want %+v", watchers, want) + } +}