From 39936074090785911b6207df91d6f384a7885703 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 23 May 2026 17:07:54 +0200 Subject: [PATCH] Update module github.com/google/go-github/v86 to v88 (#6626) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: qwerty287 --- go.mod | 2 +- go.sum | 4 +- server/forge/github/convert.go | 2 +- server/forge/github/convert_test.go | 2 +- server/forge/github/github.go | 101 +++++++++++++++++++++------- server/forge/github/github_test.go | 6 +- server/forge/github/parse.go | 2 +- 7 files changed, 86 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 6d307c83e..eea90f8dc 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/go-sql-driver/mysql v1.10.0 github.com/go-viper/mapstructure/v2 v2.5.0 github.com/golang-jwt/jwt/v5 v5.3.1 - github.com/google/go-github/v86 v86.0.0 + github.com/google/go-github/v88 v88.0.0 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-plugin v1.8.0 github.com/jellydator/ttlcache/v3 v3.4.0 diff --git a/go.sum b/go.sum index 8d2ecc689..11945d9b2 100644 --- a/go.sum +++ b/go.sum @@ -280,8 +280,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/go-github/v73 v73.0.0 h1:aR+Utnh+Y4mMkS+2qLQwcQ/cF9mOTpdwnzlaw//rG24= github.com/google/go-github/v73 v73.0.0/go.mod h1:fa6w8+/V+edSU0muqdhCVY7Beh1M8F1IlQPZIANKIYw= -github.com/google/go-github/v86 v86.0.0 h1:S/6aANJhwRm8EQmGKVML3j41yq0h2BsTP8FnDkO7kcA= -github.com/google/go-github/v86 v86.0.0/go.mod h1:zKv1l4SwDXNFMGByi2FWkq71KwSXqj/eQRZuqtmcot8= +github.com/google/go-github/v88 v88.0.0 h1:dZA9IKkPK1eXZj4ypngnpRj5FwdpTv4whix2PrQMP7M= +github.com/google/go-github/v88 v88.0.0/go.mod h1:rufTDgn2N45wjhukLTyxmvc9nilSp3mr3Rgtt6b1MPw= github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0= github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= diff --git a/server/forge/github/convert.go b/server/forge/github/convert.go index f12cb6359..2d6d30b06 100644 --- a/server/forge/github/convert.go +++ b/server/forge/github/convert.go @@ -18,7 +18,7 @@ package github import ( "fmt" - "github.com/google/go-github/v86/github" + "github.com/google/go-github/v88/github" "go.woodpecker-ci.org/woodpecker/v3/server/model" ) diff --git a/server/forge/github/convert_test.go b/server/forge/github/convert_test.go index 9d9806ed9..ef07c9bb0 100644 --- a/server/forge/github/convert_test.go +++ b/server/forge/github/convert_test.go @@ -18,7 +18,7 @@ package github import ( "testing" - "github.com/google/go-github/v86/github" + "github.com/google/go-github/v88/github" "github.com/stretchr/testify/assert" "go.woodpecker-ci.org/woodpecker/v3/server/model" diff --git a/server/forge/github/github.go b/server/forge/github/github.go index 5ac53ebba..b51ddec86 100644 --- a/server/forge/github/github.go +++ b/server/forge/github/github.go @@ -27,7 +27,7 @@ import ( "strings" "time" - "github.com/google/go-github/v86/github" + "github.com/google/go-github/v88/github" "github.com/rs/zerolog/log" "golang.org/x/oauth2" @@ -123,7 +123,11 @@ func (c *client) Login(ctx context.Context, req *forge_types.OAuthRequest) (*mod return nil, redirectURL, err } - client := c.newClientToken(ctx, token.AccessToken) + client, err := c.newClientToken(ctx, token.AccessToken) + if err != nil { + return nil, redirectURL, err + } + user, _, err := client.Users.Get(ctx, "") if err != nil { return nil, redirectURL, err @@ -178,7 +182,10 @@ func (c *client) Refresh(ctx context.Context, user *model.User) (bool, error) { // Teams returns a list of all team membership for the GitHub account. func (c *client) Teams(ctx context.Context, u *model.User, p *model.ListOptions) ([]*model.Team, error) { - client := c.newClientToken(ctx, u.AccessToken) + client, err := c.newClientToken(ctx, u.AccessToken) + if err != nil { + return nil, err + } list, _, err := client.Organizations.List(ctx, "", &github.ListOptions{ Page: p.Page, @@ -192,7 +199,10 @@ func (c *client) Teams(ctx context.Context, u *model.User, p *model.ListOptions) // Repo returns the GitHub repository. func (c *client) Repo(ctx context.Context, u *model.User, id model.ForgeRemoteID, owner, name string) (*model.Repo, error) { - client := c.newClientToken(ctx, u.AccessToken) + client, err := c.newClientToken(ctx, u.AccessToken) + if err != nil { + return nil, err + } if id.IsValid() { intID, err := strconv.ParseInt(string(id), 10, 64) @@ -227,7 +237,10 @@ func (c *client) Repos(ctx context.Context, u *model.User, p *model.ListOptions) return nil, nil } - client := c.newClientToken(ctx, u.AccessToken) + client, err := c.newClientToken(ctx, u.AccessToken) + if err != nil { + return nil, err + } opts := new(github.RepositoryListByAuthenticatedUserOptions) opts.PerPage = 100 @@ -252,7 +265,10 @@ func (c *client) Repos(ctx context.Context, u *model.User, p *model.ListOptions) // File fetches the file from the GitHub repository and returns its contents. func (c *client) File(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]byte, error) { - client := c.newClientToken(ctx, u.AccessToken) + client, err := c.newClientToken(ctx, u.AccessToken) + if err != nil { + return nil, err + } opts := new(github.RepositoryContentGetOptions) opts.Ref = b.Commit @@ -271,7 +287,10 @@ func (c *client) File(ctx context.Context, u *model.User, r *model.Repo, b *mode } func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*forge_types.FileMeta, error) { - client := c.newClientToken(ctx, u.AccessToken) + client, err := c.newClientToken(ctx, u.AccessToken) + if err != nil { + return nil, err + } opts := new(github.RepositoryContentGetOptions) opts.Ref = b.Commit @@ -322,7 +341,10 @@ func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, b *model func (c *client) PullRequests(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]*model.PullRequest, error) { token := common.UserToken(ctx, r, u) - client := c.newClientToken(ctx, token) + client, err := c.newClientToken(ctx, token) + if err != nil { + return nil, err + } pullRequests, _, err := client.PullRequests.List(ctx, r.Owner, r.Name, &github.PullRequestListOptions{ ListOptions: github.ListOptions{ @@ -373,7 +395,10 @@ func (c *client) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) { // Deactivate deactivates the repository be removing registered push hooks from // the GitHub repository. func (c *client) Deactivate(ctx context.Context, u *model.User, r *model.Repo, link string) error { - client := c.newClientToken(ctx, u.AccessToken) + client, err := c.newClientToken(ctx, u.AccessToken) + if err != nil { + return err + } // make sure a repo rename does not trick us forgeRepo, err := c.Repo(ctx, u, r.ForgeRemoteID, r.Owner, r.Name) @@ -396,7 +421,10 @@ func (c *client) Deactivate(ctx context.Context, u *model.User, r *model.Repo, l // OrgMembership returns if user is member of organization and if user // is admin/owner in this organization. func (c *client) OrgMembership(ctx context.Context, u *model.User, owner string) (*model.OrgPerm, error) { - client := c.newClientToken(ctx, u.AccessToken) + client, err := c.newClientToken(ctx, u.AccessToken) + if err != nil { + return nil, err + } org, _, err := client.Organizations.GetOrgMembership(ctx, u.Login, owner) if err != nil { return nil, err @@ -406,7 +434,10 @@ func (c *client) OrgMembership(ctx context.Context, u *model.User, owner string) } func (c *client) Org(ctx context.Context, u *model.User, owner string) (*model.Org, error) { - client := c.newClientToken(ctx, u.AccessToken) + client, err := c.newClientToken(ctx, u.AccessToken) + if err != nil { + return nil, err + } org, _, err := client.Organizations.Get(ctx, owner) log.Trace().Msgf("GitHub organization for owner %s = %v", owner, org) @@ -473,10 +504,10 @@ func (c *client) newConfig() *oauth2.Config { // newClientToken returns the GitHub oauth2 client. // It first checks if a client is available in the context, otherwise creates a new one. -func (c *client) newClientToken(ctx context.Context, token string) *github.Client { +func (c *client) newClientToken(ctx context.Context, token string) (*github.Client, error) { // Check if a client is already in the context if ctxClient, ok := ctx.Value(githubClientKey).(*github.Client); ok { - return ctxClient + return ctxClient, nil } ts := oauth2.StaticTokenSource( @@ -499,9 +530,7 @@ func (c *client) newClientToken(ctx context.Context, token string) *github.Clien // Wrap the base transport with User-Agent support tp.Base = httputil.NewUserAgentRoundTripper(baseTransport, "forge-github") - client := github.NewClient(tc) - client.BaseURL, _ = url.Parse(c.API) - return client + return github.NewClient(github.WithURLs(github.Ptr(c.API), nil), github.WithHTTPClient(tc)) } // matchingEmail returns matching user email. @@ -545,7 +574,10 @@ var reDeploy = regexp.MustCompile(`.+/deployments/(\d+)`) // Status sends the commit status to the forge. // An example would be the GitHub pull request status. func (c *client) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, workflow *model.Workflow) error { - client := c.newClientToken(ctx, user.AccessToken) + client, err := c.newClientToken(ctx, user.AccessToken) + if err != nil { + return err + } if pipeline.Event == model.EventDeploy { // Get id from url. If not found, skip. @@ -564,7 +596,7 @@ func (c *client) Status(ctx context.Context, user *model.User, repo *model.Repo, return err } - _, _, err := client.Repositories.CreateStatus(ctx, repo.Owner, repo.Name, pipeline.Commit, github.RepoStatus{ + _, _, err = client.Repositories.CreateStatus(ctx, repo.Owner, repo.Name, pipeline.Commit, github.RepoStatus{ Context: github.Ptr(common.GetPipelineStatusContext(repo, pipeline, workflow)), State: github.Ptr(convertStatus(workflow.State)), Description: github.Ptr(common.GetPipelineStatusDescription(workflow.State)), @@ -579,7 +611,10 @@ func (c *client) Activate(ctx context.Context, u *model.User, r *model.Repo, lin if err := c.Deactivate(ctx, u, r, link); err != nil { return err } - client := c.newClientToken(ctx, u.AccessToken) + client, err := c.newClientToken(ctx, u.AccessToken) + if err != nil { + return err + } hook := &github.Hook{ Name: github.Ptr("web"), Events: []string{ @@ -593,14 +628,17 @@ func (c *client) Activate(ctx context.Context, u *model.User, r *model.Repo, lin ContentType: github.Ptr("form"), }, } - _, _, err := client.Repositories.CreateHook(ctx, r.Owner, r.Name, hook) + _, _, err = client.Repositories.CreateHook(ctx, r.Owner, r.Name, hook) return err } // Branches returns the names of all branches for the named repository. func (c *client) Branches(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]string, error) { token := common.UserToken(ctx, r, u) - client := c.newClientToken(ctx, token) + client, err := c.newClientToken(ctx, token) + if err != nil { + return nil, err + } githubBranches, _, err := client.Repositories.ListBranches(ctx, r.Owner, r.Name, &github.BranchListOptions{ ListOptions: github.ListOptions{ @@ -622,7 +660,11 @@ func (c *client) Branches(ctx context.Context, u *model.User, r *model.Repo, p * // BranchHead returns the sha of the head (latest commit) of the specified branch. func (c *client) BranchHead(ctx context.Context, u *model.User, r *model.Repo, branch string) (*model.Commit, error) { token := common.UserToken(ctx, r, u) - b, _, err := c.newClientToken(ctx, token).Repositories.GetBranch(ctx, r.Owner, r.Name, branch, 1) + client, err := c.newClientToken(ctx, token) + if err != nil { + return nil, err + } + b, _, err := client.Repositories.GetBranch(ctx, r.Owner, r.Name, branch, 1) if err != nil { return nil, err } @@ -687,7 +729,10 @@ func (c *client) loadChangedFilesFromPullRequest(ctx context.Context, pull *gith // would fail with an authentication error. forge.Refresh(ctx, c, _store, user) - gh := c.newClientToken(ctx, user.AccessToken) + gh, err := c.newClientToken(ctx, user.AccessToken) + if err != nil { + return nil, err + } fileList := make([]string, 0, 16) opts := &github.ListOptions{Page: 1} @@ -730,7 +775,10 @@ func (c *client) getTagCommitSHA(ctx context.Context, repo *model.Repo, tagName // would fail with an authentication error. forge.Refresh(ctx, c, _store, user) - gh := c.newClientToken(ctx, user.AccessToken) + gh, err := c.newClientToken(ctx, user.AccessToken) + if err != nil { + return "", err + } page := 1 var tag *github.RepositoryTag @@ -790,7 +838,10 @@ func (c *client) loadChangedFilesFromCommits(ctx context.Context, tmpRepo *model // would fail with an authentication error. forge.Refresh(ctx, c, _store, user) - gh := c.newClientToken(ctx, user.AccessToken) + gh, err := c.newClientToken(ctx, user.AccessToken) + if err != nil { + return nil, err + } fileList := make([]string, 0, 16) if prev == "" { diff --git a/server/forge/github/github_test.go b/server/forge/github/github_test.go index aa7d61d6c..955279384 100644 --- a/server/forge/github/github_test.go +++ b/server/forge/github/github_test.go @@ -22,10 +22,11 @@ import ( "testing" "github.com/gin-gonic/gin" - "github.com/google/go-github/v86/github" + "github.com/google/go-github/v88/github" github_mock "github.com/migueleliasweb/go-github-mock/src/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" "go.woodpecker-ci.org/woodpecker/v3/server/forge/github/fixtures" "go.woodpecker-ci.org/woodpecker/v3/server/model" @@ -148,7 +149,8 @@ func TestHook(t *testing.T) { ) // Create a GitHub client with the mocked HTTP client - gh := github.NewClient(mockedHTTPClient) + gh, err := github.NewClient(github.WithHTTPClient(mockedHTTPClient)) + require.NoError(t, err) // Use the custom type as the key ctx := context.WithValue(context.Background(), githubClientKey, gh) diff --git a/server/forge/github/parse.go b/server/forge/github/parse.go index e0e1b633a..0040b9db0 100644 --- a/server/forge/github/parse.go +++ b/server/forge/github/parse.go @@ -22,7 +22,7 @@ import ( "net/http" "strings" - "github.com/google/go-github/v86/github" + "github.com/google/go-github/v88/github" "go.woodpecker-ci.org/woodpecker/v3/server/forge/common" "go.woodpecker-ci.org/woodpecker/v3/server/forge/types"