Skip to content

Commit

Permalink
Merge branch 'master' into issue2929
Browse files Browse the repository at this point in the history
  • Loading branch information
vandanrohatgi authored Sep 15, 2023
2 parents 69cd54d + fd33b81 commit 6e2589e
Show file tree
Hide file tree
Showing 143 changed files with 4,961 additions and 3,174 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ jobs:
lint:
strategy:
matrix:
go-version: [1.x]
platform: [ubuntu-latest]

# golangci-lint will only process a single module, so we need to call it
# separately for each module in the repo. We dont lint example/newreposecretwithlibsodium
# since that needs libsodium to run.
working-directory:
- ""
# - example # Fails with "no go files to analyze"
- example
- scrape
- update-urls
runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: golangci-lint ${{ matrix.working-directory }}
uses: golangci/golangci-lint-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Get values for cache paths to be used in later steps
- id: cache-paths
Expand Down
49 changes: 27 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
run:
build-tags:
- integration
linters:
# TODO: fix errors so that all of the linters below pass.
# The linters that are commented out, as well as those explicitly disabled,
# are currently failing. We should fix those failures or define exclusion
# rules, and then enable those linters.
enable:
- dogsled
- dupl
- gofmt
- goimports
# - gosec
- gosec
- misspell
- nakedret
- stylecheck
# - unconvert
# - unparam
- unconvert
- unparam
- whitespace
disable:
- errcheck
- gosimple
- staticcheck
- ineffassign
- unused
linters-settings:
gosec:
excludes:
# performance issue: see https://github.com/golangci/golangci-lint/issues/4039
# and https://github.com/securego/gosec/issues/1007
- G602
issues:
exclude:
- composites
exclude-rules:
- linters:
- dogsled
text: "declaration has 3 blank identifiers"
path: _test\.go
- linters:
- dupl
path: _test\.go
- linters:
- dupl
- unparam
- gosec
- dogsled
path: _test\.go

# We need to pass nil Context in order to test DoBare erroring on nil ctx.
- linters: [ staticcheck ]
text: 'SA1012: do not pass a nil Context'
path: _test\.go

# We need to use sha1 for validating signatures
- linters: [ gosec ]
text: 'G505: Blocklisted import crypto/sha1: weak cryptographic primitive'
58 changes: 16 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/v54/github)
[![GoDoc](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/github.com/google/go-github/v55/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)
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/v54
go get github.com/google/go-github/v55
```

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

## Usage ##

```go
import "github.com/google/go-github/v54/github" // with go modules enabled (GO111MODULE=on or outside GOPATH)
import "github.com/google/go-github/v55/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 @@ -84,36 +84,18 @@ For more sample code snippets, head over to the

### Authentication ###

The go-github library does not directly handle authentication. Instead, when
creating a new client, pass an `http.Client` that can handle authentication for
you. The easiest and recommended way to do this is using the [oauth2][]
library, but you can always use any other library that provides an
`http.Client`. If you have an OAuth2 access token (for example, a [personal
API token][]), you can use it with the oauth2 library using:
Use the `WithAuthToken` method to configure your client to authenticate using an
OAuth token (for example, a [personal access token][]). This is what is needed
for a majority of use cases aside from GitHub Apps.

```go
import "golang.org/x/oauth2"

func main() {
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: "... your access token ..."},
)
tc := oauth2.NewClient(ctx, ts)

client := github.NewClient(tc)

// list all repositories for the authenticated user
repos, _, err := client.Repositories.List(ctx, "", nil)
}
client := github.NewClient(nil).WithAuthToken("... your access token ...")
```

Note that when using an authenticated Client, all calls made by the client will
include the specified OAuth token. Therefore, authenticated clients should
almost never be shared between different users.

See the [oauth2 docs][] for complete instructions on using that library.

For API methods that require HTTP Basic Authentication, use the
[`BasicAuthTransport`](https://godoc.org/github.com/google/go-github/github#BasicAuthTransport).

Expand All @@ -135,7 +117,7 @@ import (
"net/http"

"github.com/bradleyfalzon/ghinstallation/v2"
"github.com/google/go-github/v54/github"
"github.com/google/go-github/v55/github"
)

func main() {
Expand Down Expand Up @@ -232,16 +214,9 @@ 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)
client := github.NewClient(
httpcache.NewMemoryCacheTransport().Client()
).WithAuthToken(os.Getenv("GITHUB_TOKEN"))
```

Learn more about GitHub conditional requests at
Expand Down Expand Up @@ -320,10 +295,8 @@ Furthermore, there are libraries like [cbrgm/githubevents][] that build upon the
For complete usage of go-github, see the full [package docs][].

[GitHub API v3]: https://docs.github.com/en/rest
[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/v54/github
[personal access token]: https://github.com/blog/1509-personal-api-tokens
[package docs]: https://pkg.go.dev/github.com/google/go-github/v55/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 @@ -396,6 +369,7 @@ Versions prior to 48.2.0 are not listed.

| go-github Version | GitHub v3 API Version |
| ----------------- | --------------------- |
| 55.0.0 | 2022-11-28 |
| 54.0.0 | 2022-11-28 |
| 53.2.0 | 2022-11-28 |
| 53.1.0 | 2022-11-28 |
Expand Down
4 changes: 2 additions & 2 deletions 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/v54/github"
"github.com/google/go-github/v55/github"
)

var (
Expand All @@ -35,7 +35,7 @@ func main() {
log.Fatal("No owner: owner of repo must be given")
}
ctx := context.Background()
client := github.NewTokenClient(ctx, token)
client := github.NewClient(nil).WithAuthToken(token)

actionsPermissionsRepository, _, err := client.Repositories.GetActionsPermissions(ctx, *owner, *name)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions 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/v54/github"
"github.com/google/go-github/v55/github"
"google.golang.org/appengine"
"google.golang.org/appengine/log"
)
Expand All @@ -28,7 +28,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
}

ctx := appengine.NewContext(r)
client := github.NewTokenClient(ctx, os.Getenv("GITHUB_AUTH_TOKEN"))
client := github.NewClient(nil).WithAuthToken(os.Getenv("GITHUB_AUTH_TOKEN"))

commits, _, err := client.Repositories.ListCommits(ctx, "google", "go-github", nil)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions example/basicauth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"
"syscall"

"github.com/google/go-github/v54/github"
"github.com/google/go-github/v55/github"
"golang.org/x/term"
)

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

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

tp := github.BasicAuthTransport{
Expand Down
4 changes: 2 additions & 2 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/v54/github"
"github.com/google/go-github/v55/github"
"golang.org/x/crypto/nacl/box"
)

Expand Down Expand Up @@ -72,7 +72,7 @@ func main() {
}

ctx := context.Background()
client := github.NewTokenClient(ctx, token)
client := github.NewClient(nil).WithAuthToken(token)

if err := addRepoSecret(ctx, client, *owner, *repo, secretName, secretValue); err != nil {
log.Fatal(err)
Expand Down
4 changes: 2 additions & 2 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/v54/github"
"github.com/google/go-github/v55/github"
"golang.org/x/crypto/nacl/box"
)

Expand Down Expand Up @@ -65,7 +65,7 @@ func main() {
}

ctx := context.Background()
client := github.NewTokenClient(ctx, token)
client := github.NewClient(nil).WithAuthToken(token)

if err := addUserSecret(ctx, client, secretName, secretValue, *owner, *repo); err != nil {
log.Fatal(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 @@ -30,7 +30,7 @@ import (
"strings"
"time"

"github.com/google/go-github/v54/github"
"github.com/google/go-github/v55/github"
)

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

// Create the commit using the tree.
date := time.Now()
author := &github.CommitAuthor{Date: &github.Timestamp{date}, Name: authorName, Email: authorEmail}
author := &github.CommitAuthor{Date: &github.Timestamp{Time: 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 @@ -189,7 +189,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`")
}
client = github.NewTokenClient(ctx, token)
client = github.NewClient(nil).WithAuthToken(token)

ref, err := getRef()
if err != nil {
Expand Down
18 changes: 10 additions & 8 deletions example/go.mod
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
module github.com/google/go-github/v54/example
module github.com/google/go-github/v55/example

go 1.17

require (
github.com/bradleyfalzon/ghinstallation/v2 v2.0.4
github.com/gofri/go-github-ratelimit v1.0.3
github.com/google/go-github/v54 v54.0.0
golang.org/x/crypto v0.7.0
golang.org/x/oauth2 v0.7.0
github.com/google/go-github/v55 v55.0.0
golang.org/x/crypto v0.12.0
golang.org/x/term v0.11.0
google.golang.org/appengine v1.6.7
)

require (
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-github/v41 v41.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.11.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
)

// Use version at HEAD, not the latest published.
replace github.com/google/go-github/v54 => ../
replace github.com/google/go-github/v55 => ../
Loading

0 comments on commit 6e2589e

Please sign in to comment.