From cde89cf631e0687e1d28f392d9aeb8fd09e519e2 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Ruel Date: Sun, 10 Dec 2017 10:35:36 -0500 Subject: [PATCH 1/2] Upgrade RepoStatus.ID from int to int64 This is needed on 32 bits platforms. Right now it is impossible to call CreateStatus() on 32 bits executable because the ID returned by Github overflows. This is an API breaking change. Fixes #806 --- github/github-accessors.go | 2 +- github/github.go | 4 ++++ github/repos_statuses.go | 2 +- github/repos_statuses_test.go | 6 +++--- github/strings_test.go | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index cc696325dd9..e846783f4f4 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -8565,7 +8565,7 @@ func (r *RepoStatus) GetDescription() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (r *RepoStatus) GetID() int { +func (r *RepoStatus) GetID() int64 { if r == nil || r.ID == nil { return 0 } diff --git a/github/github.go b/github/github.go index 8c707be3473..3373c17f8bb 100644 --- a/github/github.go +++ b/github/github.go @@ -963,6 +963,10 @@ func Bool(v bool) *bool { return &v } // to store v and returns a pointer to it. func Int(v int) *int { return &v } +// Int64 is a helper routine that allocates a new int64 value +// to store v and returns a pointer to it. +func Int64(v int64) *int64 { return &v } + // String is a helper routine that allocates a new string value // to store v and returns a pointer to it. func String(v string) *string { return &v } diff --git a/github/repos_statuses.go b/github/repos_statuses.go index 6db501076ca..f94fdc858b8 100644 --- a/github/repos_statuses.go +++ b/github/repos_statuses.go @@ -13,7 +13,7 @@ import ( // RepoStatus represents the status of a repository at a particular reference. type RepoStatus struct { - ID *int `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` URL *string `json:"url,omitempty"` // State is the current state of the repository. Possible values are: diff --git a/github/repos_statuses_test.go b/github/repos_statuses_test.go index 21cc238cf4d..b556b716695 100644 --- a/github/repos_statuses_test.go +++ b/github/repos_statuses_test.go @@ -30,7 +30,7 @@ func TestRepositoriesService_ListStatuses(t *testing.T) { t.Errorf("Repositories.ListStatuses returned error: %v", err) } - want := []*RepoStatus{{ID: Int(1)}} + want := []*RepoStatus{{ID: Int64(1)}} if !reflect.DeepEqual(statuses, want) { t.Errorf("Repositories.ListStatuses returned %+v, want %+v", statuses, want) } @@ -66,7 +66,7 @@ func TestRepositoriesService_CreateStatus(t *testing.T) { t.Errorf("Repositories.CreateStatus returned error: %v", err) } - want := &RepoStatus{ID: Int(1)} + want := &RepoStatus{ID: Int64(1)} if !reflect.DeepEqual(status, want) { t.Errorf("Repositories.CreateStatus returned %+v, want %+v", status, want) } @@ -96,7 +96,7 @@ func TestRepositoriesService_GetCombinedStatus(t *testing.T) { t.Errorf("Repositories.GetCombinedStatus returned error: %v", err) } - want := &CombinedStatus{State: String("success"), Statuses: []RepoStatus{{ID: Int(1)}}} + want := &CombinedStatus{State: String("success"), Statuses: []RepoStatus{{ID: Int64(1)}}} if !reflect.DeepEqual(status, want) { t.Errorf("Repositories.GetCombinedStatus returned %+v, want %+v", status, want) } diff --git a/github/strings_test.go b/github/strings_test.go index 6af88acd390..10cbe7b499d 100644 --- a/github/strings_test.go +++ b/github/strings_test.go @@ -117,7 +117,7 @@ func TestString(t *testing.T) { {PushEvent{PushID: Int(1)}, `github.PushEvent{PushID:1}`}, {Reference{Ref: String("r")}, `github.Reference{Ref:"r"}`}, {ReleaseAsset{ID: Int(1)}, `github.ReleaseAsset{ID:1}`}, - {RepoStatus{ID: Int(1)}, `github.RepoStatus{ID:1}`}, + {RepoStatus{ID: Int64(1)}, `github.RepoStatus{ID:1}`}, {RepositoryComment{ID: Int(1)}, `github.RepositoryComment{ID:1}`}, {RepositoryCommit{SHA: String("s")}, `github.RepositoryCommit{SHA:"s"}`}, {RepositoryContent{Name: String("n")}, `github.RepositoryContent{Name:"n"}`}, From 84280894f9f6e7c343ce9ccaa46e4451b5d877c2 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Ruel Date: Sun, 10 Dec 2017 10:39:51 -0500 Subject: [PATCH 2/2] Ran go generate -x ./... It seems the generated file was stale prior to my change. I'm not sure why GetID() exists, it's not useful. --- github/github-accessors.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index e846783f4f4..53b84d52199 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -8564,12 +8564,12 @@ func (r *RepoStatus) GetDescription() string { return *r.Description } -// GetID returns the ID field if it's non-nil, zero value otherwise. -func (r *RepoStatus) GetID() int64 { - if r == nil || r.ID == nil { - return 0 +// GetID returns the ID field. +func (r *RepoStatus) GetID() *int64 { + if r == nil { + return nil } - return *r.ID + return r.ID } // GetState returns the State field if it's non-nil, zero value otherwise.