Fixed API changes based on new dependencies

The "github.com/google/go-github/v87/github" has API shape changes, therefore a mere go.mod dependency update was inadequate; this PR adds necessary changes for feature parity and tests.

Co-authored-by: Ryan Richard <richardry@vmware.com>
Signed-off-by: Volkan Özçelik <volkan.ozcelik@broadcom.com>
This commit is contained in:
Volkan Özçelik
2026-06-23 15:10:39 -07:00
committed by Ryan Richard
parent 1ccfd13194
commit d14722396a
2 changed files with 27 additions and 13 deletions
+12 -2
View File
@@ -71,8 +71,18 @@ func NewGitHubClient(httpClient *http.Client, apiBaseURL, token string) (GitHubI
return nil, fmt.Errorf("%s: token cannot be empty string", errorPrefix)
}
client := github.NewClient(httpClient).WithAuthToken(token)
client.BaseURL = parsedURL
// go-github's WithEnterpriseURLs requires a non-empty upload URL even though
// Pinniped only calls read endpoints (Users.Get, Organizations.List,
// Teams.ListUserTeams), all of which use the base URL. The upload URL is never
// exercised today. It should be updated if an upload-style call is ever used.
client, err := github.NewClient(
github.WithHTTPClient(httpClient),
github.WithAuthToken(token),
github.WithEnterpriseURLs(parsedURL.String(), parsedURL.String()),
)
if err != nil {
return nil, fmt.Errorf("%s: %w", errorPrefix, err)
}
return &githubClient{
client: client,
+15 -11
View File
@@ -106,8 +106,8 @@ func TestNewGitHubClient(t *testing.T) {
require.NotNil(t, actualI)
actual, ok := actualI.(*githubClient)
require.True(t, ok)
require.NotNil(t, actual.client.BaseURL)
require.Equal(t, test.wantBaseURL, actual.client.BaseURL.String())
require.NotNil(t, actual.client)
require.Equal(t, test.wantBaseURL, actual.client.BaseURL())
// Force the githubClient's httpClient roundTrippers to run and add the Authorization header
@@ -227,9 +227,9 @@ func TestGetUser(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
githubClient := &githubClient{
client: github.NewClient(test.httpClient).WithAuthToken(test.token),
}
c, err := github.NewClient(github.WithHTTPClient(test.httpClient), github.WithAuthToken(test.token))
require.NoError(t, err)
githubClient := &githubClient{client: c}
ctx := context.Background()
if test.ctx != nil {
@@ -361,9 +361,9 @@ func TestGetOrgMembership(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
githubClient := &githubClient{
client: github.NewClient(test.httpClient).WithAuthToken(test.token),
}
c, err := github.NewClient(github.WithHTTPClient(test.httpClient), github.WithAuthToken(test.token))
require.NoError(t, err)
githubClient := &githubClient{client: c}
ctx := context.Background()
if test.ctx != nil {
@@ -700,6 +700,7 @@ func TestGetTeamMembership(t *testing.T) {
},
),
),
token: "fake-token",
wantErr: `error fetching team membership for authenticated user: missing the "organization" attribute for a team`,
},
{
@@ -716,6 +717,7 @@ func TestGetTeamMembership(t *testing.T) {
},
),
),
token: "fake-token",
wantErr: `error fetching team membership for authenticated user: missing the organization's "login" attribute for a team`,
},
{
@@ -733,6 +735,7 @@ func TestGetTeamMembership(t *testing.T) {
},
),
),
token: "fake-token",
wantErr: `error fetching team membership for authenticated user: the "name" attribute is missing for a team`,
},
{
@@ -750,6 +753,7 @@ func TestGetTeamMembership(t *testing.T) {
},
),
),
token: "fake-token",
wantErr: `error fetching team membership for authenticated user: the "slug" attribute is missing for a team`,
},
{
@@ -808,9 +812,9 @@ func TestGetTeamMembership(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
githubClient := &githubClient{
client: github.NewClient(test.httpClient).WithAuthToken(test.token),
}
c, err := github.NewClient(github.WithHTTPClient(test.httpClient), github.WithAuthToken(test.token))
require.NoError(t, err)
githubClient := &githubClient{client: c}
ctx := context.Background()
if test.ctx != nil {