Skip to content

Commit 2a4b920

Browse files
authored
Remove deprecated identifiers. (google#555)
This is a breaking API change. However, it removes things that were deprecated and shouldn't be used anymore (including something that's available in standard library). Next commit will be a large breaking API change anyway (which we need to do in order to resolve google#526 in a reasonable way), so it makes more sense to get rid of the deprecated things instead of updating their API. http.StatusUnprocessableEntity was added in Go 1.7, and so we can use it instead of own equivalent constant. Anyone who was previously using it should switch to using http.StatusUnprocessableEntity as well. Consider this commit to deprecate StatusUnprocessableEntity and remove it in one. Helps google#526.
1 parent 796decd commit 2a4b920

10 files changed

+15
-158
lines changed

github/activity_events.go

-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ func (e *Event) Payload() (payload interface{}) {
4949
payload = &IntegrationInstallationEvent{}
5050
case "IntegrationInstallationRepositoriesEvent":
5151
payload = &IntegrationInstallationRepositoriesEvent{}
52-
case "IssueActivityEvent":
53-
payload = &IssueActivityEvent{}
5452
case "IssueCommentEvent":
5553
payload = &IssueCommentEvent{}
5654
case "IssuesEvent":

github/event_types.go

-13
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,6 @@ type GollumEvent struct {
130130
Installation *Installation `json:"installation,omitempty"`
131131
}
132132

133-
// IssueActivityEvent represents the payload delivered by Issue webhook.
134-
//
135-
// Deprecated: Use IssuesEvent instead.
136-
type IssueActivityEvent struct {
137-
Action *string `json:"action,omitempty"`
138-
Issue *Issue `json:"issue,omitempty"`
139-
140-
// The following fields are only populated by Webhook events.
141-
Repo *Repository `json:"repository,omitempty"`
142-
Sender *User `json:"sender,omitempty"`
143-
Installation *Installation `json:"installation,omitempty"`
144-
}
145-
146133
// EditChange represents the changes when an issue, pull request, or comment has
147134
// been edited.
148135
type EditChange struct {

github/github.go

-32
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ import (
2323
"github.com/google/go-querystring/query"
2424
)
2525

26-
const (
27-
// StatusUnprocessableEntity is the status code returned when sending a request with invalid fields.
28-
StatusUnprocessableEntity = 422
29-
)
30-
3126
const (
3227
libraryVersion = "3"
3328
defaultBaseURL = "https://api.github.com/"
@@ -383,19 +378,6 @@ func parseRate(r *http.Response) Rate {
383378
return rate
384379
}
385380

386-
// Rate specifies the current rate limit for the client as determined by the
387-
// most recent API call. If the client is used in a multi-user application,
388-
// this rate may not always be up-to-date.
389-
//
390-
// Deprecated: Use the Response.Rate returned from most recent API call instead.
391-
// Call RateLimits() to check the current rate.
392-
func (c *Client) Rate() Rate {
393-
c.rateMu.Lock()
394-
rate := c.rateLimits[c.mostRecent]
395-
c.rateMu.Unlock()
396-
return rate
397-
}
398-
399381
// Do sends an API request and returns the API response. The API response is
400382
// JSON decoded and stored in the value pointed to by v, or returned as an
401383
// error if an API error has occurred. If v implements the io.Writer
@@ -730,20 +712,6 @@ func category(path string) rateLimitCategory {
730712
}
731713
}
732714

733-
// RateLimit returns the core rate limit for the current client.
734-
//
735-
// Deprecated: RateLimit is deprecated, use RateLimits instead.
736-
func (c *Client) RateLimit() (*Rate, *Response, error) {
737-
limits, resp, err := c.RateLimits()
738-
if err != nil {
739-
return nil, resp, err
740-
}
741-
if limits == nil {
742-
return nil, resp, errors.New("RateLimits returned nil limits and error; unable to extract Core rate limit")
743-
}
744-
return limits.Core, resp, nil
745-
}
746-
747715
// RateLimits returns the rate limits for the current client.
748716
func (c *Client) RateLimits() (*RateLimits, *Response, error) {
749717
req, err := c.NewRequest("GET", "rate_limit", nil)

github/github_test.go

+10-50
Original file line numberDiff line numberDiff line change
@@ -407,30 +407,20 @@ func TestDo_rateLimit(t *testing.T) {
407407
w.Header().Add(headerRateReset, "1372700873")
408408
})
409409

410-
if got, want := client.Rate().Limit, 0; got != want {
411-
t.Errorf("Client rate limit = %v, want %v", got, want)
412-
}
413-
if got, want := client.Rate().Remaining, 0; got != want {
414-
t.Errorf("Client rate remaining = %v, got %v", got, want)
415-
}
416-
if !client.Rate().Reset.IsZero() {
417-
t.Errorf("Client rate reset not initialized to zero value")
418-
}
419-
420410
req, _ := client.NewRequest("GET", "/", nil)
421-
_, err := client.Do(req, nil)
411+
resp, err := client.Do(req, nil)
422412
if err != nil {
423413
t.Errorf("Do returned unexpected error: %v", err)
424414
}
425-
if got, want := client.Rate().Limit, 60; got != want {
415+
if got, want := resp.Rate.Limit, 60; got != want {
426416
t.Errorf("Client rate limit = %v, want %v", got, want)
427417
}
428-
if got, want := client.Rate().Remaining, 59; got != want {
418+
if got, want := resp.Rate.Remaining, 59; got != want {
429419
t.Errorf("Client rate remaining = %v, want %v", got, want)
430420
}
431421
reset := time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC)
432-
if client.Rate().Reset.UTC() != reset {
433-
t.Errorf("Client rate reset = %v, want %v", client.Rate().Reset, reset)
422+
if resp.Rate.Reset.UTC() != reset {
423+
t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset, reset)
434424
}
435425
}
436426

@@ -447,23 +437,22 @@ func TestDo_rateLimit_errorResponse(t *testing.T) {
447437
})
448438

449439
req, _ := client.NewRequest("GET", "/", nil)
450-
_, err := client.Do(req, nil)
451-
440+
resp, err := client.Do(req, nil)
452441
if err == nil {
453442
t.Error("Expected error to be returned.")
454443
}
455444
if _, ok := err.(*RateLimitError); ok {
456445
t.Errorf("Did not expect a *RateLimitError error; got %#v.", err)
457446
}
458-
if got, want := client.Rate().Limit, 60; got != want {
447+
if got, want := resp.Rate.Limit, 60; got != want {
459448
t.Errorf("Client rate limit = %v, want %v", got, want)
460449
}
461-
if got, want := client.Rate().Remaining, 59; got != want {
450+
if got, want := resp.Rate.Remaining, 59; got != want {
462451
t.Errorf("Client rate remaining = %v, want %v", got, want)
463452
}
464453
reset := time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC)
465-
if client.Rate().Reset.UTC() != reset {
466-
t.Errorf("Client rate reset = %v, want %v", client.Rate().Reset, reset)
454+
if resp.Rate.Reset.UTC() != reset {
455+
t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset, reset)
467456
}
468457
}
469458

@@ -764,35 +753,6 @@ func TestError_Error(t *testing.T) {
764753
}
765754
}
766755

767-
func TestRateLimit(t *testing.T) {
768-
setup()
769-
defer teardown()
770-
771-
mux.HandleFunc("/rate_limit", func(w http.ResponseWriter, r *http.Request) {
772-
if m := "GET"; m != r.Method {
773-
t.Errorf("Request method = %v, want %v", r.Method, m)
774-
}
775-
fmt.Fprint(w, `{"resources":{
776-
"core": {"limit":2,"remaining":1,"reset":1372700873},
777-
"search": {"limit":3,"remaining":2,"reset":1372700874}
778-
}}`)
779-
})
780-
781-
rate, _, err := client.RateLimit()
782-
if err != nil {
783-
t.Errorf("Rate limit returned error: %v", err)
784-
}
785-
786-
want := &Rate{
787-
Limit: 2,
788-
Remaining: 1,
789-
Reset: Timestamp{time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC).Local()},
790-
}
791-
if !reflect.DeepEqual(rate, want) {
792-
t.Errorf("RateLimit returned %+v, want %+v", rate, want)
793-
}
794-
}
795-
796756
func TestRateLimits(t *testing.T) {
797757
setup()
798758
defer teardown()

github/misc_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func TestZen(t *testing.T) {
137137
}
138138
}
139139

140-
func TestRepositoriesService_ListServiceHooks(t *testing.T) {
140+
func TestListServiceHooks(t *testing.T) {
141141
setup()
142142
defer teardown()
143143

@@ -153,9 +153,9 @@ func TestRepositoriesService_ListServiceHooks(t *testing.T) {
153153
}]`)
154154
})
155155

156-
hooks, _, err := client.Repositories.ListServiceHooks()
156+
hooks, _, err := client.ListServiceHooks()
157157
if err != nil {
158-
t.Errorf("Repositories.ListHooks returned error: %v", err)
158+
t.Errorf("ListServiceHooks returned error: %v", err)
159159
}
160160

161161
want := []*ServiceHook{{
@@ -165,6 +165,6 @@ func TestRepositoriesService_ListServiceHooks(t *testing.T) {
165165
Schema: [][]string{{"a", "b"}},
166166
}}
167167
if !reflect.DeepEqual(hooks, want) {
168-
t.Errorf("Repositories.ListServiceHooks returned %+v, want %+v", hooks, want)
168+
t.Errorf("ListServiceHooks returned %+v, want %+v", hooks, want)
169169
}
170170
}

github/orgs_teams_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func TestOrganizationsService_AddTeamRepo_noAccess(t *testing.T) {
381381

382382
mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) {
383383
testMethod(t, r, "PUT")
384-
w.WriteHeader(StatusUnprocessableEntity)
384+
w.WriteHeader(http.StatusUnprocessableEntity)
385385
})
386386

387387
_, err := client.Organizations.AddTeamRepo(1, "o", "r", nil)

github/repos_contents.go

-15
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package github
1111
import (
1212
"encoding/base64"
1313
"encoding/json"
14-
"errors"
1514
"fmt"
1615
"io"
1716
"net/http"
@@ -64,20 +63,6 @@ func (r RepositoryContent) String() string {
6463
return Stringify(r)
6564
}
6665

67-
// Decode decodes the file content if it is base64 encoded.
68-
//
69-
// Deprecated: Use GetContent instead.
70-
func (r *RepositoryContent) Decode() ([]byte, error) {
71-
if *r.Encoding != "base64" {
72-
return nil, errors.New("cannot decode non-base64")
73-
}
74-
o, err := base64.StdEncoding.DecodeString(*r.Content)
75-
if err != nil {
76-
return nil, err
77-
}
78-
return o, nil
79-
}
80-
8166
// GetContent returns the content of r, decoding it if necessary.
8267
func (r *RepositoryContent) GetContent() (string, error) {
8368
var encoding string

github/repos_contents_test.go

-35
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,6 @@ import (
1313
"testing"
1414
)
1515

16-
func TestRepositoryContent_Decode(t *testing.T) {
17-
tests := []struct {
18-
encoding, content *string // input encoding and content
19-
want string // desired output
20-
wantErr bool // whether an error is expected
21-
}{
22-
{
23-
encoding: String("base64"),
24-
content: String("aGVsbG8="),
25-
want: "hello",
26-
wantErr: false,
27-
},
28-
{
29-
encoding: String("bad"),
30-
content: String("aGVsbG8="),
31-
want: "",
32-
wantErr: true,
33-
},
34-
}
35-
36-
for _, tt := range tests {
37-
r := RepositoryContent{Encoding: tt.encoding, Content: tt.content}
38-
o, err := r.Decode()
39-
if err != nil && !tt.wantErr {
40-
t.Errorf("RepositoryContent(%q, %q) returned unexpected error: %v", tt.encoding, tt.content, err)
41-
}
42-
if err == nil && tt.wantErr {
43-
t.Errorf("RepositoryContent(%q, %q) did not return unexpected error", tt.encoding, tt.content)
44-
}
45-
if got, want := string(o), tt.want; got != want {
46-
t.Errorf("RepositoryContent.Decode returned %+v, want %+v", got, want)
47-
}
48-
}
49-
}
50-
5116
func TestRepositoryContent_GetContent(t *testing.T) {
5217
tests := []struct {
5318
encoding, content *string // input encoding and content

github/repos_deployments.go

-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ type DeploymentStatus struct {
144144
// DeploymentStatusRequest represents a deployment request
145145
type DeploymentStatusRequest struct {
146146
State *string `json:"state,omitempty"`
147-
TargetURL *string `json:"target_url,omitempty"` // Deprecated. Use LogURL instead.
148147
LogURL *string `json:"log_url,omitempty"`
149148
Description *string `json:"description,omitempty"`
150149
EnvironmentURL *string `json:"environment_url,omitempty"`

github/repos_hooks.go

-5
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,3 @@ func (s *RepositoriesService) TestHook(owner, repo string, id int) (*Response, e
189189
}
190190
return s.client.Do(req, nil)
191191
}
192-
193-
// ListServiceHooks is deprecated. Use Client.ListServiceHooks instead.
194-
func (s *RepositoriesService) ListServiceHooks() ([]*ServiceHook, *Response, error) {
195-
return s.client.ListServiceHooks()
196-
}

0 commit comments

Comments
 (0)