Repository navigation
Add link to GitHub Apps authentication package in docs. - #649
Conversation
|
I feel it'd be nice to replace the period with a colon and add a simple basic usage example here, in this README. You said:
The way I see it, in this README, just include a basic usage example for people to get started with. But leave advanced usage, details, explanations in the ghinstallation repo README. Just like for |
|
Sure, I can add a simple example. Is this OK: I can make it inline the |
|
I think it'd be helpful to include the import statement. It makes it easier to see the whole thing at a glance. Otherwise it's extra work and uncertainty for people to figure out the import path (it could be a vanity import path, so it requires extra steps to find out). You can stop after creating a GitHub client, no need to call methods on it. Maybe just a Also, why do you suggest creating a separate |
26095af to
e97b685
Compare
|
Sure, updated.
Ah must just be an oversight, GopherCI uses DefaultTransport (https://github.com/bradleyfalzon/gopherci/blob/03badd2364a4a3e85c0e4389c88ca86b7e2f7a70/internal/github/github.go#L38), so I'll modify that example. |
|
|
||
| func main() { | ||
| // Shared transport to reuse TCP connections. | ||
| tr := http.DefaultTransport |
There was a problem hiding this comment.
I think you can delete this line and its comment, and pass http.DefaultTransport directly to the ghinstallation.NewKeyFromFile call below.
It's pretty common knowledge that transports should be reused, unless there are specific reasons not to. I don't think you need to elaborate on that here. This is meant to be a minimal simple example to get started quickly.
There was a problem hiding this comment.
Agreed, done.
| // Wrap the shared transport for use with the integration ID 1 authenticating with installation ID 99. | ||
| itr, err := ghinstallation.NewKeyFromFile(tr, 1, 99, "2016-10-19.private-key.pem") | ||
| if err != nil { | ||
| log.Fatal(err) |
There was a problem hiding this comment.
Replace with // handle error to leave error handling up to user. We don't want to suggest bad practices, and doing better error handling can be verbose. It's common for usage examples to not elaborate on error handling, just that it should be done.
|
|
||
| // Use installation transport with client | ||
| client := github.NewClient(http.Client{Transport: itr}) | ||
| } |
There was a problem hiding this comment.
Replace } with // use client.... This is an incomplete program anyway (it's missing a package clause), so leaving out the closing } is okay. I don't see why you'd want to include } and make it seem like client isn't used at all.
There was a problem hiding this comment.
Yeah, but I was half copying the style of oauth2, I'll make this change, but let me know if you want to make further edits there for consistency.
135f498 to
399fdcd
Compare
There was a problem hiding this comment.
Hopefully last nitpicky comments.
After this, I think this looks good to me. But I want @gmlewis and/or @willnorris to review the change at a high level - are we okay with adding endorsement for the ghinstallation package in a separate repository?
I am okay with that, because:
- As I understand, it adds relevant missing functionality (to help #627).
- I briefly looked at the code and it looks clean to me (and it's short).
- There are no issues on https://goreportcard.com/report/github.com/bradleyfalzon/ghinstallation.
- It only imports 1 external dependency (
github.com/dgrijalva/jwt-go), which imports only standard library and looks fairly clean itself too (but I don't have experience with it). - I know @bradleyfalzon and trust his work. I'm sure that he'll maintain the package, or let us know if it should ever be removed from the README because it's no longer supported, etc.
- It also helps to know that it's used in production.
| func main() { | ||
| // Wrap the shared transport for use with the integration ID 1 authenticating with installation ID 99. | ||
| itr, err := ghinstallation.NewKeyFromFile(http.DefaultTransport, 1, 99, "2016-10-19.private-key.pem") | ||
| // Handle error. |
There was a problem hiding this comment.
I meant like this:
itr, err := ghinstallation.NewKeyFromFile(http.DefaultTransport, 1, 99, "2016-10-19.private-key.pem")
if err != nil {
// Handle error.
}I think it's a lot more readable at a glance this way, compared to just a plain text comment without the if err != nil { line.
There was a problem hiding this comment.
Of course, I wasn't thinking. Done.
| client := github.NewClient(http.Client{Transport: itr}) | ||
|
|
||
| // Use client... | ||
|
|
There was a problem hiding this comment.
Okay, I see how this looks kinda bad/unbalanced without the closing } for func main() { now. So let's add that back in. Keep the // Use client... comment of course.
There was a problem hiding this comment.
Yeah sounds good. Done.
| For API methods that require HTTP Basic Authentication, use the | ||
| [`BasicAuthTransport`](https://godoc.org/github.com/google/go-github/github#BasicAuthTransport). | ||
|
|
||
| GitHub Apps authentication can be provided by [ghinstallation](https://github.com/bradleyfalzon/ghinstallation). |
There was a problem hiding this comment.
Add the word "package" after ghinstallation maybe?
GitHub Apps authentication can be provided by the ghinstallation package.
Notice how above it says:
The easiest and recommended way to do this is using the oauth2 library, ...
There was a problem hiding this comment.
Agreed, done.
399fdcd to
7c732c8
Compare
The other option is to roll ghinstallation into go-github, I'd have no problem with that. Potentially with the idea to split the single Transport package into IntegrationTransport and InstallationTransport. |
| } | ||
|
|
||
| // Use installation transport with client. | ||
| client := github.NewClient(http.Client{Transport: itr}) |
There was a problem hiding this comment.
Minor. Shouldn't this be &http.Client?
There was a problem hiding this comment.
Yes it should, fixed, and thanks.
7c732c8 to
509b36e
Compare
|
Friendly ping @gmlewis and @willnorris. I want to make sure you saw my comment from 7 days ago, in case it got buried by the minor typo discussion that followed. |
|
I'm fine with the endorsement, but before proceeding, I would like confirmation from @willnorris and I defer to his judgement. I'll ask him to review this. |
|
Great! Merging. If there are any important updates or changes to the linked package, please let us know @bradleyfalzon. We're here to help. Thanks for creating it! |
This is a package that provides an http.RoundTripper for GitHub Apps Authentication as an Installation. It can be used with go-github. Helps google#455. Helps google#627.
This is a package that provides an http.RoundTripper for GitHub Apps Authentication as an Installation. It can be used with go-github. Helps google#455. Helps google#627.
As discussed in #627 I have a package which provides the GitHub Apps Authentication as an Installation
http.RoundTripperthat I use with this GitHub library successfully. I'm happy to keep maintaining it in an external repository, but a link from this library may assist others in finding the package.Relates to #455.