Skip to content

Commit

Permalink
Merge branch 'google:master' into google#2579
Browse files Browse the repository at this point in the history
  • Loading branch information
XaurDesu committed Jan 31, 2023
2 parents e1f29fe + da244a4 commit b0f971d
Show file tree
Hide file tree
Showing 123 changed files with 4,096 additions and 767 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Expand Up @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v3

- name: golangci-lint ${{ matrix.working-directory }}
uses: golangci/golangci-lint-action@0ad9a0988b3973e851ab0a07adf248ec2e100376 #v3.3.1
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 #v3.4.0
with:
version: v1.50.1
working-directory: ${{ matrix.working-directory}}
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/tests.yml
@@ -1,3 +1,7 @@
concurrency:
group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
push:
branches:
Expand All @@ -15,9 +19,6 @@ permissions:

jobs:
test:
permissions:
actions: write # for styfle/cancel-workflow-action to cancel/stop running workflows
contents: read # for actions/checkout to fetch code
strategy:
matrix:
go-version: [1.x, 1.18.x]
Expand All @@ -35,11 +36,6 @@ jobs:
runs-on: ${{ matrix.platform }}

steps:
- name: Cancel previous
uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 #0.11.0
with:
access_token: ${{ github.token }}

- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
Expand Down
4 changes: 3 additions & 1 deletion .golangci.yml
Expand Up @@ -21,7 +21,9 @@ linters:
- staticcheck
- ineffassign
- unused
issues:
issues:
exclude:
- composites
exclude-rules:
- linters:
- dogsled
Expand Down
6 changes: 6 additions & 0 deletions AUTHORS
Expand Up @@ -152,6 +152,7 @@ Florian Wagner <h2floh@github.com>
Francesc Gil <xescugil@gmail.com>
Francis <hello@francismakes.com>
Francisco Guimarães <francisco.cpg@gmail.com>
François de Metz <francois@2metz.fr>
Fredrik Jönsson <fredrik.jonsson@izettle.com>
Gabriel <samfiragabriel@gmail.com>
Garrett Squire <garrettsquire@gmail.com>
Expand Down Expand Up @@ -261,6 +262,7 @@ Martins Sipenko <martins.sipenko@gmail.com>
Marwan Sulaiman <marwan.sameer@gmail.com>
Masayuki Izumi <m@izum.in>
Mat Geist <matgeist@gmail.com>
Matija Horvat <horvat2112@gmail.com>
Matin Rahmanian <itsmatinx@gmail.com>
Matt <alpmatthew@gmail.com>
Matt Brender <mjbrender@gmail.com>
Expand All @@ -274,6 +276,7 @@ Michael Tiller <michael.tiller@gmail.com>
Michał Glapa <michal.glapa@gmail.com>
Michelangelo Morrillo <michelangelo@morrillo.it>
Miguel Elias dos Santos <migueleliasweb@gmail.com>
Mike Chen <mchen300@gmail.com>
Mohammed AlDujaili <avainer11@gmail.com>
Mukundan Senthil <mukundan314@gmail.com>
Munia Balayil <munia.247@gmail.com>
Expand Down Expand Up @@ -304,6 +307,7 @@ parkhyukjun89 <park.hyukjun89@gmail.com>
Pat Alwell <pat.alwell@gmail.com>
Patrick DeVivo <patrick.devivo@gmail.com>
Patrick Marabeas <patrick@marabeas.io>
Pavel Dvoinos <pavel.dvoinos@transferwise.com>
Pavel Shtanko <pavel.shtanko@gmail.com>
Pete Wagner <thepwagner@github.com>
Petr Shevtsov <petr.shevtsov@gmail.com>
Expand Down Expand Up @@ -359,6 +363,7 @@ Sasha Melentyev <sasha@melentyev.io>
Sean Wang <sean@decrypted.org>
Sebastian Mandrean <sebastian.mandrean@gmail.com>
Sebastian Mæland Pedersen <sem.pedersen@stud.uis.no>
Sergei Popinevskii <gurza000@gmail.com>
Sergey Romanov <xxsmotur@gmail.com>
Sergio Garcia <sergio.garcia@gmail.com>
Seth Vargo <seth@sethvargo.com>
Expand Down Expand Up @@ -399,6 +404,7 @@ tkhandel <tarunkhandelwal.iitr@gmail.com>
Tobias Gesellchen <tobias@gesellix.de>
Tom Payne <twpayne@gmail.com>
Trey Tacon <ttacon@gmail.com>
tsbkw <tsbkw0@gmail.com>
ttacon <ttacon@gmail.com>
Vaibhav Singh <vaibhav.singh.14cse@bml.edu.in>
Varadarajan Aravamudhan <varadaraajan@gmail.com>
Expand Down
85 changes: 77 additions & 8 deletions README.md
@@ -1,7 +1,7 @@
# 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/v48/github)
[![GoDoc](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/github.com/google/go-github/v50/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)
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/v48
go get github.com/google/go-github/v50
```

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/v48/github"
import "github.com/google/go-github/v50/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/v48@master
go get github.com/google/go-github/v50@master
```

## Usage ##

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

Expand Down Expand Up @@ -135,7 +135,7 @@ import (
"net/http"

"github.com/bradleyfalzon/ghinstallation/v2"
"github.com/google/go-github/v48/github"
"github.com/google/go-github/v50/github"
)

func main() {
Expand Down Expand Up @@ -186,6 +186,24 @@ if _, ok := err.(*github.RateLimitError); ok {
Learn more about GitHub rate limiting at
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.

To detect an API secondary rate limit error, you can check if its type is `*github.AbuseRateLimitError`:

```go
repos, _, err := client.Repositories.List(ctx, "", nil)
if _, ok := err.(*github.AbuseRateLimitError); ok {
log.Println("hit secondary rate limit")
}
```

You can use [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/overview/resources-in-the-rest-api#secondary-rate-limits .

### Accepted Status ###

Some endpoints may return a 202 Accepted status code, meaning that the
Expand All @@ -209,7 +227,22 @@ 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.
https://github.com/gregjones/httpcache for that. For example:

```go
import "github.com/gregjones/httpcache"

ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
)
tc := &http.Client{
Transport: &oauth2.Transport{
Base: httpcache.NewMemoryCacheTransport(),
Source: ts,
},
}
client := github.NewClient(tc)
```

Learn more about GitHub conditional requests at
https://docs.github.com/en/rest/overview/resources-in-the-rest-api#conditional-requests.
Expand Down Expand Up @@ -290,7 +323,7 @@ For complete usage of go-github, see the full [package docs][].
[oauth2]: https://github.com/golang/oauth2
[oauth2 docs]: https://godoc.org/golang.org/x/oauth2
[personal API token]: https://github.com/blog/1509-personal-api-tokens
[package docs]: https://pkg.go.dev/github.com/google/go-github/v48/github
[package docs]: https://pkg.go.dev/github.com/google/go-github/v50/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
Expand Down Expand Up @@ -332,6 +365,42 @@ Preview functionality may take the form of entire methods or simply additional
data returned from an otherwise non-preview method. Refer to the GitHub API
documentation for details on preview functionality.

### Calendar Versioning ###

As of 2022-11-28, GitHub [has announced](https://github.blog/2022-11-28-to-infinity-and-beyond-enabling-the-future-of-githubs-rest-api-with-api-versioning/)
that they are starting to version their v3 API based on "calendar-versioning".

In practice, our goal is to make per-method version overrides (at
least in the core library) rare and temporary.

Our understanding of the GitHub docs is that they will be revving the
entire API to each new date-based version, even if only a few methods
have breaking changes. Other methods will accept the new version with
their existing functionality. So when a new date-based version of the
GitHub API is released, we (the repo maintainers) plan to:

* update each method that had breaking changes, overriding their
per-method API version header. This may happen in one or multiple
commits and PRs, and is all done in the main branch.

* once all of the methods with breaking changes have been updated,
have a final commit that bumps the default API version, and remove
all of the per-method overrides. That would now get a major version
bump when the next go-github release is made.

### Version Compatibility Table ###

The following table identifies which version of the GitHub API is
supported by this (and past) versions of this repo (go-github).
Versions prior to 48.2.0 are not listed.

| go-github Version | GitHub v3 API Version |
| ----------------- | --------------------- |
| 50.0.0 | 2022-11-28 |
| 49.1.0 | 2022-11-28 |
| 49.0.0 | 2022-11-28 |
| 48.2.0 | 2022-11-28 |

## License ##

This library is distributed under the BSD-style license found in the [LICENSE](./LICENSE)
Expand Down
7 changes: 2 additions & 5 deletions example/actionpermissions/main.go
Expand Up @@ -14,8 +14,7 @@ import (
"log"
"os"

"github.com/google/go-github/v48/github"
"golang.org/x/oauth2"
"github.com/google/go-github/v50/github"
)

var (
Expand All @@ -36,9 +35,7 @@ func main() {
log.Fatal("No owner: owner of repo must be given")
}
ctx := context.Background()
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
client := github.NewTokenClient(ctx, token)

actionsPermissionsRepository, _, err := client.Repositories.GetActionsPermissions(ctx, *owner, *name)
if err != nil {
Expand Down
9 changes: 2 additions & 7 deletions example/appengine/app.go
Expand Up @@ -12,8 +12,7 @@ import (
"net/http"
"os"

"github.com/google/go-github/v48/github"
"golang.org/x/oauth2"
"github.com/google/go-github/v50/github"
"google.golang.org/appengine"
"google.golang.org/appengine/log"
)
Expand All @@ -29,11 +28,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
}

ctx := appengine.NewContext(r)
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_AUTH_TOKEN")},
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
client := github.NewTokenClient(ctx, os.Getenv("GITHUB_AUTH_TOKEN"))

commits, _, err := client.Repositories.ListCommits(ctx, "google", "go-github", nil)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion example/basicauth/main.go
Expand Up @@ -22,7 +22,7 @@ import (
"strings"
"syscall"

"github.com/google/go-github/v48/github"
"github.com/google/go-github/v50/github"
"golang.org/x/crypto/ssh/terminal"
)

Expand Down
9 changes: 3 additions & 6 deletions example/commitpr/main.go
Expand Up @@ -30,8 +30,7 @@ import (
"strings"
"time"

"github.com/google/go-github/v48/github"
"golang.org/x/oauth2"
"github.com/google/go-github/v50/github"
)

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

// Create the commit using the tree.
date := time.Now()
author := &github.CommitAuthor{Date: &date, Name: authorName, Email: authorEmail}
author := &github.CommitAuthor{Date: &github.Timestamp{date}, Name: authorName, Email: authorEmail}
commit := &github.Commit{Author: author, Message: commitMessage, Tree: tree, Parents: []*github.Commit{parent.Commit}}
newCommit, _, err := client.Git.CreateCommit(ctx, *sourceOwner, *sourceRepo, commit)
if err != nil {
Expand Down Expand Up @@ -188,9 +187,7 @@ func main() {
if *sourceOwner == "" || *sourceRepo == "" || *commitBranch == "" || *sourceFiles == "" || *authorName == "" || *authorEmail == "" {
log.Fatal("You need to specify a non-empty value for the flags `-source-owner`, `-source-repo`, `-commit-branch`, `-files`, `-author-name` and `-author-email`")
}
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
tc := oauth2.NewClient(ctx, ts)
client = github.NewClient(tc)
client = github.NewTokenClient(ctx, token)

ref, err := getRef()
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions example/go.mod
@@ -1,10 +1,11 @@
module github.com/google/go-github/v48/example
module github.com/google/go-github/v50/example

go 1.17

require (
github.com/bradleyfalzon/ghinstallation/v2 v2.0.4
github.com/google/go-github/v48 v48.0.0
github.com/gofri/go-github-ratelimit v1.0.1
github.com/google/go-github/v50 v50.0.0
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
google.golang.org/appengine v1.6.7
Expand All @@ -21,4 +22,4 @@ require (
)

// Use version at HEAD, not the latest published.
replace github.com/google/go-github/v48 => ../
replace github.com/google/go-github/v50 => ../
6 changes: 4 additions & 2 deletions example/go.sum
@@ -1,14 +1,16 @@
github.com/bradleyfalzon/ghinstallation/v2 v2.0.4 h1:tXKVfhE7FcSkhkv0UwkLvPDeZ4kz6OXd0PKPlFqf81M=
github.com/bradleyfalzon/ghinstallation/v2 v2.0.4/go.mod h1:B40qPqJxWE0jDZgOR1JmaMy+4AY1eBP+IByOvqyAKp0=
github.com/gofri/go-github-ratelimit v1.0.1 h1:sgefSzxhnvwZ+wR9uZ4l9TnjgLuNiwipJVzJL4YLj9A=
github.com/gofri/go-github-ratelimit v1.0.1/go.mod h1:OnCi5gV+hAG/LMR7llGhU7yHt44se9sYgKPnafoL7RY=
github.com/golang-jwt/jwt/v4 v4.0.0 h1:RAqyYixv1p7uEnocuy8P1nru5wprCh/MH2BIlW5z5/o=
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v41 v41.0.0 h1:HseJrM2JFf2vfiZJ8anY2hqBjdfY1Vlj/K27ueww4gg=
github.com/google/go-github/v41 v41.0.0/go.mod h1:XgmCA5H323A9rtgExdTcnDkcqp6S30AVACCBDOonIxg=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
Expand Down
8 changes: 2 additions & 6 deletions example/listenvironments/main.go
Expand Up @@ -18,8 +18,7 @@ import (
"log"
"os"

"github.com/google/go-github/v48/github"
"golang.org/x/oauth2"
"github.com/google/go-github/v50/github"
)

func main() {
Expand All @@ -31,11 +30,8 @@ func main() {
log.Fatal("Unauthorized: No token present")
}

ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})

ctx := context.Background()
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
client := github.NewTokenClient(ctx, token)

expectedPageSize := 2

Expand Down

0 comments on commit b0f971d

Please sign in to comment.