diff --git a/github/git_commits.go b/github/git_commits.go index 22cb49afaf8..3c49a8a2992 100644 --- a/github/git_commits.go +++ b/github/git_commits.go @@ -28,6 +28,7 @@ type Commit struct { 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"` diff --git a/github/github-accessors.go b/github/github-accessors.go index bf39feeb0b5..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 { @@ -500,84 +508,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..7668b8b6256 100644 --- a/github/search.go +++ b/github/search.go @@ -65,17 +65,17 @@ 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)