Fixing issue with commit search results deserialization #601#602
Fixing issue with commit search results deserialization #601#602gmlewis merged 7 commits intogoogle:masterfrom foundcenter:master
Conversation
github/search.go
Outdated
| Commit *Commit `json:"commit,omitempty"` | ||
| Author *User `json:"author,omitempty"` | ||
| Committer *User `json:"committer,omitempty"` | ||
| Parents []Commit `json:"parents,omitempty"` |
There was a problem hiding this comment.
Based on #180 and #520 (comment) (/cc @gmlewis), I think we'd want to go with []*Commit here. Even though it's a little inconsistent with other similar structs.
At least that's what I think @gmlewis would request.
There was a problem hiding this comment.
Got it, will fix.
|
As part of this cleanup, can you please add Also, in Since these are breaking API changes, we also need to bump the version number. Thank you! |
|
@gmlewis All fine for TotalCount. For HTMLURL in Commit, I think it's fine right now. Also for RepositoryCommit as a result of https://developer.github.com/v3/repos/commits/#get-a-single-commit So, as I understand both result structures are wrappers around a commit with a specific HTMLURL, this is inline with github docs. Also parents in get single commit don't have html_url As far as I see in docs for other endpoints parents array is always just a reference to parent commits it never contains actual commit data, so maybe the best thing would be to create new struct to that represents that like: and change RepositoryResult and CommitResult to be: What do you think? |
@gmlewis, I don't think we should do this. At least not in this PR. It makes things inconsistent. Look at the rest of // RepositoriesSearchResult represents the result of a repositories search.
type RepositoriesSearchResult struct {
Total *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"`
Repositories []Repository `json:"items,omitempty"`
}
// IssuesSearchResult represents the result of an issues search.
type IssuesSearchResult struct {
Total *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"`
Issues []Issue `json:"items,omitempty"`
}
// UsersSearchResult represents the result of a users search.
type UsersSearchResult struct {
Total *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"`
Users []User `json:"items,omitempty"`
}
// CodeSearchResult represents the result of a code search.
type CodeSearchResult struct {
Total *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"`
CodeResults []CodeResult `json:"items,omitempty"`
}Do you see how it'd be inconsistent to change // CommitsSearchResult represents the result of a commits search.
type CommitsSearchResult struct {
TotalCount *int `json:"total_count,omitempty"`
IncompleteResults *bool `json:"incomplete_results,omitempty"`
Commits []*CommitResult `json:"items,omitempty"`
}We've already discussed this at #520 (comment) previously, and you agreed to prefer consistency there. @gmlewis Can you open an issue about this instead, so we can come to a decision and address all similar structs at once? But let's keep it out of scope of this PR. @amirilovic Please revert |
|
OK, SGTM. |
|
About @amirilovic, it's pretty subtle as to why. If you look at our https://godoc.org/github.com/google/go-github/github#GitService.GetCommit method, it returns {
"sha": "7638417db6d59f3c431d3e1f261cc637155684cd",
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd",
"author": {
"date": "2014-11-07T22:01:45Z",
"name": "Scott Chacon",
"email": "schacon@gmail.com"
},
"committer": {
"date": "2014-11-07T22:01:45Z",
"name": "Scott Chacon",
"email": "schacon@gmail.com"
},
"message": "added readme, because im a good github citizen",
"tree": {
"url": "https://api.github.com/repos/octocat/Hello-World/git/trees/691272480426f78a0138979dd3ce63b77f706feb",
"sha": "691272480426f78a0138979dd3ce63b77f706feb"
},
"parents": [
{
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5",
"sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5"
}
]
}However, GitHub API documentation is not always 100% up to date and does not always show all fields that the real API returns. This is an example of that. If you hit that endpoint for real, it includes "html_url" field. For example, try: {
"sha": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
"html_url": "https://github.com/octocat/Hello-World/commit/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
"author": {
"name": "The Octocat",
"email": "octocat@nowhere.com",
"date": "2012-03-06T23:06:50Z"
},
"committer": {
"name": "The Octocat",
"email": "octocat@nowhere.com",
"date": "2012-03-06T23:06:50Z"
},
"tree": {
"sha": "b4eecafa9be2f2006ce1b709d6857b07069b4608",
"url": "https://api.github.com/repos/octocat/Hello-World/git/trees/b4eecafa9be2f2006ce1b709d6857b07069b4608"
},
"message": "Merge pull request #6 from Spaceghost/patch-1\n\nNew line at end of file.",
"parents": [
{
"sha": "553c2077f0edc3d5dc5d17262f6aa498e69d6f8e",
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/553c2077f0edc3d5dc5d17262f6aa498e69d6f8e",
"html_url": "https://github.com/octocat/Hello-World/commit/553c2077f0edc3d5dc5d17262f6aa498e69d6f8e"
},
{
"sha": "762941318ee16e59dabbacb1b4049eec22f0d303",
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/762941318ee16e59dabbacb1b4049eec22f0d303",
"html_url": "https://github.com/octocat/Hello-World/commit/762941318ee16e59dabbacb1b4049eec22f0d303"
}
]
}Also note that parents have "html_url" field too. So, They've probably added it more recently, and didn't update their old documentation examples. |
|
@shurcooL Good point. |
github/git_commits.go
Outdated
| // Commit represents a GitHub commit. | ||
| type Commit struct { | ||
| SHA *string `json:"sha,omitempty"` | ||
| HTMLURL *string `json:"html_url,omitempty"` |
There was a problem hiding this comment.
Move it near URL, that should be a more fitting place for it.
See
go-github/github/repos_commits.go
Line 24 in 3c8f26c
|
@shurcooL Anything else that needs to be done here? |
github/search.go
Outdated
| URL *string `json:"url,omitempty"` | ||
| CommentsURL *string `json:"comments_url,omitempty"` | ||
| Repository *Repository `json:"repository,omitempty"` | ||
| Score *float64 `json:"score,omitempty"` |
There was a problem hiding this comment.
As an observation, CommitResult now looks very similar to RepositoryCommit. But it differs in the last 2 fields. RepositoryCommit has Stats and Files, which CommitResult does not, and CommitResult has Repository and Score, that RepositoryCommit doesn't.
That's completely fine, just pointing it out.
However, I think it'd be nice to add a blank line between CommentsURL field and Repository field, to separate the common vs differing fields, similar to the blank line separator that RepositoryCommit already has.
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @amirilovic and @shurcooL!
|
Merging. |
…oogle#602) Fix issue with commit search results deserialization Fixes google#601.
There were breaking API changes in previous commit (175a6b4). Follows google#602.
No description provided.