-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Update apps.go #1238
Update apps.go #1238
Conversation
Add installation token parameters, allowing creation of permission-scoped github tokens.
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). 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 (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Add test for creating installation tokens with additional parameters. https://developer.github.com/v3/apps/#create-a-new-installation-token
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
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, @emoryruscus.
Please address the comments and then we will go for another round of review.
github/apps.go
Outdated
// InstallationTokenParameters allow restricting a token's access to specific repositories. | ||
type InstallationTokenParameters struct { | ||
// The ids of the repositories that the installation token can access. | ||
// Providing repository ids restricts the access of an installation token to specific repositories. |
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.
Let's please change ids
in the comment to IDs
for the auto-generated godocs.
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.
github/apps.go
Outdated
@@ -194,10 +211,10 @@ func (s *AppsService) ListUserInstallations(ctx context.Context, opt *ListOption | |||
// CreateInstallationToken creates a new installation token. | |||
// | |||
// GitHub API docs: https://developer.github.com/v3/apps/#create-a-new-installation-token | |||
func (s *AppsService) CreateInstallationToken(ctx context.Context, id int64) (*InstallationToken, *Response, error) { | |||
func (s *AppsService) CreateInstallationToken(ctx context.Context, id int64, body ...interface{}) (*InstallationToken, *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.
Please let's not use ...interface{}
but keep this repo strictly typed.
There are many other examples where we pass in a pointer to an optional struct and we usually call it opt
, as in:
opt *InstallationTokenOptions
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.
github/apps.go
Outdated
} | ||
|
||
// InstallationTokenParameters allow restricting a token's access to specific repositories. | ||
type InstallationTokenParameters 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.
Let's please rename this to InstallationTokenOptions
to be more consistent with the rest of the repo.
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.
github/apps.go
Outdated
Token *string `json:"token,omitempty"` | ||
ExpiresAt *time.Time `json:"expires_at,omitempty"` | ||
Permissions *InstallationPermissions `json:"permissions,omitempty"` | ||
Repositories *[]Repository `json:"repositories,emitempty"` |
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.
Please change *[]Repository
to []*Repository
instead.
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.
github/apps.go
Outdated
@@ -282,3 +299,32 @@ func (s *AppsService) getInstallation(ctx context.Context, url string) (*Install | |||
|
|||
return i, resp, nil | |||
} | |||
|
|||
// GetReadWriter converts a body interface into an io.ReadWriter object. | |||
func GetReadWriter(body interface{}) (io.ReadWriter, 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.
I don't think this or the next function are necessary. Please remove them.
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.
They are used in apps_test.go, and I would like to use them in the ghinstallation package in a subsequent pull request as well. It's useful for comparing results in testing, and will be useful in converting installation token options into a ReadWriter to pass to http.NewRequest in ghinstallation.
FYI This PR has related / same feature: #1182 |
Ah, thank you for the pointer, @shanempope! It appears that #1182 never got completed... so when this PR is merged we can close that other PR, unless that one gets finished first, then we can close this one. 😃 |
Change 'parameters' to 'options'.
Friendly ping, @gmlewis do you have a moment to look over the small changes I made? |
Hi @emoryruscus, I was waiting to review again until after you fix the broken Travis CI build. Also, I'm not convinced that we need the helper functions and do not wish to increase the maintenance burden of this repo by adding unnecessary functions... I haven't read your argument yet, just saw that you added one. I don't have time now, but was going to give it more detailed attention once you fix the broken build. |
Add GetPermissions() and GetRepositories() accessor functions.
Try to comply with Travis build failure.
Reformat file for Travis.
gofmt fix spacing issue
Codecov Report
@@ Coverage Diff @@
## master #1238 +/- ##
==========================================
+ Coverage 73.36% 73.42% +0.06%
==========================================
Files 86 86
Lines 6026 6040 +14
==========================================
+ Hits 4421 4435 +14
Misses 836 836
Partials 769 769
Continue to review full report at Codecov.
|
Move GetReadWriter and GetReadCloser from apps.go to apps_test.go to improve coverage.
Move GetReadWriter and GetReadCloser from apps.go to apps_test.go to improve coverage.
Fix imports.
Fix imports.
author Emory Ruscus <[email protected]> 1563895211 -0400 committer Emory Ruscus <[email protected]> 1565621142 -0400 Update apps.go Add installation token parameters, allowing creation of permission-scoped github tokens. Update apps_test.go Add test for creating installation tokens with additional parameters. https://developer.github.com/v3/apps/#create-a-new-installation-token Update apps.go - Change 'parameters' to 'options' Update apps_test.go Change 'parameters' to 'options'. Update apps_test.go Update github-accessors.go Add GetPermissions() and GetRepositories() accessor functions. Update github-accessors.go Try to comply with Travis build failure. Update github-accessors.go Reformat file for Travis. gofmt spacing fix Move reader functions for coverage test. Move GetReadWriter and GetReadCloser from apps.go to apps_test.go to improve coverage. Move reader functions for coverage test. Move GetReadWriter and GetReadCloser from apps.go to apps_test.go to improve coverage. Update apps.go Fix imports. Update apps_test.go Fix imports.
…to patch-1 Tip of current branch is behind its remote counterpart.
Sorry about that! Fixed the broken Travis CI build. Also moved the helper functions into apps_test.go, which I think you will like more. |
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, @emoryruscus!
This looks much better to me now.
Just one minor tweak, please, and then I think we'll be ready to merge once we get a second LGTM.
github/apps.go
Outdated
Token *string `json:"token,omitempty"` | ||
ExpiresAt *time.Time `json:"expires_at,omitempty"` | ||
Permissions *InstallationPermissions `json:"permissions,omitempty"` | ||
Repositories []*Repository `json:"repositories,emitempty"` |
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 should be omitempty
, not emitempty
.
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.
Great catch, thanks! Done.
@@ -330,3 +382,31 @@ func TestAppsService_FindUserInstallation(t *testing.T) { | |||
t.Errorf("Apps.FindUserInstallation returned %+v, want %+v", installation, want) | |||
} | |||
} | |||
|
|||
// GetReadWriter converts a body interface into an io.ReadWriter object. |
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.
Yes, I much prefer these two new helper functions be used for testing only... thank you!
In fact, since they are rather general purpose, I would be fine to move them to github_test.go
if you want, or we could just leave them here for now and move them in a later PR if they become more generally used.
We'll see what @gauntface thinks about them.
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.
Welcome! Will leave them here for now if that is alright.
Change 'emitempty' to '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.
No problem! @gauntface is there anything else you would like to see in this change? |
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 from me =. I'd keep the helpers where they are until someone wants to re-use them.
Sounds good, thanks! |
Thank you, @emoryruscus and @gauntface ! Merging. Note to self: This is a breaking API change so the major version needs to be bumped after merging. |
Add installation token parameters, allowing creation of permission-scoped github tokens.
https://developer.github.com/v3/apps/#create-a-new-installation-token