Browse Source

Add support for listing watchers

Amey Sakhadeo 12 years ago
committed by Will Norris
parent
commit
b4885541b1
2 changed files with 51 additions and 0 deletions
  1. +23
    -0
      github/activity_watching.go
  2. +28
    -0
      github/activity_watching_test.go

+ 23
- 0
github/activity_watching.go View File

@ -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
}

+ 28
- 0
github/activity_watching_test.go View File

@ -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)
}
}

Loading…
Cancel
Save