-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add missing apps methods #733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add missing apps methods #733
Conversation
3d78587
to
7136f17
Compare
73cc038
to
56b2ed1
Compare
Note: I accidentally pushed an incorrect squash, but fixed it. However, that caused |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @mandrean!
Just a few minor comments to address, and some advice requested from other reviewers.
github/apps.go
Outdated
// the authenticated GitHub App. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/apps/#get-a-single-github-app | ||
func (s *AppsService) Get(ctx context.Context, slug string) (*App, *Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please change slug
to appSlug
to match the docs and also add the following comment so that people don't have to follow the link to figure out what an appSlug
is?
// Note: appSlug is just the URL-friendly name of your GitHub App.
// You can find this on the settings page for your GitHub App
// (e.g., https://github.com/settings/apps/:app_slug).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
|
||
// AppsService provides access to the installation related functions | ||
// in the GitHub API. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/apps/ | ||
type AppsService service | ||
|
||
// App represents a GitHub App. | ||
type App struct { | ||
ID *int `json:"id,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually more of a question for @shurcooL or @willnorris...
In the light of #597, do you think we should start using int64
for numeric IDs for new APIs in order to make the implementation of #597 easier (by providing an example and reducing the number of changes needed)?
Or do you think that we should remain internally consistent and just change everything all at once when #597 is addressed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it's unclear what the state of #597 is right now. The issue has been opened a while ago, but I haven't seen any reports of issues from production use. I'm not convinced that we should act right away, or how we should act. I think that we need to collect more data in that issue (or, wait until there's a concrete need to act).
Because of that, I think we should not try to incorporate that issue into this one. So, I suggest we stay consistent, and deal with int
-> int64
changes (or another solution), if at all, later and separately from this PR.
// TODO: remove custom Accept header when this API fully launches. | ||
req.Header.Set("Accept", mediaTypeIntegrationPreview) | ||
|
||
var i struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shurcooL - what do you think about making this a new type ... struct
and include the TotalCount
field, then returning a pointer to the struct in the return value of this method?
I'm asking because it seems more consistent with the rest of the package and also allows GitHub to add/tweak their response and we could more flexibly support it however they decide to tweak it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I think we should have this method return a pointer to a struct that corresponds to the JSON response in the documentation.
Returning []*Installation
would've made sense if the GitHub response was a JSON array of installation objects, but it's a JSON object containing installations
field with the array.
The only question is what to name it, if we make it exported (I think we have to, don't we?). Perhaps ListUserInstallationsResponse
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then again, it's unfortunate it's quite different from the existing ListInstallations
method (https://developer.github.com/v3/apps/#find-installations) which does return a JSON array of installations...
I can't help but think GitHub might've made the API inconsistent unintentionally and might want to change it while it's still in preview, so it'd be worth shooting them an email about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmlewis @shurcooL I did this in my original contribution, but later removed it because I didn't see this pattern being used in other places in go-github
where the same type of JSON structure was being handled.
I tried to stay "idiomatic" to your library. But personally I would have mimicked their JSON response as closely as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see this pattern being used in other places in
go-github
where the same type of JSON structure was being handled.
Mind sharing examples of that? It would be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shurcooL: This is currently in master
: https://github.com/google/go-github/blob/master/github/apps_installation.go#L40
But as you can see in the GitHub API docs, the response actually has the total_count
field: https://developer.github.com/v3/apps/installations/#list-repositories
So I just reused that same pattern for my ListUserRepos
and ListUserInstallations
contribution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@gmlewis What do you think about this finding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github/apps_installation.go
Outdated
// TODO: remove custom Accept header when this API fully launches. | ||
req.Header.Set("Accept", mediaTypeIntegrationPreview) | ||
|
||
var r struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shurcooL - Same for this one... make a new type ... struct
and return it?
github/apps_installation.go
Outdated
} | ||
|
||
// TODO: remove custom Accept header when this API fully launches. | ||
req.Header.Set("Accept", mediaTypeIntegrationPreview) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed for this endpoint? I didn't see it in the link on line 57.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed!
1580d77
to
0142ac9
Compare
Is there any update on this PR in terms of reviewing the updates from @mandrean ? It would be great to have those missing APIs, and it's hard to add them outside the library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you, @mandrean.
Awaiting second LGTM before merging. @shurcooL may not be available currently, so I will request a review from @elliott-beach if he can.
@mandrean - would you mind resolving the merge conflicts? |
With the help of @itay and PR #769, I'll take care of the merge conflicts here by force pushing the squashed and rebased commit 15ad131 (with merge conflicts resolved) to the PR branch. I've confirmed that it's good and doesn't differ from the contents of this PR (aside from conflict resolution). Edit: Done. (For reference, the previous head commit of this PR was 0142ac9.) |
0142ac9
to
15ad131
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reviewed at a high-level and didn't spot any major issues. Since this is new functionality, instead of spending an exorbitant amount of time reviewing it for low-level issues prior to merging, I'd prefer we merge it sooner and let people who want to use this API (e.g., @itay) test it out. If any issues or deviations from actual GitHub API are discovered through real-world use, they'll be easy to prioritize and address then. That seems like a more efficient way to move forward.
So, LGTM. It already has @gmlewis's LGTM, so I'll merge. Please let us know if any issues come up.
This pull request provides the missing apps methods and tests.
Fixes #734.