Skip to content

Commit 75b5f1b

Browse files
committed
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.
1 parent 3561cc2 commit 75b5f1b

File tree

3 files changed

+56
-57
lines changed

3 files changed

+56
-57
lines changed

github/activity_watching.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package github
22

33
import "fmt"
44

5-
// RepositorySubscription identifies a repository subscription.
6-
type RepositorySubscription struct {
5+
// Subscription identifies a repository subscription.
6+
type Subscription struct {
77
Subscribed *bool `json:"subscribed,omitempty"`
88
Ignored *bool `json:"ignored,omitempty"`
99
Reason *string `json:"reason,omitempty"`
@@ -36,12 +36,11 @@ func (s *ActivityService) ListWatchers(owner, repo string, opt *ListOptions) ([]
3636
return *watchers, resp, err
3737
}
3838

39-
// ListWatchedRepositories lists the repositories the specified user is watching.
40-
// Passing the empty string will fetch watched repos for the authenticated
41-
// user.
39+
// ListWatched lists the repositories the specified user is watching. Passing
40+
// the empty string will fetch watched repos for the authenticated user.
4241
//
4342
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
44-
func (s *ActivityService) ListWatchedRepositories(user string) ([]Repository, *Response, error) {
43+
func (s *ActivityService) ListWatched(user string) ([]Repository, *Response, error) {
4544
var u string
4645
if user != "" {
4746
u = fmt.Sprintf("users/%v/subscriptions", user)
@@ -62,20 +61,20 @@ func (s *ActivityService) ListWatchedRepositories(user string) ([]Repository, *R
6261
return *watched, resp, err
6362
}
6463

65-
// GetRepositorySubscription returns the subscription for the specified repository for
64+
// GetSubscription returns the subscription for the specified repository for
6665
// the authenticated user. If the authenticated user is not watching the
67-
// repository, a nil RepositorySubscription is returned.
66+
// repository, a nil Subscription is returned.
6867
//
6968
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#get-a-repository-subscription
70-
func (s *ActivityService) GetRepositorySubscription(owner, repo string) (*RepositorySubscription, *Response, error) {
69+
func (s *ActivityService) GetSubscription(owner, repo string) (*Subscription, *Response, error) {
7170
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
7271

7372
req, err := s.client.NewRequest("GET", u, nil)
7473
if err != nil {
7574
return nil, nil, err
7675
}
7776

78-
sub := new(RepositorySubscription)
77+
sub := new(Subscription)
7978
resp, err := s.client.Do(req, sub)
8079
if err != nil {
8180
// if it's just a 404, don't return that as an error
@@ -86,19 +85,19 @@ func (s *ActivityService) GetRepositorySubscription(owner, repo string) (*Reposi
8685
return sub, resp, err
8786
}
8887

89-
// SetRepositorySubscription sets the subscription for the specified repository for
90-
// the authenticated user.
88+
// SetSubscription sets the subscription for the specified repository for the
89+
// authenticated user.
9190
//
9291
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#set-a-repository-subscription
93-
func (s *ActivityService) SetRepositorySubscription(owner, repo string, subscription *RepositorySubscription) (*RepositorySubscription, *Response, error) {
92+
func (s *ActivityService) SetSubscription(owner, repo string, subscription *Subscription) (*Subscription, *Response, error) {
9493
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
9594

9695
req, err := s.client.NewRequest("PUT", u, subscription)
9796
if err != nil {
9897
return nil, nil, err
9998
}
10099

101-
sub := new(RepositorySubscription)
100+
sub := new(Subscription)
102101
resp, err := s.client.Do(req, sub)
103102
if err != nil {
104103
return nil, resp, err
@@ -107,11 +106,11 @@ func (s *ActivityService) SetRepositorySubscription(owner, repo string, subscrip
107106
return sub, resp, err
108107
}
109108

110-
// DeleteRepositorySubscription deletes the subscription for the specified repository for
109+
// DeleteSubscription deletes the subscription for the specified repository for
111110
// the authenticated user.
112111
//
113112
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#delete-a-repository-subscription
114-
func (s *ActivityService) DeleteRepositorySubscription(owner, repo string) (*Response, error) {
113+
func (s *ActivityService) DeleteSubscription(owner, repo string) (*Response, error) {
115114
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
116115
req, err := s.client.NewRequest("DELETE", u, nil)
117116
if err != nil {

github/activity_watching_test.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestActivityService_ListWatchers(t *testing.T) {
3232
}
3333
}
3434

35-
func TestActivityService_ListWatchedRepositories_authenticatedUser(t *testing.T) {
35+
func TestActivityService_ListWatched_authenticatedUser(t *testing.T) {
3636
setup()
3737
defer teardown()
3838

@@ -41,18 +41,18 @@ func TestActivityService_ListWatchedRepositories_authenticatedUser(t *testing.T)
4141
fmt.Fprint(w, `[{"id":1}]`)
4242
})
4343

44-
watched, _, err := client.Activity.ListWatchedRepositories("")
44+
watched, _, err := client.Activity.ListWatched("")
4545
if err != nil {
46-
t.Errorf("Activity.ListWatchedRepositories returned error: %v", err)
46+
t.Errorf("Activity.ListWatched returned error: %v", err)
4747
}
4848

4949
want := []Repository{{ID: Int(1)}}
5050
if !reflect.DeepEqual(watched, want) {
51-
t.Errorf("Activity.ListWatchedRepositories returned %+v, want %+v", watched, want)
51+
t.Errorf("Activity.ListWatched returned %+v, want %+v", watched, want)
5252
}
5353
}
5454

55-
func TestActivityService_ListWatchedRepositories_specifiedUser(t *testing.T) {
55+
func TestActivityService_ListWatched_specifiedUser(t *testing.T) {
5656
setup()
5757
defer teardown()
5858

@@ -61,18 +61,18 @@ func TestActivityService_ListWatchedRepositories_specifiedUser(t *testing.T) {
6161
fmt.Fprint(w, `[{"id":1}]`)
6262
})
6363

64-
watched, _, err := client.Activity.ListWatchedRepositories("u")
64+
watched, _, err := client.Activity.ListWatched("u")
6565
if err != nil {
66-
t.Errorf("Activity.ListWatchedRepositories returned error: %v", err)
66+
t.Errorf("Activity.ListWatched returned error: %v", err)
6767
}
6868

6969
want := []Repository{{ID: Int(1)}}
7070
if !reflect.DeepEqual(watched, want) {
71-
t.Errorf("Activity.ListWatchedRepositories returned %+v, want %+v", watched, want)
71+
t.Errorf("Activity.ListWatched returned %+v, want %+v", watched, want)
7272
}
7373
}
7474

75-
func TestActivityService_GetRepositorySubscription_true(t *testing.T) {
75+
func TestActivityService_GetSubscription_true(t *testing.T) {
7676
setup()
7777
defer teardown()
7878

@@ -81,18 +81,18 @@ func TestActivityService_GetRepositorySubscription_true(t *testing.T) {
8181
fmt.Fprint(w, `{"subscribed":true}`)
8282
})
8383

84-
sub, _, err := client.Activity.GetRepositorySubscription("o", "r")
84+
sub, _, err := client.Activity.GetSubscription("o", "r")
8585
if err != nil {
86-
t.Errorf("Activity.GetRepositorySubscription returned error: %v", err)
86+
t.Errorf("Activity.GetSubscription returned error: %v", err)
8787
}
8888

89-
want := &RepositorySubscription{Subscribed: Bool(true)}
89+
want := &Subscription{Subscribed: Bool(true)}
9090
if !reflect.DeepEqual(sub, want) {
91-
t.Errorf("Activity.GetRepositorySubscription returned %+v, want %+v", sub, want)
91+
t.Errorf("Activity.GetSubscription returned %+v, want %+v", sub, want)
9292
}
9393
}
9494

95-
func TestActivityService_GetRepositorySubscription_false(t *testing.T) {
95+
func TestActivityService_GetSubscription_false(t *testing.T) {
9696
setup()
9797
defer teardown()
9898

@@ -101,18 +101,18 @@ func TestActivityService_GetRepositorySubscription_false(t *testing.T) {
101101
w.WriteHeader(http.StatusNotFound)
102102
})
103103

104-
sub, _, err := client.Activity.GetRepositorySubscription("o", "r")
104+
sub, _, err := client.Activity.GetSubscription("o", "r")
105105
if err != nil {
106-
t.Errorf("Activity.GetRepositorySubscription returned error: %v", err)
106+
t.Errorf("Activity.GetSubscription returned error: %v", err)
107107
}
108108

109-
var want *RepositorySubscription
109+
var want *Subscription
110110
if !reflect.DeepEqual(sub, want) {
111-
t.Errorf("Activity.GetRepositorySubscription returned %+v, want %+v", sub, want)
111+
t.Errorf("Activity.GetSubscription returned %+v, want %+v", sub, want)
112112
}
113113
}
114114

115-
func TestActivityService_GetRepositorySubscription_error(t *testing.T) {
115+
func TestActivityService_GetSubscription_error(t *testing.T) {
116116
setup()
117117
defer teardown()
118118

@@ -121,20 +121,20 @@ func TestActivityService_GetRepositorySubscription_error(t *testing.T) {
121121
w.WriteHeader(http.StatusBadRequest)
122122
})
123123

124-
_, _, err := client.Activity.GetRepositorySubscription("o", "r")
124+
_, _, err := client.Activity.GetSubscription("o", "r")
125125
if err == nil {
126126
t.Errorf("Expected HTTP 400 response")
127127
}
128128
}
129129

130-
func TestActivityService_SetRepositorySubscription(t *testing.T) {
130+
func TestActivityService_SetSubscription(t *testing.T) {
131131
setup()
132132
defer teardown()
133133

134-
input := &RepositorySubscription{Subscribed: Bool(true)}
134+
input := &Subscription{Subscribed: Bool(true)}
135135

136136
mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) {
137-
v := new(RepositorySubscription)
137+
v := new(Subscription)
138138
json.NewDecoder(r.Body).Decode(v)
139139

140140
testMethod(t, r, "PUT")
@@ -145,27 +145,27 @@ func TestActivityService_SetRepositorySubscription(t *testing.T) {
145145
fmt.Fprint(w, `{"ignored":true}`)
146146
})
147147

148-
sub, _, err := client.Activity.SetRepositorySubscription("o", "r", input)
148+
sub, _, err := client.Activity.SetSubscription("o", "r", input)
149149
if err != nil {
150-
t.Errorf("Activity.SetRepositorySubscription returned error: %v", err)
150+
t.Errorf("Activity.SetSubscription returned error: %v", err)
151151
}
152152

153-
want := &RepositorySubscription{Ignored: Bool(true)}
153+
want := &Subscription{Ignored: Bool(true)}
154154
if !reflect.DeepEqual(sub, want) {
155-
t.Errorf("Activity.SetRepositorySubscription returned %+v, want %+v", sub, want)
155+
t.Errorf("Activity.SetSubscription returned %+v, want %+v", sub, want)
156156
}
157157
}
158158

159-
func TestActivityService_DeleteRepositorySubscription(t *testing.T) {
159+
func TestActivityService_DeleteSubscription(t *testing.T) {
160160
setup()
161161
defer teardown()
162162

163163
mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) {
164164
testMethod(t, r, "DELETE")
165165
})
166166

167-
_, err := client.Activity.DeleteRepositorySubscription("o", "r")
167+
_, err := client.Activity.DeleteSubscription("o", "r")
168168
if err != nil {
169-
t.Errorf("Activity.DeleteRepositorySubscription returned error: %v", err)
169+
t.Errorf("Activity.DeleteSubscription returned error: %v", err)
170170
}
171171
}

tests/integration/activity_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,40 @@ func TestActivity_Watching(t *testing.T) {
1717
}
1818

1919
// first, check if already watching google/go-github
20-
sub, _, err := client.Activity.GetRepositorySubscription("google", "go-github")
20+
sub, _, err := client.Activity.GetSubscription("google", "go-github")
2121
if err != nil {
22-
t.Fatalf("Activity.GetRepositorySubscription returned error: %v", err)
22+
t.Fatalf("Activity.GetSubscription returned error: %v", err)
2323
}
2424
if sub != nil {
2525
t.Fatalf("Already watching google/go-github. Please manually stop watching it first.")
2626
}
2727

2828
// watch google/go-github
29-
sub = &github.RepositorySubscription{Subscribed: github.Bool(true)}
30-
_, _, err = client.Activity.SetRepositorySubscription("google", "go-github", sub)
29+
sub = &github.Subscription{Subscribed: github.Bool(true)}
30+
_, _, err = client.Activity.SetSubscription("google", "go-github", sub)
3131
if err != nil {
32-
t.Fatalf("Activity.SetRepositorySubscription returned error: %v", err)
32+
t.Fatalf("Activity.SetSubscription returned error: %v", err)
3333
}
3434

3535
// check again and verify watching
36-
sub, _, err = client.Activity.GetRepositorySubscription("google", "go-github")
36+
sub, _, err = client.Activity.GetSubscription("google", "go-github")
3737
if err != nil {
38-
t.Fatalf("Activity.GetRepositorySubscription returned error: %v", err)
38+
t.Fatalf("Activity.GetSubscription returned error: %v", err)
3939
}
4040
if sub == nil || !*sub.Subscribed {
4141
t.Fatalf("Not watching google/go-github after setting subscription.")
4242
}
4343

4444
// delete subscription
45-
_, err = client.Activity.DeleteRepositorySubscription("google", "go-github")
45+
_, err = client.Activity.DeleteSubscription("google", "go-github")
4646
if err != nil {
47-
t.Fatalf("Activity.DeleteRepositorySubscription returned error: %v", err)
47+
t.Fatalf("Activity.DeleteSubscription returned error: %v", err)
4848
}
4949

5050
// check again and verify not watching
51-
sub, _, err = client.Activity.GetRepositorySubscription("google", "go-github")
51+
sub, _, err = client.Activity.GetSubscription("google", "go-github")
5252
if err != nil {
53-
t.Fatalf("Activity.GetRepositorySubscription returned error: %v", err)
53+
t.Fatalf("Activity.GetSubscription returned error: %v", err)
5454
}
5555
if sub != nil {
5656
t.Fatalf("Still watching google/go-github after deleting subscription.")

0 commit comments

Comments
 (0)