-
Notifications
You must be signed in to change notification settings - Fork 2.1k
docs: Improve formatting in README #3300
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
docs: Improve formatting in README
- Loading branch information
commit 5a6087819752da0686d5c9db234d2634e12ba14c
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
# go-github # | ||
|
||
[](https://github.com/google/go-github/releases) | ||
[](https://pkg.go.dev/github.com/google/go-github/v65/github) | ||
[](https://pkg.go.dev/github.com/google/go-github/v65/github) | ||
[](https://github.com/google/go-github/actions?query=workflow%3Atests) | ||
[](https://codecov.io/gh/google/go-github) | ||
[![Discuss at [email protected]](https://img.shields.io/badge/discuss-go--github%40googlegroups.com-blue.svg)](https://groups.google.com/group/go-github) | ||
[](https://bestpractices.coreinfrastructure.org/projects/796) | ||
|
||
go-github is a Go client library for accessing the [GitHub API v3][]. | ||
|
||
Currently, **go-github requires Go version 1.13 or greater**. go-github tracks | ||
Currently, **go-github requires Go version 1.21 or greater**. go-github tracks | ||
[Go's version support policy][support-policy]. We do our best not to break | ||
older versions of Go if we don't have to, but due to tooling constraints, we | ||
don't always test older versions. | ||
|
@@ -71,10 +71,9 @@ repos, _, err := client.Repositories.ListByOrg(context.Background(), "github", o | |
``` | ||
|
||
The services of a client divide the API into logical chunks and correspond to | ||
the structure of the GitHub API documentation at | ||
https://docs.github.com/en/rest . | ||
the structure of the [GitHub API documentation](https://docs.github.com/en/rest). | ||
|
||
NOTE: Using the [context](https://godoc.org/context) package, one can easily | ||
NOTE: Using the [context](https://pkg.go.dev/context) package, one can easily | ||
pass cancelation signals and deadlines to various services of the client for | ||
handling a request. In case there is no context available, then `context.Background()` | ||
can be used as a starting point. | ||
|
@@ -97,11 +96,12 @@ include the specified OAuth token. Therefore, authenticated clients should | |
almost never be shared between different users. | ||
|
||
For API methods that require HTTP Basic Authentication, use the | ||
[`BasicAuthTransport`](https://godoc.org/github.com/google/go-github/github#BasicAuthTransport). | ||
[`BasicAuthTransport`](https://pkg.go.dev/github.com/google/go-github/github#BasicAuthTransport). | ||
|
||
#### As a GitHub App #### | ||
|
||
GitHub Apps authentication can be provided by different pkgs like [ghinstallation](https://github.com/bradleyfalzon/ghinstallation) or [go-githubauth](https://github.com/jferrl/go-githubauth). | ||
GitHub Apps authentication can be provided by different pkgs like [bradleyfalzon/ghinstallation](https://github.com/bradleyfalzon/ghinstallation) | ||
or [jferrl/go-githubauth](https://github.com/jferrl/go-githubauth). | ||
|
||
> **Note**: Most endpoints (ex. [`GET /rate_limit`]) require access token authentication | ||
> while a few others (ex. [`GET /app/hook/deliveries`]) require [JWT] authentication. | ||
|
@@ -148,33 +148,33 @@ Other example using `go-githubauth`: | |
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/google/go-github/v65/github" | ||
"github.com/jferrl/go-githubauth" | ||
"golang.org/x/oauth2" | ||
"context" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/google/go-github/v65/github" | ||
"github.com/jferrl/go-githubauth" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
func main() { | ||
privateKey := []byte(os.Getenv("GITHUB_APP_PRIVATE_KEY")) | ||
privateKey := []byte(os.Getenv("GITHUB_APP_PRIVATE_KEY")) | ||
|
||
appTokenSource, err := githubauth.NewApplicationTokenSource(1112, privateKey) | ||
if err != nil { | ||
fmt.Println("Error creating application token source:", err) | ||
return | ||
} | ||
appTokenSource, err := githubauth.NewApplicationTokenSource(1112, privateKey) | ||
if err != nil { | ||
fmt.Println("Error creating application token source:", err) | ||
return | ||
} | ||
|
||
installationTokenSource := githubauth.NewInstallationTokenSource(1113, appTokenSource) | ||
installationTokenSource := githubauth.NewInstallationTokenSource(1113, appTokenSource) | ||
|
||
// oauth2.NewClient uses oauth2.ReuseTokenSource to reuse the token until it expires. | ||
// The token will be automatically refreshed when it expires. | ||
// InstallationTokenSource has the mechanism to refresh the token when it expires. | ||
httpClient := oauth2.NewClient(context.Background(), installationTokenSource) | ||
// oauth2.NewClient uses oauth2.ReuseTokenSource to reuse the token until it expires. | ||
// The token will be automatically refreshed when it expires. | ||
// InstallationTokenSource has the mechanism to refresh the token when it expires. | ||
httpClient := oauth2.NewClient(context.Background(), installationTokenSource) | ||
|
||
client := github.NewClient(httpClient) | ||
client := github.NewClient(httpClient) | ||
} | ||
``` | ||
|
||
|
@@ -205,8 +205,7 @@ if _, ok := err.(*github.RateLimitError); ok { | |
} | ||
``` | ||
|
||
Learn more about GitHub rate limiting at | ||
https://docs.github.com/en/rest/rate-limit . | ||
Learn more about GitHub rate limiting in the ["REST API endpoints for rate limits"](https://docs.github.com/en/rest/rate-limit). | ||
|
||
In addition to these rate limits, GitHub imposes a secondary rate limit on all API clients. | ||
This rate limit prevents clients from making too many concurrent requests. | ||
|
@@ -226,11 +225,11 @@ Alternatively, you can block until the rate limit is reset by using the `context | |
repos, _, err := client.Repositories.List(context.WithValue(ctx, github.SleepUntilPrimaryRateLimitResetWhenRateLimited, true), "", nil) | ||
``` | ||
|
||
You can use [go-github-ratelimit](https://github.com/gofri/go-github-ratelimit) to handle | ||
You can use [gofri/go-github-ratelimit](https://github.com/gofri/go-github-ratelimit) to handle | ||
secondary rate limit sleep-and-retry for you. | ||
|
||
Learn more about GitHub secondary rate limiting at | ||
https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#about-secondary-rate-limits . | ||
Learn more about GitHub secondary rate limiting in the | ||
alexandear marked this conversation as resolved.
Show resolved
Hide resolved
|
||
["About secondary rate limits"](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#about-secondary-rate-limits). | ||
alexandear marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Accepted Status ### | ||
|
||
|
@@ -255,7 +254,7 @@ The GitHub API has good support for conditional requests which will help | |
prevent you from burning through your rate limit, as well as help speed up your | ||
application. `go-github` does not handle conditional requests directly, but is | ||
instead designed to work with a caching `http.Transport`. We recommend using | ||
https://github.com/gregjones/httpcache for that. For example: | ||
[gregjones/httpcache](https://github.com/gregjones/httpcache) for that. For example: | ||
|
||
```go | ||
import "github.com/gregjones/httpcache" | ||
|
@@ -265,8 +264,8 @@ import "github.com/gregjones/httpcache" | |
).WithAuthToken(os.Getenv("GITHUB_TOKEN")) | ||
``` | ||
|
||
Learn more about GitHub conditional requests at | ||
https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api?apiVersion=2022-11-28#use-conditional-requests-if-appropriate | ||
Learn more about GitHub conditional requests in the | ||
alexandear marked this conversation as resolved.
Show resolved
Hide resolved
|
||
["Use conditional requests if appropriate"](https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api?apiVersion=2022-11-28#use-conditional-requests-if-appropriate). | ||
alexandear marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Creating and Updating Resources ### | ||
|
||
|
@@ -316,7 +315,7 @@ for { | |
} | ||
``` | ||
|
||
#### Iterators (**experimental**) | ||
#### Iterators (**experimental**) #### | ||
|
||
Go v1.23 introduces the new `iter` package. | ||
|
||
|
@@ -367,7 +366,7 @@ For complete usage of go-github, see the full [package docs][]. | |
[GitHub webhook events]: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads | ||
[cbrgm/githubevents]: https://github.com/cbrgm/githubevents | ||
|
||
### Testing code that uses `go-github` | ||
### Testing code that uses `go-github` ### | ||
|
||
The repo [migueleliasweb/go-github-mock](https://github.com/migueleliasweb/go-github-mock) provides a way to mock responses. Check the repo for more details. | ||
|
||
|
@@ -376,6 +375,7 @@ The repo [migueleliasweb/go-github-mock](https://github.com/migueleliasweb/go-gi | |
You can run integration tests from the `test` directory. See the integration tests [README](test/README.md). | ||
|
||
## Contributing ## | ||
|
||
I would like to cover the entire GitHub API and contributions are of course always welcome. The | ||
calling pattern is pretty well established, so adding new methods is relatively | ||
straightforward. See [`CONTRIBUTING.md`](CONTRIBUTING.md) for details. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.