Skip to content

Fixing issue with commit search results deserialization #601 - #602

Merged
gmlewis merged 7 commits into
google:masterfrom
foundcenter:master
Mar 31, 2017
Merged

Fixing issue with commit search results deserialization #601#602
gmlewis merged 7 commits into
google:masterfrom
foundcenter:master

Conversation

@amirilovic

Copy link
Copy Markdown
Contributor

No description provided.

Comment threadgithub/search.go Outdated
Commit *Commit `json:"commit,omitempty"`
Author *User `json:"author,omitempty"`
Committer *User `json:"committer,omitempty"`
Parents []Commit `json:"parents,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, will fix.

@gmlewis

Copy link
Copy Markdown
Collaborator

As part of this cleanup, can you please add HTMLURL to type Commit struct in git_commits.go (I cam across this while looking at the parents response)?

Also, in search.go can you please rename Total in type CommitsSearchResult struct to TotalCount for consistency?

Since these are breaking API changes, we also need to bump the version number.

Thank you!

@amirilovic

Copy link
Copy Markdown
ContributorAuthor

@gmlewis All fine for TotalCount.

For HTMLURL in Commit, I think it's fine right now.
If you take a look at https://developer.github.com/v3/search/#search-commits results are represented as CommitResult which does have HTMLURL

type CommitResult struct {
...
Commit *Commit `json:"commit,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
....
}

Also for RepositoryCommit as a result of https://developer.github.com/v3/repos/commits/#get-a-single-commit

type RepositoryCommit struct {
...
Commit *Commit `json:"commit,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
...
}

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

...
"parents": [
{
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
}
],
...

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:

type CommitReference {
SHA *string `json:"sha,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
}

and change RepositoryResult and CommitResult to be:

type RepositoryCommit struct {
...
Parents []CommitReference `json:"parents,omitempty"`
...
}
type CommitResult struct {
...
Parents []CommitReference `json:"parents,omitempty"`
...
}

What do you think?

@dmitshur

dmitshur commented Mar 29, 2017

Copy link
Copy Markdown
Member

Also, in search.go can you please rename Total in type CommitsSearchResult struct to TotalCount for consistency?

@gmlewis, I don't think we should do this. At least not in this PR. It makes things inconsistent. Look at the rest of search.go:

// 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 Total to TotalCount only in CommitsSearchResult?

// 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 TotalCount to Total for now.

@gmlewis

Copy link
Copy Markdown
Collaborator

OK, SGTM.
Opened: #605
Sorry for the trouble, @amirilovic.

@dmitshur

Copy link
Copy Markdown
Member

About HTMLURL in Commit, I agree with @gmlewis that we should add it there.

@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 Commit. It maps to https://developer.github.com/v3/git/commits/#get-a-commit GitHub API endpoint, and its example output does not contain a "html_url" field:

{
"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:

https://api.github.com/repos/octocat/Hello-World/git/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d

{
"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, Commit should have HTMLURL.

They've probably added it more recently, and didn't update their old documentation examples.

@amirilovic

Copy link
Copy Markdown
ContributorAuthor

@shurcooL Good point.

Comment threadgithub/git_commits.go Outdated
// Commit represents a GitHub commit.
type Commit struct {
SHA *string `json:"sha,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`

@dmitshurdmitshurMar 30, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move it near URL, that should be a more fitting place for it.

See

HTMLURL*string`json:"html_url,omitempty"`
.

@amirilovic

Copy link
Copy Markdown
ContributorAuthor

@shurcooL Anything else that needs to be done here?

@dmitshurdmitshur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only request is to add a blank line – see inline comment for details.

Aside from that, I don't see any issues, so this will have my LGTM after this one change request. Thanks!

Comment threadgithub/search.go Outdated
URL *string `json:"url,omitempty"`
CommentsURL *string `json:"comments_url,omitempty"`
Repository *Repository `json:"repository,omitempty"`
Score *float64 `json:"score,omitempty"`

@dmitshurdmitshurMar 30, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dmitshurdmitshur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@dmitshur
dmitshur requested a review from gmlewisMarch 31, 2017 21:45

@gmlewisgmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @amirilovic and @shurcooL!

@gmlewis

Copy link
Copy Markdown
Collaborator

Merging.

@gmlewis
gmlewis merged commit 175a6b4 into google:masterMar 31, 2017
dmitshur added a commit that referenced this pull request Mar 31, 2017
There were breaking API changes in previous commit (175a6b4).
Follows #602.
bubg-dev pushed a commit to bubg-dev/go-github that referenced this pull request Jun 16, 2017
bubg-dev pushed a commit to bubg-dev/go-github that referenced this pull request Jun 16, 2017
There were breaking API changes in previous commit (175a6b4).
Follows google#602.
jlaportebot added a commit to jlaportebot/go-github that referenced this pull request Jun 28, 2026
jlaportebot added a commit to jlaportebot/go-github that referenced this pull request Jun 28, 2026
There were breaking API changes in previous commit (175a6b4).
Follows google#602.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@amirilovic@gmlewis@dmitshur