Uh oh!
There was an error while loading. Please reload this page.
Fixing issue with commit search results deserialization #601 - #602
Conversation
| 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.
gmlewis
commented
Mar 29, 2017
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! |
amirilovic
commented
Mar 29, 2017
@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.typeRepositoriesSearchResultstruct {
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.typeIssuesSearchResultstruct {
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.typeUsersSearchResultstruct {
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.typeCodeSearchResultstruct {
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.typeCommitsSearchResultstruct {
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 |
gmlewis
commented
Mar 29, 2017
OK, SGTM. |
dmitshur
commented
Mar 29, 2017
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. |
amirilovic
commented
Mar 30, 2017
@shurcooL Good point. |
| // 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
amirilovic
commented
Mar 30, 2017
@shurcooL Anything else that needs to be done here? |
| 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!
gmlewis
commented
Mar 31, 2017
Merging. |
…oogle#602) Fix issue with commit search results deserialization Fixesgoogle#601.
There were breaking API changes in previous commit (175a6b4). Follows google#602.
…oogle#602) Fix issue with commit search results deserialization Fixesgoogle#601.
There were breaking API changes in previous commit (175a6b4). Follows google#602.
No description provided.