-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat!: Refactor client constructor to use options pattern #4201
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,7 +50,11 @@ func main() { | |||||||
|
|
||||||||
| fmt.Printf("\nDownloading %v/%v/%v at ref %v to %v...\n", owner, repo, repoPath, ref, outputPath) | ||||||||
|
|
||||||||
| client := github.NewClient(nil) | ||||||||
| client, err := github.NewClient() | ||||||||
| if err != nil { | ||||||||
| fmt.Printf("Error creating GitHub client: %v\n", err) | ||||||||
| os.Exit(1) | ||||||||
|
Comment on lines
+55
to
+56
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } | ||||||||
|
|
||||||||
| rc, _, err := client.Repositories.DownloadContents(context.Background(), owner, repo, repoPath, &github.RepositoryContentGetOptions{Ref: ref}) | ||||||||
| if err != nil { | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,7 +37,11 @@ func main() { | |||||||
| paginator := githubpagination.NewClient(rateLimiter, | ||||||||
| githubpagination.WithPerPage(100), // default to 100 results per page | ||||||||
| ) | ||||||||
| client := github.NewClient(paginator) | ||||||||
| client, err := github.NewClient(github.WithHTTPClient(paginator)) | ||||||||
| if err != nil { | ||||||||
| fmt.Printf("Error creating GitHub client: %v\n", err) | ||||||||
| return | ||||||||
|
Comment on lines
+42
to
+43
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } | ||||||||
|
|
||||||||
| // Example usage of the client | ||||||||
| repos, _, err := client.Repositories.ListByUser(context.Background(), username, nil) | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,7 +25,10 @@ func main() { | |||||
| fmt.Println() | ||||||
|
|
||||||
| ctx := context.Background() | ||||||
| client := github.NewClient(nil).WithAuthToken(string(token)) | ||||||
| client, err := github.NewClient(github.WithAuthToken(string(token))) | ||||||
| if err != nil { | ||||||
| log.Fatalf("Error creating GitHub client: %v\n", err) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| user, resp, err := client.Users.Get(ctx, "") | ||||||
| if err != nil { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -24,7 +24,10 @@ func main() { | |||||
| } | ||||||
|
|
||||||
| ctx := context.Background() | ||||||
| client := github.NewClient(nil).WithAuthToken(token) | ||||||
| client, err := github.NewClient(github.WithAuthToken(token)) | ||||||
| if err != nil { | ||||||
| log.Fatalf("Error creating GitHub client: %v\n", err) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| owner := "OWNER" | ||||||
| repo := "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.
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 intentionally kept the existing pattern for the individual examples rather than standardising them all.
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, let's please clean them all up and standardize them since you are touching every one of these in this PR.