Skip to content

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 3 commits into from
Oct 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

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
alexandear committed Oct 3, 2024
commit 5a6087819752da0686d5c9db234d2634e12ba14c
74 changes: 37 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# go-github #

[![go-github release (latest SemVer)](https://img.shields.io/github/v/release/google/go-github?sort=semver)](https://github.com/google/go-github/releases)
[![GoDoc](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/github.com/google/go-github/v65/github)
[![Go Reference](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/github.com/google/go-github/v65/github)
[![Test Status](https://github.com/google/go-github/workflows/tests/badge.svg)](https://github.com/google/go-github/actions?query=workflow%3Atests)
[![Test Coverage](https://codecov.io/gh/google/go-github/branch/master/graph/badge.svg)](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)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/796/badge)](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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)
}
```

Expand Down Expand Up @@ -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.
Expand All @@ -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
["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).

### Accepted Status ###

Expand All @@ -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"
Expand All @@ -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
["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).

### Creating and Updating Resources ###

Expand Down Expand Up @@ -316,7 +315,7 @@ for {
}
```

#### Iterators (**experimental**)
#### Iterators (**experimental**) ####

Go v1.23 introduces the new `iter` package.

Expand Down Expand Up @@ -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.

Expand All @@ -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.
Expand Down
Loading