Fix GetBranch response#490
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
|
I signed it! |
|
CLAs look good, thanks! |
|
You're absolutely right. It was surprising to me that we'd have such a glaring error, so I dug through git blame to see how it occurred (in order to make sure I'm not overlooking something). It seems we've had the issue since its very initial implementation in 2014. From that commit, I have a pretty good of how it happened. If you look at https://developer.github.com/v3/repos/branches/#list-branches, you'll see the example that the list endpoint provides has only "sha" and "url" fields inside the "commit" object. A coincidence is that both
Thanks for the patch! |
github/repos_test.go
Outdated
| want := &Branch{ | ||
| Name: String("n"), | ||
| Commit: &Commit{SHA: String("s")}, | ||
| Commit: &RepositoryCommit{SHA: String("s")}, |
There was a problem hiding this comment.
This is good, but I think it's a good opportunity to expand the test data to include a Commit inside. That way it'd be a little more representative of the real data you get from GitHub, ala https://developer.github.com/v3/repos/branches/#get-branch.
Something like this:
want := &Branch{
Name: String("n"),
Commit: &RepositoryCommit{
SHA: String("s"),
Commit: &Commit{
Message: String("m"),
},
},
Protected: Bool(true),
}You'd have to update the mux.HandleFunc("/repos/o/r/branches/b" above, of course.
Doing this is optional, if you agree it'd be an improvement for this Go package.
|
Included in a77ccc9. |
Closes google#490. Change-Id: Ie12aca585fe07cb572b347ef3b8f42c26b229808
I want to get a time of the last commit in branch. I read Github API: Get Branch docs and found the RepositoriesService.GetBranch method. I called it like so:
But get the following data (e.g. for this repo):
{ github.Commit { SHA:"5c45bca952b96dedace6c307caff915483013003", Author:github.CommitAuthor{}, Committer:github.CommitAuthor{}, Parents:[ github.Commit{ SHA:"5c5ff1dadae3bb0b306004d480a88e7ddc1714ca", URL:"https://api.github.com/repos/google/go-github/commits/5c5ff1dadae3bb0b306004d480a88e7ddc1714ca" } ], URL:"https://api.github.com/repos/google/go-github/commits/5c45bca952b96dedace6c307caff915483013003" } }As you see, the Author and Committer fields has no info. I tried to call the endpoint with curl:
And get data I expected:
Looks like
commitat the root of response is a RepositoryCommit.