Browse Source

renaming RepositorySubscription to Subscription

I changed my mind.  This really is terribly verbose, and looking at the
design of the API, it seems unlikely GitHub would change the
subscriptions endpoint to include anything other that repositories.  And
if they do...  well, we'll deal with it.
Will Norris 12 years ago
parent
commit
75b5f1b393
3 changed files with 56 additions and 57 deletions
  1. +15
    -16
      github/activity_watching.go
  2. +30
    -30
      github/activity_watching_test.go
  3. +11
    -11
      tests/integration/activity_test.go

+ 15
- 16
github/activity_watching.go View File

@ -2,8 +2,8 @@ package github
import "fmt" import "fmt"
// RepositorySubscription identifies a repository subscription.
type RepositorySubscription struct {
// Subscription identifies a repository subscription.
type Subscription struct {
Subscribed *bool `json:"subscribed,omitempty"` Subscribed *bool `json:"subscribed,omitempty"`
Ignored *bool `json:"ignored,omitempty"` Ignored *bool `json:"ignored,omitempty"`
Reason *string `json:"reason,omitempty"` Reason *string `json:"reason,omitempty"`
@ -36,12 +36,11 @@ func (s *ActivityService) ListWatchers(owner, repo string, opt *ListOptions) ([]
return *watchers, resp, err return *watchers, resp, err
} }
// ListWatchedRepositories lists the repositories the specified user is watching.
// Passing the empty string will fetch watched repos for the authenticated
// user.
// ListWatched lists the repositories the specified user is watching. Passing
// the empty string will fetch watched repos for the authenticated user.
// //
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#list-repositories-being-watched // GitHub API Docs: https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
func (s *ActivityService) ListWatchedRepositories(user string) ([]Repository, *Response, error) {
func (s *ActivityService) ListWatched(user string) ([]Repository, *Response, error) {
var u string var u string
if user != "" { if user != "" {
u = fmt.Sprintf("users/%v/subscriptions", user) u = fmt.Sprintf("users/%v/subscriptions", user)
@ -62,12 +61,12 @@ func (s *ActivityService) ListWatchedRepositories(user string) ([]Repository, *R
return *watched, resp, err return *watched, resp, err
} }
// GetRepositorySubscription returns the subscription for the specified repository for
// GetSubscription returns the subscription for the specified repository for
// the authenticated user. If the authenticated user is not watching the // the authenticated user. If the authenticated user is not watching the
// repository, a nil RepositorySubscription is returned.
// repository, a nil Subscription is returned.
// //
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#get-a-repository-subscription // GitHub API Docs: https://developer.github.com/v3/activity/watching/#get-a-repository-subscription
func (s *ActivityService) GetRepositorySubscription(owner, repo string) (*RepositorySubscription, *Response, error) {
func (s *ActivityService) GetSubscription(owner, repo string) (*Subscription, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo) u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
@ -75,7 +74,7 @@ func (s *ActivityService) GetRepositorySubscription(owner, repo string) (*Reposi
return nil, nil, err return nil, nil, err
} }
sub := new(RepositorySubscription)
sub := new(Subscription)
resp, err := s.client.Do(req, sub) resp, err := s.client.Do(req, sub)
if err != nil { if err != nil {
// if it's just a 404, don't return that as an error // if it's just a 404, don't return that as an error
@ -86,11 +85,11 @@ func (s *ActivityService) GetRepositorySubscription(owner, repo string) (*Reposi
return sub, resp, err return sub, resp, err
} }
// SetRepositorySubscription sets the subscription for the specified repository for
// the authenticated user.
// SetSubscription sets the subscription for the specified repository for the
// authenticated user.
// //
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#set-a-repository-subscription // GitHub API Docs: https://developer.github.com/v3/activity/watching/#set-a-repository-subscription
func (s *ActivityService) SetRepositorySubscription(owner, repo string, subscription *RepositorySubscription) (*RepositorySubscription, *Response, error) {
func (s *ActivityService) SetSubscription(owner, repo string, subscription *Subscription) (*Subscription, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo) u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
req, err := s.client.NewRequest("PUT", u, subscription) req, err := s.client.NewRequest("PUT", u, subscription)
@ -98,7 +97,7 @@ func (s *ActivityService) SetRepositorySubscription(owner, repo string, subscrip
return nil, nil, err return nil, nil, err
} }
sub := new(RepositorySubscription)
sub := new(Subscription)
resp, err := s.client.Do(req, sub) resp, err := s.client.Do(req, sub)
if err != nil { if err != nil {
return nil, resp, err return nil, resp, err
@ -107,11 +106,11 @@ func (s *ActivityService) SetRepositorySubscription(owner, repo string, subscrip
return sub, resp, err return sub, resp, err
} }
// DeleteRepositorySubscription deletes the subscription for the specified repository for
// DeleteSubscription deletes the subscription for the specified repository for
// the authenticated user. // the authenticated user.
// //
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#delete-a-repository-subscription // GitHub API Docs: https://developer.github.com/v3/activity/watching/#delete-a-repository-subscription
func (s *ActivityService) DeleteRepositorySubscription(owner, repo string) (*Response, error) {
func (s *ActivityService) DeleteSubscription(owner, repo string) (*Response, error) {
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo) u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {


+ 30
- 30
github/activity_watching_test.go View File

@ -32,7 +32,7 @@ func TestActivityService_ListWatchers(t *testing.T) {
} }
} }
func TestActivityService_ListWatchedRepositories_authenticatedUser(t *testing.T) {
func TestActivityService_ListWatched_authenticatedUser(t *testing.T) {
setup() setup()
defer teardown() defer teardown()
@ -41,18 +41,18 @@ func TestActivityService_ListWatchedRepositories_authenticatedUser(t *testing.T)
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
watched, _, err := client.Activity.ListWatchedRepositories("")
watched, _, err := client.Activity.ListWatched("")
if err != nil { if err != nil {
t.Errorf("Activity.ListWatchedRepositories returned error: %v", err)
t.Errorf("Activity.ListWatched returned error: %v", err)
} }
want := []Repository{{ID: Int(1)}} want := []Repository{{ID: Int(1)}}
if !reflect.DeepEqual(watched, want) { if !reflect.DeepEqual(watched, want) {
t.Errorf("Activity.ListWatchedRepositories returned %+v, want %+v", watched, want)
t.Errorf("Activity.ListWatched returned %+v, want %+v", watched, want)
} }
} }
func TestActivityService_ListWatchedRepositories_specifiedUser(t *testing.T) {
func TestActivityService_ListWatched_specifiedUser(t *testing.T) {
setup() setup()
defer teardown() defer teardown()
@ -61,18 +61,18 @@ func TestActivityService_ListWatchedRepositories_specifiedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
watched, _, err := client.Activity.ListWatchedRepositories("u")
watched, _, err := client.Activity.ListWatched("u")
if err != nil { if err != nil {
t.Errorf("Activity.ListWatchedRepositories returned error: %v", err)
t.Errorf("Activity.ListWatched returned error: %v", err)
} }
want := []Repository{{ID: Int(1)}} want := []Repository{{ID: Int(1)}}
if !reflect.DeepEqual(watched, want) { if !reflect.DeepEqual(watched, want) {
t.Errorf("Activity.ListWatchedRepositories returned %+v, want %+v", watched, want)
t.Errorf("Activity.ListWatched returned %+v, want %+v", watched, want)
} }
} }
func TestActivityService_GetRepositorySubscription_true(t *testing.T) {
func TestActivityService_GetSubscription_true(t *testing.T) {
setup() setup()
defer teardown() defer teardown()
@ -81,18 +81,18 @@ func TestActivityService_GetRepositorySubscription_true(t *testing.T) {
fmt.Fprint(w, `{"subscribed":true}`) fmt.Fprint(w, `{"subscribed":true}`)
}) })
sub, _, err := client.Activity.GetRepositorySubscription("o", "r")
sub, _, err := client.Activity.GetSubscription("o", "r")
if err != nil { if err != nil {
t.Errorf("Activity.GetRepositorySubscription returned error: %v", err)
t.Errorf("Activity.GetSubscription returned error: %v", err)
} }
want := &RepositorySubscription{Subscribed: Bool(true)}
want := &Subscription{Subscribed: Bool(true)}
if !reflect.DeepEqual(sub, want) { if !reflect.DeepEqual(sub, want) {
t.Errorf("Activity.GetRepositorySubscription returned %+v, want %+v", sub, want)
t.Errorf("Activity.GetSubscription returned %+v, want %+v", sub, want)
} }
} }
func TestActivityService_GetRepositorySubscription_false(t *testing.T) {
func TestActivityService_GetSubscription_false(t *testing.T) {
setup() setup()
defer teardown() defer teardown()
@ -101,18 +101,18 @@ func TestActivityService_GetRepositorySubscription_false(t *testing.T) {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
}) })
sub, _, err := client.Activity.GetRepositorySubscription("o", "r")
sub, _, err := client.Activity.GetSubscription("o", "r")
if err != nil { if err != nil {
t.Errorf("Activity.GetRepositorySubscription returned error: %v", err)
t.Errorf("Activity.GetSubscription returned error: %v", err)
} }
var want *RepositorySubscription
var want *Subscription
if !reflect.DeepEqual(sub, want) { if !reflect.DeepEqual(sub, want) {
t.Errorf("Activity.GetRepositorySubscription returned %+v, want %+v", sub, want)
t.Errorf("Activity.GetSubscription returned %+v, want %+v", sub, want)
} }
} }
func TestActivityService_GetRepositorySubscription_error(t *testing.T) {
func TestActivityService_GetSubscription_error(t *testing.T) {
setup() setup()
defer teardown() defer teardown()
@ -121,20 +121,20 @@ func TestActivityService_GetRepositorySubscription_error(t *testing.T) {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
}) })
_, _, err := client.Activity.GetRepositorySubscription("o", "r")
_, _, err := client.Activity.GetSubscription("o", "r")
if err == nil { if err == nil {
t.Errorf("Expected HTTP 400 response") t.Errorf("Expected HTTP 400 response")
} }
} }
func TestActivityService_SetRepositorySubscription(t *testing.T) {
func TestActivityService_SetSubscription(t *testing.T) {
setup() setup()
defer teardown() defer teardown()
input := &RepositorySubscription{Subscribed: Bool(true)}
input := &Subscription{Subscribed: Bool(true)}
mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) {
v := new(RepositorySubscription)
v := new(Subscription)
json.NewDecoder(r.Body).Decode(v) json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PUT") testMethod(t, r, "PUT")
@ -145,18 +145,18 @@ func TestActivityService_SetRepositorySubscription(t *testing.T) {
fmt.Fprint(w, `{"ignored":true}`) fmt.Fprint(w, `{"ignored":true}`)
}) })
sub, _, err := client.Activity.SetRepositorySubscription("o", "r", input)
sub, _, err := client.Activity.SetSubscription("o", "r", input)
if err != nil { if err != nil {
t.Errorf("Activity.SetRepositorySubscription returned error: %v", err)
t.Errorf("Activity.SetSubscription returned error: %v", err)
} }
want := &RepositorySubscription{Ignored: Bool(true)}
want := &Subscription{Ignored: Bool(true)}
if !reflect.DeepEqual(sub, want) { if !reflect.DeepEqual(sub, want) {
t.Errorf("Activity.SetRepositorySubscription returned %+v, want %+v", sub, want)
t.Errorf("Activity.SetSubscription returned %+v, want %+v", sub, want)
} }
} }
func TestActivityService_DeleteRepositorySubscription(t *testing.T) {
func TestActivityService_DeleteSubscription(t *testing.T) {
setup() setup()
defer teardown() defer teardown()
@ -164,8 +164,8 @@ func TestActivityService_DeleteRepositorySubscription(t *testing.T) {
testMethod(t, r, "DELETE") testMethod(t, r, "DELETE")
}) })
_, err := client.Activity.DeleteRepositorySubscription("o", "r")
_, err := client.Activity.DeleteSubscription("o", "r")
if err != nil { if err != nil {
t.Errorf("Activity.DeleteRepositorySubscription returned error: %v", err)
t.Errorf("Activity.DeleteSubscription returned error: %v", err)
} }
} }

+ 11
- 11
tests/integration/activity_test.go View File

@ -17,40 +17,40 @@ func TestActivity_Watching(t *testing.T) {
} }
// first, check if already watching google/go-github // first, check if already watching google/go-github
sub, _, err := client.Activity.GetRepositorySubscription("google", "go-github")
sub, _, err := client.Activity.GetSubscription("google", "go-github")
if err != nil { if err != nil {
t.Fatalf("Activity.GetRepositorySubscription returned error: %v", err)
t.Fatalf("Activity.GetSubscription returned error: %v", err)
} }
if sub != nil { if sub != nil {
t.Fatalf("Already watching google/go-github. Please manually stop watching it first.") t.Fatalf("Already watching google/go-github. Please manually stop watching it first.")
} }
// watch google/go-github // watch google/go-github
sub = &github.RepositorySubscription{Subscribed: github.Bool(true)}
_, _, err = client.Activity.SetRepositorySubscription("google", "go-github", sub)
sub = &github.Subscription{Subscribed: github.Bool(true)}
_, _, err = client.Activity.SetSubscription("google", "go-github", sub)
if err != nil { if err != nil {
t.Fatalf("Activity.SetRepositorySubscription returned error: %v", err)
t.Fatalf("Activity.SetSubscription returned error: %v", err)
} }
// check again and verify watching // check again and verify watching
sub, _, err = client.Activity.GetRepositorySubscription("google", "go-github")
sub, _, err = client.Activity.GetSubscription("google", "go-github")
if err != nil { if err != nil {
t.Fatalf("Activity.GetRepositorySubscription returned error: %v", err)
t.Fatalf("Activity.GetSubscription returned error: %v", err)
} }
if sub == nil || !*sub.Subscribed { if sub == nil || !*sub.Subscribed {
t.Fatalf("Not watching google/go-github after setting subscription.") t.Fatalf("Not watching google/go-github after setting subscription.")
} }
// delete subscription // delete subscription
_, err = client.Activity.DeleteRepositorySubscription("google", "go-github")
_, err = client.Activity.DeleteSubscription("google", "go-github")
if err != nil { if err != nil {
t.Fatalf("Activity.DeleteRepositorySubscription returned error: %v", err)
t.Fatalf("Activity.DeleteSubscription returned error: %v", err)
} }
// check again and verify not watching // check again and verify not watching
sub, _, err = client.Activity.GetRepositorySubscription("google", "go-github")
sub, _, err = client.Activity.GetSubscription("google", "go-github")
if err != nil { if err != nil {
t.Fatalf("Activity.GetRepositorySubscription returned error: %v", err)
t.Fatalf("Activity.GetSubscription returned error: %v", err)
} }
if sub != nil { if sub != nil {
t.Fatalf("Still watching google/go-github after deleting subscription.") t.Fatalf("Still watching google/go-github after deleting subscription.")


Loading…
Cancel
Save