Skip to content

Commit

Permalink
Merge branch 'master' into copilot_usage
Browse files Browse the repository at this point in the history
  • Loading branch information
claystation authored Oct 9, 2024
2 parents c082b15 + 13afa20 commit d45f521
Show file tree
Hide file tree
Showing 209 changed files with 5,700 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ jobs:

- name: Upload coverage to Codecov
if: ${{ matrix.update-coverage }}
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 #v4.5.0
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 #v4.6.0
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ linters:
- gosec
- misspell
- nakedret
- paralleltest
- stylecheck
- tparallel
- unconvert
- unparam
- whitespace
Expand Down Expand Up @@ -50,3 +52,7 @@ issues:
- linters: [ gosec ]
text: 'G304: Potential file inclusion via variable'
path: '^(example|tools)\/'

# We don't run parallel integration tests
- linters: [ paralleltest, tparallel ]
path: '^test/integration'
88 changes: 45 additions & 43 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/v66/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 go-github@googlegroups.com](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 tests against Go version 1.22 and 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 All @@ -24,29 +24,29 @@ If you're interested in using the [GraphQL API v4][], the recommended library is
go-github is compatible with modern Go releases in module mode, with Go installed:

```bash
go get github.com/google/go-github/v65
go get github.com/google/go-github/v66
```

will resolve and add the package to the current development module, along with its dependencies.

Alternatively the same can be achieved if you use import in a package:

```go
import "github.com/google/go-github/v65/github"
import "github.com/google/go-github/v66/github"
```

and run `go get` without parameters.

Finally, to use the top-of-trunk version of this repo, use the following command:

```bash
go get github.com/google/go-github/v65@master
go get github.com/google/go-github/v66@master
```

## Usage ##

```go
import "github.com/google/go-github/v65/github" // with go modules enabled (GO111MODULE=on or outside GOPATH)
import "github.com/google/go-github/v66/github" // with go modules enabled (GO111MODULE=on or outside GOPATH)
import "github.com/google/go-github/github" // with go modules disabled
```

Expand All @@ -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 All @@ -119,7 +119,7 @@ import (
"net/http"

"github.com/bradleyfalzon/ghinstallation/v2"
"github.com/google/go-github/v65/github"
"github.com/google/go-github/v66/github"
)

func main() {
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/v66/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,8 @@ 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
["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 +226,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
["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 +255,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 +265,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
["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 +316,7 @@ for {
}
```

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

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

Expand Down Expand Up @@ -361,13 +361,13 @@ For complete usage of go-github, see the full [package docs][].

[GitHub API v3]: https://docs.github.com/en/rest
[personal access token]: https://github.com/blog/1509-personal-api-tokens
[package docs]: https://pkg.go.dev/github.com/google/go-github/v65/github
[package docs]: https://pkg.go.dev/github.com/google/go-github/v66/github
[GraphQL API v4]: https://developer.github.com/v4/
[shurcooL/githubv4]: https://github.com/shurcooL/githubv4
[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 +376,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 Expand Up @@ -434,6 +435,7 @@ Versions prior to 48.2.0 are not listed.

| go-github Version | GitHub v3 API Version |
| ----------------- | --------------------- |
| 66.0.0 | 2022-11-28 |
| 65.0.0 | 2022-11-28 |
| 64.0.0 | 2022-11-28 |
| 63.0.0 | 2022-11-28 |
Expand Down
2 changes: 1 addition & 1 deletion example/actionpermissions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"log"
"os"

"github.com/google/go-github/v65/github"
"github.com/google/go-github/v66/github"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion example/appengine/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"net/http"
"os"

"github.com/google/go-github/v65/github"
"github.com/google/go-github/v66/github"
"google.golang.org/appengine"
"google.golang.org/appengine/log"
)
Expand Down
7 changes: 3 additions & 4 deletions example/basicauth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"os"
"strings"

"github.com/google/go-github/v65/github"
"github.com/google/go-github/v66/github"
"golang.org/x/term"
)

Expand All @@ -31,12 +31,11 @@ func main() {
username, _ := r.ReadString('\n')

fmt.Print("GitHub Password: ")
bytePassword, _ := term.ReadPassword(int(os.Stdin.Fd()))
password := string(bytePassword)
password, _ := term.ReadPassword(int(os.Stdin.Fd()))

tp := github.BasicAuthTransport{
Username: strings.TrimSpace(username),
Password: strings.TrimSpace(password),
Password: strings.TrimSpace(string(password)),
}

client := github.NewClient(tp.Client())
Expand Down
5 changes: 2 additions & 3 deletions example/codespaces/newreposecretwithxcrypto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"log"
"os"

"github.com/google/go-github/v65/github"
"github.com/google/go-github/v66/github"
"golang.org/x/crypto/nacl/box"
)

Expand Down Expand Up @@ -147,8 +147,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string,

var boxKey [32]byte
copy(boxKey[:], decodedPublicKey)
secretBytes := []byte(secretValue)
encryptedBytes, err := box.SealAnonymous([]byte{}, secretBytes, &boxKey, crypto_rand.Reader)
encryptedBytes, err := box.SealAnonymous([]byte{}, []byte(secretValue), &boxKey, crypto_rand.Reader)
if err != nil {
return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions example/codespaces/newusersecretwithxcrypto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"log"
"os"

"github.com/google/go-github/v65/github"
"github.com/google/go-github/v66/github"
"golang.org/x/crypto/nacl/box"
)

Expand Down Expand Up @@ -154,8 +154,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string,

var boxKey [32]byte
copy(boxKey[:], decodedPublicKey)
secretBytes := []byte(secretValue)
encryptedBytes, err := box.SealAnonymous([]byte{}, secretBytes, &boxKey, crypto_rand.Reader)
encryptedBytes, err := box.SealAnonymous([]byte{}, []byte(secretValue), &boxKey, crypto_rand.Reader)
if err != nil {
return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions example/commitpr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//
// Note, if you want to push a single file, you probably prefer to use the
// content API. An example is available here:
// https://godoc.org/github.com/google/go-github/github#example-RepositoriesService-CreateFile
// https://pkg.go.dev/github.com/google/go-github/github#example-RepositoriesService-CreateFile
//
// Note, for this to work at least 1 commit is needed, so you if you use this
// after creating a repository you might want to make sure you set `AutoInit` to
Expand All @@ -33,7 +33,7 @@ import (
"time"

"github.com/ProtonMail/go-crypto/openpgp"
"github.com/google/go-github/v65/github"
"github.com/google/go-github/v66/github"
)

var (
Expand Down Expand Up @@ -168,7 +168,7 @@ func pushCommit(ref *github.Reference, tree *github.Tree) (err error) {
return err
}

// createPR creates a pull request. Based on: https://godoc.org/github.com/google/go-github/github#example-PullRequestsService-Create
// createPR creates a pull request. Based on: https://pkg.go.dev/github.com/google/go-github/github#example-PullRequestsService-Create
func createPR() (err error) {
if *prSubject == "" {
return errors.New("missing `-pr-title` flag; skipping PR creation")
Expand Down
6 changes: 3 additions & 3 deletions example/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/google/go-github/v65/example
module github.com/google/go-github/v66/example

go 1.21

require (
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371
github.com/bradleyfalzon/ghinstallation/v2 v2.0.4
github.com/gofri/go-github-ratelimit v1.0.3
github.com/google/go-github/v65 v65.0.0
github.com/google/go-github/v66 v66.0.0
golang.org/x/crypto v0.21.0
golang.org/x/term v0.18.0
google.golang.org/appengine v1.6.7
Expand All @@ -24,4 +24,4 @@ require (
)

// Use version at HEAD, not the latest published.
replace github.com/google/go-github/v65 => ../
replace github.com/google/go-github/v66 => ../
2 changes: 1 addition & 1 deletion example/listenvironments/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"log"
"os"

"github.com/google/go-github/v65/github"
"github.com/google/go-github/v66/github"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion example/migrations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"context"
"fmt"

"github.com/google/go-github/v65/github"
"github.com/google/go-github/v66/github"
)

func fetchAllUserMigrations() ([]*github.UserMigration, error) {
Expand Down
Loading

0 comments on commit d45f521

Please sign in to comment.