Skip to content
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

Merged
merged 18 commits into from
Aug 24, 2019
Merged

Update apps.go #1238

merged 18 commits into from
Aug 24, 2019

Conversation

emoryruscus
Copy link
Contributor

Add installation token parameters, allowing creation of permission-scoped github tokens.

https://developer.github.com/v3/apps/#create-a-new-installation-token

Add installation token parameters, allowing creation of permission-scoped github tokens.
@googlebot
Copy link

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. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual 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
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Indication that the PR author has signed a Google Contributor License Agreement. and removed cla: no labels Jul 23, 2019
Copy link
Collaborator

@gmlewis gmlewis left a 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.
Copy link
Collaborator

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.

Copy link
Contributor Author

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) {
Copy link
Collaborator

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

Copy link
Contributor Author

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 {
Copy link
Collaborator

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.

Copy link
Contributor Author

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"`
Copy link
Collaborator

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.

Copy link
Contributor Author

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) {
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

https://github.com/bradleyfalzon/ghinstallation

@shanempope
Copy link
Contributor

FYI This PR has related / same feature: #1182

@gmlewis
Copy link
Collaborator

gmlewis commented Jul 24, 2019

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. 😃

@emoryruscus
Copy link
Contributor Author

Friendly ping, @gmlewis do you have a moment to look over the small changes I made?

@gmlewis
Copy link
Collaborator

gmlewis commented Jul 30, 2019

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.

emoryruscus and others added 7 commits August 1, 2019 15:26
Add GetPermissions() and GetRepositories() accessor functions.
Try to comply with Travis build failure.
Reformat file for Travis.
gofmt fix spacing issue
@codecov
Copy link

codecov bot commented Aug 5, 2019

Codecov Report

Merging #1238 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
github/apps.go 67.81% <100%> (ø) ⬆️
github/github.go 89.31% <0%> (ø) ⬆️
github/repos.go 75.16% <0%> (+0.79%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c756c32...9d6fd70. Read the comment docs.

emoryruscus and others added 6 commits August 8, 2019 11:05
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.
@emoryruscus
Copy link
Contributor Author

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.

Copy link
Collaborator

@gmlewis gmlewis left a 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"`
Copy link
Collaborator

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.

Copy link
Contributor Author

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.
Copy link
Collaborator

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.

Copy link
Contributor Author

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'.
Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @emoryruscus!

LGTM.

Awaiting second LGTM before merging.

@gmlewis gmlewis requested a review from gauntface August 13, 2019 14:26
@emoryruscus
Copy link
Contributor Author

No problem! @gauntface is there anything else you would like to see in this change?

Copy link
Contributor

@gauntface gauntface left a 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.

@emoryruscus
Copy link
Contributor Author

Sounds good, thanks!

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 24, 2019

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.

@gmlewis gmlewis merged commit 61d9e5b into google:master Aug 24, 2019
gmlewis added a commit that referenced this pull request Aug 24, 2019
@emoryruscus emoryruscus deleted the patch-1 branch August 24, 2019 17:10
n1lesh pushed a commit to n1lesh/go-github that referenced this pull request Oct 2, 2020
n1lesh pushed a commit to n1lesh/go-github that referenced this pull request Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indication that the PR author has signed a Google Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants