Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/gofiber/contrib/v3/jwt v1.1.5
github.com/gofiber/fiber/v3 v3.3.0
github.com/golang-jwt/jwt/v5 v5.3.1
github.com/google/go-github/v85 v85.0.0
github.com/google/go-github/v88 v88.0.0
github.com/google/uuid v1.6.0
github.com/jackc/pgx/v5 v5.9.2
github.com/jferrl/go-githubauth v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
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/v85 v85.0.0 h1:1+TLFX/akTFXK7o9Z9uAloQGufOn4ySa5DItUM1VWT4=
github.com/google/go-github/v85 v85.0.0/go.mod h1:jYkBnqN+SzR2A2fGKYfbt6DEEQAyxeK0Q2XpPV9ZFsU=
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/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0=
Expand Down
6 changes: 5 additions & 1 deletion pkg/usecase/auth/github/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ func (o *OAuthHandler) Callback(c fiber.Ctx) error {
return c.SendStatus(fiber.StatusInternalServerError)
}

ghClient := gh.NewDefaultGithubClient(tokenResponse.AccessToken)
ghClient, err := gh.NewDefaultGithubClient(tokenResponse.AccessToken)
if err != nil {
log.Errorf("Failed to create github client: %v", err)
return c.SendStatus(fiber.StatusInternalServerError)
}
user, _, err := ghClient.Users.Get(c.Context(), "")
if err != nil {
log.Errorf("Failed to get user: %v", err)
Expand Down
6 changes: 5 additions & 1 deletion pkg/usecase/auth/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ func (h *ProfileHandler) GetLoggedUser(c fiber.Ctx) error {
return c.SendStatus(fiber.StatusInternalServerError)
}

ghClient := gh.NewDefaultGithubClient(dbUser.AccessToken)
ghClient, err := gh.NewDefaultGithubClient(dbUser.AccessToken)
if err != nil {
log.Error("error creating github client. ", err)
return c.SendStatus(fiber.StatusInternalServerError)
}
ghUser, _, err := ghClient.Users.Get(c.Context(), "")
if err != nil {
log.Error("error getting github user. ", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/usecase/sync/org/github/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"driftive.cloud/api/pkg/usecase/utils/parsing"
"errors"
"github.com/gofiber/fiber/v3/log"
"github.com/google/go-github/v85/github"
"github.com/google/go-github/v88/github"
"time"
)

Expand Down Expand Up @@ -152,7 +152,7 @@ func (so SyncOrganization) SyncInstallationIdByOrgId(ctx context.Context, orgId
return
}

installation, _, err := ghClient.Apps.FindOrganizationInstallation(ctx, org.Name)
installation, _, err := ghClient.Apps.GetOrganizationInstallation(ctx, org.Name)
if err != nil {
log.Error("error fetching installations for org: ", org.Name)
return
Expand Down
8 changes: 6 additions & 2 deletions pkg/usecase/sync/user_resources/github/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"errors"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/log"
"github.com/google/go-github/v85/github"
"github.com/google/go-github/v88/github"
"time"
)

Expand Down Expand Up @@ -48,7 +48,11 @@ func (s *UserResourceSyncer) SyncUserResources(ctx context.Context, userId int64
log.Errorf("error finding user by id: %v", err)
}

ghClient := gh.NewDefaultGithubClient(user.AccessToken)
ghClient, err := gh.NewDefaultGithubClient(user.AccessToken)
if err != nil {
log.Errorf("error creating github client: %v", err)
return err
}

var allOrgs []*github.Organization
opts := &github.ListOptions{PerPage: 100} // Fetch up to 100 orgs per page
Expand Down
20 changes: 8 additions & 12 deletions pkg/usecase/utils/gh/ghutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@ import (

"driftive.cloud/api/pkg/repository"
"github.com/gofiber/fiber/v3/log"
"github.com/google/go-github/v85/github"
"github.com/google/go-github/v88/github"
"github.com/jferrl/go-githubauth"
"golang.org/x/oauth2"
)

func NewDefaultGithubClient(token string) *github.Client {
func NewDefaultGithubClient(token string) (*github.Client, error) {
httpClient := http.Client{}
ghClient := github.NewClient(&httpClient)

opts := []github.ClientOptionsFunc{github.WithHTTPClient(&httpClient)}
if token != "" {
return ghClient.WithAuthToken(token)
opts = append(opts, github.WithAuthToken(token))
}

return ghClient
return github.NewClient(opts...)
}

func NewUserGithubClient(ctx context.Context, userId int64, usersRepository repository.UserRepository) (*github.Client, error) {
Expand All @@ -34,7 +32,7 @@ func NewUserGithubClient(ctx context.Context, userId int64, usersRepository repo
return nil, err
}

return NewDefaultGithubClient(user.AccessToken), nil
return NewDefaultGithubClient(user.AccessToken)
}

func NewAppGithubInstallationClient(ctx context.Context, installationId int64) (*github.Client, error) {
Expand All @@ -53,8 +51,7 @@ func NewAppGithubInstallationClient(ctx context.Context, installationId int64) (
installationTokenSource := githubauth.NewInstallationTokenSource(installationId, appTokenSource)

oauth2HttpClient := oauth2.NewClient(ctx, installationTokenSource)
ghClient := github.NewClient(oauth2HttpClient)
return ghClient, nil
return github.NewClient(github.WithHTTPClient(oauth2HttpClient))
}

func NewAppGithubClient(ctx context.Context) (*github.Client, error) {
Expand All @@ -71,8 +68,7 @@ func NewAppGithubClient(ctx context.Context) (*github.Client, error) {
}

oauth2HttpClient := oauth2.NewClient(ctx, appTokenSource)
ghClient := github.NewClient(oauth2HttpClient)
return ghClient, nil
return github.NewClient(github.WithHTTPClient(oauth2HttpClient))
}

func ParseOrgRole(role string) string {
Expand Down