diff --git a/scm/github/app_transport.go b/scm/github/app_transport.go index c7c68a3b7..d005fb420 100644 --- a/scm/github/app_transport.go +++ b/scm/github/app_transport.go @@ -28,7 +28,6 @@ import ( const ( acceptHeader = "application/vnd.github.v3+json" - apiBaseURL = "https://api.github.com" ) // AppsTransport provides a http.RoundTripper by wrapping an existing @@ -58,12 +57,12 @@ func (c *client) newGitHubAppTransport(appID int64, privateKey, baseURL string) return nil, fmt.Errorf("failed to parse PEM block containing the key") } - _privateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes) + parsedPrivateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { return nil, fmt.Errorf("failed to parse RSA private key: %w", err) } - transport := c.newAppsTransportFromPrivateKey(http.DefaultTransport, appID, _privateKey) + transport := c.newAppsTransportFromPrivateKey(http.DefaultTransport, appID, parsedPrivateKey) transport.BaseURL = baseURL // apply tracing to the transport @@ -82,7 +81,7 @@ func (c *client) newGitHubAppTransport(appID int64, privateKey, baseURL string) // newAppsTransportFromPrivateKey returns an AppsTransport using a crypto/rsa.(*PrivateKey). func (c *client) newAppsTransportFromPrivateKey(tr http.RoundTripper, appID int64, key *rsa.PrivateKey) *AppsTransport { return &AppsTransport{ - BaseURL: apiBaseURL, + BaseURL: defaultAPI, Client: &http.Client{Transport: tr}, tr: tr, signer: NewRSASigner(jwt.SigningMethodRS256, key), diff --git a/scm/github/repo.go b/scm/github/repo.go index f6ad559b2..f6b84f1fd 100644 --- a/scm/github/repo.go +++ b/scm/github/repo.go @@ -720,7 +720,7 @@ func (c *client) GetNetrcPassword(ctx context.Context, r *api.Repo, u *api.User, } for resource, perm := range perms { - ghPerms, err = WithGitHubInstallationPermission(ghPerms, resource, perm) + ghPerms, err = applyGitHubInstallationPermission(ghPerms, resource, perm) if err != nil { l.Errorf("unable to create github app installation token with permission %s:%s: %v", resource, perm, err) @@ -817,8 +817,8 @@ func (c *client) SyncRepoWithInstallation(ctx context.Context, r *api.Repo) (*ap return r, nil } -// WithGitHubInstallationPermission takes permissions and applies a new permission if valid. -func WithGitHubInstallationPermission(perms *github.InstallationPermissions, resource, perm string) (*github.InstallationPermissions, error) { +// applyGitHubInstallationPermission takes permissions and applies a new permission if valid. +func applyGitHubInstallationPermission(perms *github.InstallationPermissions, resource, perm string) (*github.InstallationPermissions, error) { // convert permissions from yaml string switch strings.ToLower(perm) { case constants.AppInstallPermissionNone: