From 511dcd19331d08e8dd8cff3dadc1791525714ab3 Mon Sep 17 00:00:00 2001 From: Aleksandar Mirilovic Date: Tue, 28 Mar 2017 15:04:07 +0200 Subject: [PATCH 1/7] Fixing issue with commit search results deserialization #601 --- github/github-accessors.go | 80 ++++++++------------------------------ github/search.go | 21 +++++----- github/search_test.go | 4 +- 3 files changed, 28 insertions(+), 77 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index bf39feeb0b5..67280696e01 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -500,84 +500,36 @@ func (c *CommitFile) GetStatus() string { return *c.Status } -// GetAuthorDate returns the AuthorDate field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetAuthorDate() Timestamp { - if c == nil || c.AuthorDate == nil { - return Timestamp{} - } - return *c.AuthorDate -} - -// GetAuthorEmail returns the AuthorEmail field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetAuthorEmail() string { - if c == nil || c.AuthorEmail == nil { - return "" - } - return *c.AuthorEmail -} - -// GetAuthorID returns the AuthorID field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetAuthorID() int { - if c == nil || c.AuthorID == nil { - return 0 - } - return *c.AuthorID -} - -// GetAuthorName returns the AuthorName field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetAuthorName() string { - if c == nil || c.AuthorName == nil { - return "" - } - return *c.AuthorName -} - -// GetCommitterDate returns the CommitterDate field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetCommitterDate() Timestamp { - if c == nil || c.CommitterDate == nil { - return Timestamp{} - } - return *c.CommitterDate -} - -// GetCommitterEmail returns the CommitterEmail field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetCommitterEmail() string { - if c == nil || c.CommitterEmail == nil { +// GetCommentsURL returns the CommentsURL field if it's non-nil, zero value otherwise. +func (c *CommitResult) GetCommentsURL() string { + if c == nil || c.CommentsURL == nil { return "" } - return *c.CommitterEmail + return *c.CommentsURL } -// GetCommitterID returns the CommitterID field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetCommitterID() int { - if c == nil || c.CommitterID == nil { - return 0 - } - return *c.CommitterID -} - -// GetCommitterName returns the CommitterName field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetCommitterName() string { - if c == nil || c.CommitterName == nil { +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (c *CommitResult) GetHTMLURL() string { + if c == nil || c.HTMLURL == nil { return "" } - return *c.CommitterName + return *c.HTMLURL } -// GetHash returns the Hash field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetHash() string { - if c == nil || c.Hash == nil { +// GetSHA returns the SHA field if it's non-nil, zero value otherwise. +func (c *CommitResult) GetSHA() string { + if c == nil || c.SHA == nil { return "" } - return *c.Hash + return *c.SHA } -// GetMessage returns the Message field if it's non-nil, zero value otherwise. -func (c *CommitResult) GetMessage() string { - if c == nil || c.Message == nil { +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (c *CommitResult) GetURL() string { + if c == nil || c.URL == nil { return "" } - return *c.Message + return *c.URL } // GetAheadBy returns the AheadBy field if it's non-nil, zero value otherwise. diff --git a/github/search.go b/github/search.go index 0fdaad91921..d7271efcaba 100644 --- a/github/search.go +++ b/github/search.go @@ -65,17 +65,16 @@ type CommitsSearchResult struct { // CommitResult represents a commit object as returned in commit search endpoint response. type CommitResult struct { - Hash *string `json:"hash,omitempty"` - Message *string `json:"message,omitempty"` - AuthorID *int `json:"author_id,omitempty"` - AuthorName *string `json:"author_name,omitempty"` - AuthorEmail *string `json:"author_email,omitempty"` - AuthorDate *Timestamp `json:"author_date,omitempty"` - CommitterID *int `json:"committer_id,omitempty"` - CommitterName *string `json:"committer_name,omitempty"` - CommitterEmail *string `json:"committer_email,omitempty"` - CommitterDate *Timestamp `json:"committer_date,omitempty"` - Repository *Repository `json:"repository,omitempty"` + SHA *string `json:"sha,omitempty"` + Commit *Commit `json:"commit,omitempty"` + Author *User `json:"author,omitempty"` + Committer *User `json:"committer,omitempty"` + Parents []Commit `json:"parents,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + URL *string `json:"url,omitempty"` + CommentsURL *string `json:"comments_url,omitempty"` + Repository *Repository `json:"repository,omitempty"` + Score *float64 `json:"score,omitempty"` } // Commits searches commits via various criteria. diff --git a/github/search_test.go b/github/search_test.go index 3126bc8de35..ee2f69be2a3 100644 --- a/github/search_test.go +++ b/github/search_test.go @@ -59,7 +59,7 @@ func TestSearchService_Commits(t *testing.T) { "order": "desc", }) - fmt.Fprint(w, `{"total_count": 4, "incomplete_results": false, "items": [{"hash":"random_hash1"},{"hash":"random_hash2"}]}`) + fmt.Fprint(w, `{"total_count": 4, "incomplete_results": false, "items": [{"sha":"random_hash1"},{"sha":"random_hash2"}]}`) }) opts := &SearchOptions{Sort: "author-date", Order: "desc"} @@ -71,7 +71,7 @@ func TestSearchService_Commits(t *testing.T) { want := &CommitsSearchResult{ Total: Int(4), IncompleteResults: Bool(false), - Commits: []*CommitResult{{Hash: String("random_hash1")}, {Hash: String("random_hash2")}}, + Commits: []*CommitResult{{SHA: String("random_hash1")}, {SHA: String("random_hash2")}}, } if !reflect.DeepEqual(result, want) { t.Errorf("Search.Commits returned %+v, want %+v", result, want) From 420bfddf1c54348a597893b93a77023aae616258 Mon Sep 17 00:00:00 2001 From: Aleksandar Mirilovic Date: Wed, 29 Mar 2017 10:35:46 +0200 Subject: [PATCH 2/7] Fixes #602 --- github/search.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/search.go b/github/search.go index d7271efcaba..6bdbbc36b3f 100644 --- a/github/search.go +++ b/github/search.go @@ -69,7 +69,7 @@ type CommitResult struct { Commit *Commit `json:"commit,omitempty"` Author *User `json:"author,omitempty"` Committer *User `json:"committer,omitempty"` - Parents []Commit `json:"parents,omitempty"` + Parents []*Commit `json:"parents,omitempty"` HTMLURL *string `json:"html_url,omitempty"` URL *string `json:"url,omitempty"` CommentsURL *string `json:"comments_url,omitempty"` From 97ffef0c75fac8b58ccc90d3ad7df03dd44796c0 Mon Sep 17 00:00:00 2001 From: Aleksandar Mirilovic Date: Wed, 29 Mar 2017 21:49:51 +0200 Subject: [PATCH 3/7] Fixing naming issue with mapping total_count from result #602 --- github/search.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/search.go b/github/search.go index 6bdbbc36b3f..be376252dc7 100644 --- a/github/search.go +++ b/github/search.go @@ -58,7 +58,7 @@ func (s *SearchService) Repositories(ctx context.Context, query string, opt *Sea // CommitsSearchResult represents the result of a commits search. type CommitsSearchResult struct { - Total *int `json:"total_count,omitempty"` + TotalCount *int `json:"total_count,omitempty"` IncompleteResults *bool `json:"incomplete_results,omitempty"` Commits []*CommitResult `json:"items,omitempty"` } From b0fc7d2ef072b25344a49e5c29fc98ff9626e463 Mon Sep 17 00:00:00 2001 From: Aleksandar Mirilovic Date: Thu, 30 Mar 2017 05:59:18 +0200 Subject: [PATCH 4/7] Reverse TotalCount commit #602 --- github/search.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/search.go b/github/search.go index be376252dc7..6bdbbc36b3f 100644 --- a/github/search.go +++ b/github/search.go @@ -58,7 +58,7 @@ func (s *SearchService) Repositories(ctx context.Context, query string, opt *Sea // CommitsSearchResult represents the result of a commits search. type CommitsSearchResult struct { - TotalCount *int `json:"total_count,omitempty"` + Total *int `json:"total_count,omitempty"` IncompleteResults *bool `json:"incomplete_results,omitempty"` Commits []*CommitResult `json:"items,omitempty"` } From 5ab7b75544fdae3462c38b3bb4015bd9244ed65d Mon Sep 17 00:00:00 2001 From: Aleksandar Mirilovic Date: Thu, 30 Mar 2017 06:39:01 +0200 Subject: [PATCH 5/7] Add HTMLURL to Commit (#602) --- github/git_commits.go | 1 + github/github-accessors.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/github/git_commits.go b/github/git_commits.go index 22cb49afaf8..d8421cdb00d 100644 --- a/github/git_commits.go +++ b/github/git_commits.go @@ -22,6 +22,7 @@ type SignatureVerification struct { // Commit represents a GitHub commit. type Commit struct { SHA *string `json:"sha,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` Author *CommitAuthor `json:"author,omitempty"` Committer *CommitAuthor `json:"committer,omitempty"` Message *string `json:"message,omitempty"` diff --git a/github/github-accessors.go b/github/github-accessors.go index 67280696e01..d0bc2bf5527 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -356,6 +356,14 @@ func (c *Commit) GetCommentCount() int { return *c.CommentCount } +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (c *Commit) GetHTMLURL() string { + if c == nil || c.HTMLURL == nil { + return "" + } + return *c.HTMLURL +} + // GetMessage returns the Message field if it's non-nil, zero value otherwise. func (c *Commit) GetMessage() string { if c == nil || c.Message == nil { From 966917d2e8fb79c648d2f6613b7f1d749bfe7978 Mon Sep 17 00:00:00 2001 From: Aleksandar Mirilovic Date: Thu, 30 Mar 2017 06:46:58 +0200 Subject: [PATCH 6/7] Move HTMLURL near URL field (#602) --- github/git_commits.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/git_commits.go b/github/git_commits.go index d8421cdb00d..3c49a8a2992 100644 --- a/github/git_commits.go +++ b/github/git_commits.go @@ -22,13 +22,13 @@ type SignatureVerification struct { // Commit represents a GitHub commit. type Commit struct { SHA *string `json:"sha,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` Author *CommitAuthor `json:"author,omitempty"` Committer *CommitAuthor `json:"committer,omitempty"` Message *string `json:"message,omitempty"` Tree *Tree `json:"tree,omitempty"` Parents []Commit `json:"parents,omitempty"` Stats *CommitStats `json:"stats,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` URL *string `json:"url,omitempty"` Verification *SignatureVerification `json:"verification,omitempty"` From 3f67f5c82a6ab857ba591ca5ae665d031d161c04 Mon Sep 17 00:00:00 2001 From: Aleksandar Mirilovic Date: Fri, 31 Mar 2017 11:49:22 +0200 Subject: [PATCH 7/7] Add blank line between Commit common fields and search specific fields (#602) --- github/search.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/github/search.go b/github/search.go index 6bdbbc36b3f..7668b8b6256 100644 --- a/github/search.go +++ b/github/search.go @@ -65,16 +65,17 @@ type CommitsSearchResult struct { // CommitResult represents a commit object as returned in commit search endpoint response. type CommitResult struct { - SHA *string `json:"sha,omitempty"` - Commit *Commit `json:"commit,omitempty"` - Author *User `json:"author,omitempty"` - Committer *User `json:"committer,omitempty"` - Parents []*Commit `json:"parents,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - URL *string `json:"url,omitempty"` - CommentsURL *string `json:"comments_url,omitempty"` - Repository *Repository `json:"repository,omitempty"` - Score *float64 `json:"score,omitempty"` + SHA *string `json:"sha,omitempty"` + Commit *Commit `json:"commit,omitempty"` + Author *User `json:"author,omitempty"` + Committer *User `json:"committer,omitempty"` + Parents []*Commit `json:"parents,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + URL *string `json:"url,omitempty"` + CommentsURL *string `json:"comments_url,omitempty"` + + Repository *Repository `json:"repository,omitempty"` + Score *float64 `json:"score,omitempty"` } // Commits searches commits via various criteria.