From f34b33dcba2b30ea087164662f70af6b336fc498 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Fri, 17 Feb 2017 21:18:35 -0500 Subject: [PATCH] Remove deprecated identifiers. 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, 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 #526. --- github/activity_events.go | 2 -- github/event_types.go | 13 -------- github/github.go | 32 ------------------- github/github_test.go | 60 ++++++----------------------------- github/misc_test.go | 8 ++--- github/orgs_teams_test.go | 2 +- github/repos_contents.go | 15 --------- github/repos_contents_test.go | 35 -------------------- github/repos_deployments.go | 1 - github/repos_hooks.go | 5 --- 10 files changed, 15 insertions(+), 158 deletions(-) diff --git a/github/activity_events.go b/github/activity_events.go index f9c8f53dca7..f749f6df847 100644 --- a/github/activity_events.go +++ b/github/activity_events.go @@ -49,8 +49,6 @@ func (e *Event) Payload() (payload interface{}) { payload = &IntegrationInstallationEvent{} case "IntegrationInstallationRepositoriesEvent": payload = &IntegrationInstallationRepositoriesEvent{} - case "IssueActivityEvent": - payload = &IssueActivityEvent{} case "IssueCommentEvent": payload = &IssueCommentEvent{} case "IssuesEvent": diff --git a/github/event_types.go b/github/event_types.go index f06bd68ab4d..b98492ebca4 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -130,19 +130,6 @@ type GollumEvent struct { Installation *Installation `json:"installation,omitempty"` } -// IssueActivityEvent represents the payload delivered by Issue webhook. -// -// Deprecated: Use IssuesEvent instead. -type IssueActivityEvent struct { - Action *string `json:"action,omitempty"` - Issue *Issue `json:"issue,omitempty"` - - // The following fields are only populated by Webhook events. - Repo *Repository `json:"repository,omitempty"` - Sender *User `json:"sender,omitempty"` - Installation *Installation `json:"installation,omitempty"` -} - // EditChange represents the changes when an issue, pull request, or comment has // been edited. type EditChange struct { diff --git a/github/github.go b/github/github.go index e9bb5185ed0..379ec06d9e6 100644 --- a/github/github.go +++ b/github/github.go @@ -23,11 +23,6 @@ import ( "github.com/google/go-querystring/query" ) -const ( - // StatusUnprocessableEntity is the status code returned when sending a request with invalid fields. - StatusUnprocessableEntity = 422 -) - const ( libraryVersion = "3" defaultBaseURL = "https://api.github.com/" @@ -383,19 +378,6 @@ func parseRate(r *http.Response) Rate { return rate } -// Rate specifies the current rate limit for the client as determined by the -// most recent API call. If the client is used in a multi-user application, -// this rate may not always be up-to-date. -// -// Deprecated: Use the Response.Rate returned from most recent API call instead. -// Call RateLimits() to check the current rate. -func (c *Client) Rate() Rate { - c.rateMu.Lock() - rate := c.rateLimits[c.mostRecent] - c.rateMu.Unlock() - return rate -} - // Do sends an API request and returns the API response. The API response is // JSON decoded and stored in the value pointed to by v, or returned as an // error if an API error has occurred. If v implements the io.Writer @@ -730,20 +712,6 @@ func category(path string) rateLimitCategory { } } -// RateLimit returns the core rate limit for the current client. -// -// Deprecated: RateLimit is deprecated, use RateLimits instead. -func (c *Client) RateLimit() (*Rate, *Response, error) { - limits, resp, err := c.RateLimits() - if err != nil { - return nil, resp, err - } - if limits == nil { - return nil, resp, errors.New("RateLimits returned nil limits and error; unable to extract Core rate limit") - } - return limits.Core, resp, nil -} - // RateLimits returns the rate limits for the current client. func (c *Client) RateLimits() (*RateLimits, *Response, error) { req, err := c.NewRequest("GET", "rate_limit", nil) diff --git a/github/github_test.go b/github/github_test.go index d65ffff480f..89a14dc6da3 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -407,30 +407,20 @@ func TestDo_rateLimit(t *testing.T) { w.Header().Add(headerRateReset, "1372700873") }) - if got, want := client.Rate().Limit, 0; got != want { - t.Errorf("Client rate limit = %v, want %v", got, want) - } - if got, want := client.Rate().Remaining, 0; got != want { - t.Errorf("Client rate remaining = %v, got %v", got, want) - } - if !client.Rate().Reset.IsZero() { - t.Errorf("Client rate reset not initialized to zero value") - } - req, _ := client.NewRequest("GET", "/", nil) - _, err := client.Do(req, nil) + resp, err := client.Do(req, nil) if err != nil { t.Errorf("Do returned unexpected error: %v", err) } - if got, want := client.Rate().Limit, 60; got != want { + if got, want := resp.Rate.Limit, 60; got != want { t.Errorf("Client rate limit = %v, want %v", got, want) } - if got, want := client.Rate().Remaining, 59; got != want { + if got, want := resp.Rate.Remaining, 59; got != want { t.Errorf("Client rate remaining = %v, want %v", got, want) } reset := time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC) - if client.Rate().Reset.UTC() != reset { - t.Errorf("Client rate reset = %v, want %v", client.Rate().Reset, reset) + if resp.Rate.Reset.UTC() != reset { + t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset, reset) } } @@ -447,23 +437,22 @@ func TestDo_rateLimit_errorResponse(t *testing.T) { }) req, _ := client.NewRequest("GET", "/", nil) - _, err := client.Do(req, nil) - + resp, err := client.Do(req, nil) if err == nil { t.Error("Expected error to be returned.") } if _, ok := err.(*RateLimitError); ok { t.Errorf("Did not expect a *RateLimitError error; got %#v.", err) } - if got, want := client.Rate().Limit, 60; got != want { + if got, want := resp.Rate.Limit, 60; got != want { t.Errorf("Client rate limit = %v, want %v", got, want) } - if got, want := client.Rate().Remaining, 59; got != want { + if got, want := resp.Rate.Remaining, 59; got != want { t.Errorf("Client rate remaining = %v, want %v", got, want) } reset := time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC) - if client.Rate().Reset.UTC() != reset { - t.Errorf("Client rate reset = %v, want %v", client.Rate().Reset, reset) + if resp.Rate.Reset.UTC() != reset { + t.Errorf("Client rate reset = %v, want %v", resp.Rate.Reset, reset) } } @@ -764,35 +753,6 @@ func TestError_Error(t *testing.T) { } } -func TestRateLimit(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/rate_limit", func(w http.ResponseWriter, r *http.Request) { - if m := "GET"; m != r.Method { - t.Errorf("Request method = %v, want %v", r.Method, m) - } - fmt.Fprint(w, `{"resources":{ - "core": {"limit":2,"remaining":1,"reset":1372700873}, - "search": {"limit":3,"remaining":2,"reset":1372700874} - }}`) - }) - - rate, _, err := client.RateLimit() - if err != nil { - t.Errorf("Rate limit returned error: %v", err) - } - - want := &Rate{ - Limit: 2, - Remaining: 1, - Reset: Timestamp{time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC).Local()}, - } - if !reflect.DeepEqual(rate, want) { - t.Errorf("RateLimit returned %+v, want %+v", rate, want) - } -} - func TestRateLimits(t *testing.T) { setup() defer teardown() diff --git a/github/misc_test.go b/github/misc_test.go index afced702d65..71eb2f7054e 100644 --- a/github/misc_test.go +++ b/github/misc_test.go @@ -137,7 +137,7 @@ func TestZen(t *testing.T) { } } -func TestRepositoriesService_ListServiceHooks(t *testing.T) { +func TestListServiceHooks(t *testing.T) { setup() defer teardown() @@ -153,9 +153,9 @@ func TestRepositoriesService_ListServiceHooks(t *testing.T) { }]`) }) - hooks, _, err := client.Repositories.ListServiceHooks() + hooks, _, err := client.ListServiceHooks() if err != nil { - t.Errorf("Repositories.ListHooks returned error: %v", err) + t.Errorf("ListServiceHooks returned error: %v", err) } want := []*ServiceHook{{ @@ -165,6 +165,6 @@ func TestRepositoriesService_ListServiceHooks(t *testing.T) { Schema: [][]string{{"a", "b"}}, }} if !reflect.DeepEqual(hooks, want) { - t.Errorf("Repositories.ListServiceHooks returned %+v, want %+v", hooks, want) + t.Errorf("ListServiceHooks returned %+v, want %+v", hooks, want) } } diff --git a/github/orgs_teams_test.go b/github/orgs_teams_test.go index 36701f1a456..3e8cd30980f 100644 --- a/github/orgs_teams_test.go +++ b/github/orgs_teams_test.go @@ -381,7 +381,7 @@ func TestOrganizationsService_AddTeamRepo_noAccess(t *testing.T) { mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") - w.WriteHeader(StatusUnprocessableEntity) + w.WriteHeader(http.StatusUnprocessableEntity) }) _, err := client.Organizations.AddTeamRepo(1, "o", "r", nil) diff --git a/github/repos_contents.go b/github/repos_contents.go index d60ede56023..32b1573da1b 100644 --- a/github/repos_contents.go +++ b/github/repos_contents.go @@ -11,7 +11,6 @@ package github import ( "encoding/base64" "encoding/json" - "errors" "fmt" "io" "net/http" @@ -64,20 +63,6 @@ func (r RepositoryContent) String() string { return Stringify(r) } -// Decode decodes the file content if it is base64 encoded. -// -// Deprecated: Use GetContent instead. -func (r *RepositoryContent) Decode() ([]byte, error) { - if *r.Encoding != "base64" { - return nil, errors.New("cannot decode non-base64") - } - o, err := base64.StdEncoding.DecodeString(*r.Content) - if err != nil { - return nil, err - } - return o, nil -} - // GetContent returns the content of r, decoding it if necessary. func (r *RepositoryContent) GetContent() (string, error) { var encoding string diff --git a/github/repos_contents_test.go b/github/repos_contents_test.go index 6d025ab9e17..b86d7e16bef 100644 --- a/github/repos_contents_test.go +++ b/github/repos_contents_test.go @@ -13,41 +13,6 @@ import ( "testing" ) -func TestRepositoryContent_Decode(t *testing.T) { - tests := []struct { - encoding, content *string // input encoding and content - want string // desired output - wantErr bool // whether an error is expected - }{ - { - encoding: String("base64"), - content: String("aGVsbG8="), - want: "hello", - wantErr: false, - }, - { - encoding: String("bad"), - content: String("aGVsbG8="), - want: "", - wantErr: true, - }, - } - - for _, tt := range tests { - r := RepositoryContent{Encoding: tt.encoding, Content: tt.content} - o, err := r.Decode() - if err != nil && !tt.wantErr { - t.Errorf("RepositoryContent(%q, %q) returned unexpected error: %v", tt.encoding, tt.content, err) - } - if err == nil && tt.wantErr { - t.Errorf("RepositoryContent(%q, %q) did not return unexpected error", tt.encoding, tt.content) - } - if got, want := string(o), tt.want; got != want { - t.Errorf("RepositoryContent.Decode returned %+v, want %+v", got, want) - } - } -} - func TestRepositoryContent_GetContent(t *testing.T) { tests := []struct { encoding, content *string // input encoding and content diff --git a/github/repos_deployments.go b/github/repos_deployments.go index 72dc05cb625..ad931afc208 100644 --- a/github/repos_deployments.go +++ b/github/repos_deployments.go @@ -144,7 +144,6 @@ type DeploymentStatus struct { // DeploymentStatusRequest represents a deployment request type DeploymentStatusRequest struct { State *string `json:"state,omitempty"` - TargetURL *string `json:"target_url,omitempty"` // Deprecated. Use LogURL instead. LogURL *string `json:"log_url,omitempty"` Description *string `json:"description,omitempty"` EnvironmentURL *string `json:"environment_url,omitempty"` diff --git a/github/repos_hooks.go b/github/repos_hooks.go index 6f316ecdc4f..818286b7998 100644 --- a/github/repos_hooks.go +++ b/github/repos_hooks.go @@ -189,8 +189,3 @@ func (s *RepositoriesService) TestHook(owner, repo string, id int) (*Response, e } return s.client.Do(req, nil) } - -// ListServiceHooks is deprecated. Use Client.ListServiceHooks instead. -func (s *RepositoriesService) ListServiceHooks() ([]*ServiceHook, *Response, error) { - return s.client.ListServiceHooks() -}