Skip to content

Commit

Permalink
use common provider for fetching gitlab client (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
motatoes authored Jul 24, 2024
1 parent 5ed838a commit b0838f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions backend/utils/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (
)

type GitlabProvider interface {
NewClient(token string, baseUrl string) (*gitlab.Client, error)
NewClient(token string) (*gitlab.Client, error)
}

type GitlabClientProvider struct{}

func (g GitlabClientProvider) NewClient(token string, baseUrl string) (*gitlab.Client, error) {
func (g GitlabClientProvider) NewClient(token string) (*gitlab.Client, error) {
baseUrl := os.Getenv("DIGGER_GITLAB_BASE_URL")
if baseUrl == "" {
client, err := gitlab.NewClient(token)
return client, err
Expand All @@ -29,9 +30,8 @@ func (g GitlabClientProvider) NewClient(token string, baseUrl string) (*gitlab.C

func GetGitlabService(gh GitlabProvider, projectId int, repoName string, repoFullName string, prNumber int, discussionId string) (*orchestrator_gitlab.GitLabService, error) {
token := os.Getenv("DIGGER_GITLAB_ACCESS_TOKEN")
baseUrl := os.Getenv("DIGGER_GITLAB_BASE_URL")

client, err := gh.NewClient(token, baseUrl)
client, err := gh.NewClient(token)
if err != nil {
return nil, fmt.Errorf("could not get gitlab client: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions ee/backend/ci_backends/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"github.com/buildkite/go-buildkite/v3/buildkite"
"github.com/diggerhq/digger/backend/ci_backends"
"github.com/xanzy/go-gitlab"
"github.com/diggerhq/digger/backend/utils"
"log"
"os"
)
Expand All @@ -21,7 +21,7 @@ func (b EEBackendProvider) GetCiBackend(options ci_backends.CiBackendOptions) (c
if token == "" {
return nil, fmt.Errorf("missing environment variable: DIGGER_GITLAB_ACCESS_TOKEN")
}
client, err := gitlab.NewClient(token)
client, err := utils.GitlabClientProvider{}.NewClient(token)
if err != nil {
return nil, fmt.Errorf("could not create gitlab client: %v", err)
}
Expand Down

0 comments on commit b0838f2

Please sign in to comment.