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 package constructors #2904

Merged
merged 7 commits into from
Aug 31, 2023
Merged

Update package constructors #2904

merged 7 commits into from
Aug 31, 2023

Conversation

WillAbides
Copy link
Contributor

Closes #2897

After experimenting with implementing #2897, I think this ends up with better usage for end users.

This deprecates github.NewTokenClient and github.NewEnterpriseClient and replaces them with Client.WithAuthToken and Client.WithEnterpriseURLs.

Now you can create an authenticated client for an enterprise server with:

client, err := github.NewClient(nil).WithAuthToken(token).WithEnterpriseURLs(baseURL,uploadURL)

There is no need for users import github.com/x/oauth2 anymore.

I opted for this implementation over my WithOptions proposal the error returned from WithOptions means that most uses of go-github would have an unnecessary error check.

client err := github.NewClient(nil).WithOptions(github.WithAuthToken(token))
if err != nil {
  panic(err)
}

vs

client := github.NewClient(nil).WithAuthToken(token)

@codecov
Copy link

codecov bot commented Aug 28, 2023

Codecov Report

Merging #2904 (8a74e05) into master (c36edbd) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2904   +/-   ##
=======================================
  Coverage   98.10%   98.11%           
=======================================
  Files         142      142           
  Lines       12347    12385   +38     
=======================================
+ Hits        12113    12151   +38     
  Misses        159      159           
  Partials       75       75           
Files Changed Coverage Δ
github/github.go 98.10% <100.00%> (+0.10%) ⬆️

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.

This looks great, @WillAbides !
Just a few minor nits, please, then we should be ready for a second LGTM+Approval from any other contributor to this repo before merging.

github/github.go Show resolved Hide resolved
github/github.go Show resolved Hide resolved
github/github.go Show resolved Hide resolved
@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Aug 28, 2023
@WillAbides
Copy link
Contributor Author

@gmlewis Updated with your suggestions.

As an aside, is there a way to get a preview of what codecov is going to report before pushing? I looked for a way to run it locally, and it appears to require an API token and membership in the right org.

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 29, 2023

As an aside, is there a way to get a preview of what codecov is going to report before pushing? I looked for a way to run it locally, and it appears to require an API token and membership in the right org.

Not that I'm aware of.

Sometimes, to get an idea of what it might report, I run this locally first:

$ cat coverage-web.sh
#!/bin/bash -ex
go test -coverprofile=cover.out ./...
go tool cover -html cover.out

but it is obviously not the same.

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.

Awesome! Thank you, @WillAbides !
LGTM.

Awaiting second LGTM+Approval from any other contributor to this repo before merging.

@WillAbides
Copy link
Contributor Author

I made a script to preview whether codecov will fail your PR: https://gist.github.com/WillAbides/e0bbffccb34d9922cecb2ab9d66defec

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 29, 2023

I made a script to preview whether codecov will fail your PR: https://gist.github.com/WillAbides/e0bbffccb34d9922cecb2ab9d66defec

Thank you, @WillAbides ! That's fantastic!

Copy link
Contributor

@sridharavinash sridharavinash left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the updates 💖 .

@gmlewis gmlewis removed the NeedsReview PR is awaiting a review before merging. label Aug 31, 2023
@gmlewis gmlewis changed the title Update constructors Update package constructors Aug 31, 2023
@gmlewis
Copy link
Collaborator

gmlewis commented Aug 31, 2023

Thank you, @sridharavinash !
Merging.

@gmlewis gmlewis merged commit 5ab57e7 into google:master Aug 31, 2023
9 checks passed
@WillAbides WillAbides deleted the clientopts3 branch August 31, 2023 19:28
gmlewis pushed a commit to gmlewis/go-github that referenced this pull request Sep 19, 2023
MichaelUrman added a commit to mutility/coverpkg that referenced this pull request Jan 10, 2024
google/go-github#2904 added support for bypassing github.com/x/oauth2. Use it.
MichaelUrman added a commit to mutility/coverpkg that referenced this pull request Jan 10, 2024
google/go-github#2904 added support for bypassing github.com/x/oauth2. Use it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: client.WithOptions
3 participants