Skip to content

Commit

Permalink
fix the error calling cli (#1585)
Browse files Browse the repository at this point in the history
* fix the error calling cli

* fix build
  • Loading branch information
motatoes authored Jun 20, 2024
1 parent db110f1 commit 353215e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cli/cmd/digger/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (r *RunConfig) GetServices() (*orchestrator.PullRequestService, *orchestrat
switch r.Reporter {
case "github":
repoOwner, repositoryName := utils.ParseRepoNamespace(r.RepoNamespace)
prService = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, repositoryName, repoOwner)
orgService = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, r.RepoNamespace, r.Actor)
prService, _ = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, repositoryName, repoOwner)
orgService, _ = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, r.RepoNamespace, r.Actor)
reporter = &reporting.CiReporter{
CiService: prService,
ReportStrategy: ReportStrategy,
Expand Down
5 changes: 4 additions & 1 deletion cli/pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ func GitHubCI(lock core_locking.Lock, policyChecker core_policy.Checker, backend
}

repoOwner, repositoryName := utils.ParseRepoNamespace(ghRepository)
githubPrService := githubServiceProvider.NewService(ghToken, repositoryName, repoOwner)
githubPrService, err := githubServiceProvider.NewService(ghToken, repositoryName, repoOwner)
if err != nil {
usage.ReportErrorAndExit(githubActor, fmt.Sprintf("could not create pr service: %v", err), 4)
}

currentDir, err := os.Getwd()
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cli/pkg/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func getProjectLockForTests() (error, *locking.PullRequestLock) {
repoOwner := "diggerhq"
repositoryName := "test_dynamodb_lock"
ghToken := "token"
githubPrService := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)
githubPrService, _ := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)
reporter := reporting.CiReporter{
CiService: &githubPrService,
PrNumber: 1,
Expand Down Expand Up @@ -388,7 +388,7 @@ func TestHappyPath(t *testing.T) {
ghEvent := parsedNewPullRequestContext.Event
repoOwner := parsedNewPullRequestContext.RepositoryOwner
repositoryName := parsedNewPullRequestContext.Repository
githubPrService := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)
githubPrService, _ := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)

assert.Equal(t, "pull_request", parsedNewPullRequestContext.EventName)

Expand Down Expand Up @@ -545,7 +545,7 @@ func TestMultiEnvHappyPath(t *testing.T) {
repoOwner := parsedNewPullRequestContext.RepositoryOwner
repositoryName := parsedNewPullRequestContext.Repository
diggerProjectNamespace := repoOwner + "/" + repositoryName
githubPrService := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)
githubPrService, _ := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)

assert.Equal(t, "pull_request", parsedNewPullRequestContext.EventName)

Expand Down Expand Up @@ -765,7 +765,7 @@ workflows:
ghEvent := parsedNewPullRequestContext.Event
repoOwner := parsedNewPullRequestContext.RepositoryOwner
repositoryName := parsedNewPullRequestContext.Repository
githubPrService := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)
githubPrService, _ := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)
diggerProjectNamespace := repoOwner + "/" + repositoryName

assert.Equal(t, "pull_request", parsedNewPullRequestContext.EventName)
Expand Down
4 changes: 2 additions & 2 deletions ee/cli/cmd/digger/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (r *RunConfig) GetServices() (*orchestrator.PullRequestService, *orchestrat
switch r.Reporter {
case "github":
repoOwner, repositoryName := utils.ParseRepoNamespace(r.RepoNamespace)
prService = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, repositoryName, repoOwner)
orgService = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, r.RepoNamespace, r.Actor)
prService, _ = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, repositoryName, repoOwner)
orgService, _ = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, r.RepoNamespace, r.Actor)
reporter = &reporting.CiReporter{
CiService: prService,
ReportStrategy: ReportStrategy,
Expand Down
11 changes: 8 additions & 3 deletions ee/cli/pkg/github/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@ import (

type GithubServiceProviderAdvanced struct{}

func (_ GithubServiceProviderAdvanced) NewService(ghToken string, repoName string, owner string) dg_github.GithubService {
func (_ GithubServiceProviderAdvanced) NewService(ghToken string, repoName string, owner string) (dg_github.GithubService, error) {
client := github.NewClient(nil)
if ghToken != "" {
client = client.WithAuthToken(ghToken)
}

githubHostname := os.Getenv("DIGGER_GITHUB_HOSTNAME")
var err error
if githubHostname != "" {
log.Printf("info: using github hostname: %v", githubHostname)
githubEnterpriseBaseUrl := fmt.Sprintf("https://%v/api/v3/", githubHostname)
githubEnterpriseUploadUrl := fmt.Sprintf("https://%v/api/uploads/", githubHostname)
client.WithEnterpriseURLs(githubEnterpriseBaseUrl, githubEnterpriseUploadUrl)
client, err = client.WithEnterpriseURLs(githubEnterpriseBaseUrl, githubEnterpriseUploadUrl)
if err != nil {
log.Printf("error: could not create enterprise client: %v", err)
return dg_github.GithubService{}, fmt.Errorf("could not create enterprise client: %v", err)
}
}

return dg_github.GithubService{
Client: client,
RepoName: repoName,
Owner: owner,
}
}, nil
}
6 changes: 3 additions & 3 deletions libs/orchestrator/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
)

type GithubServiceProvider interface {
NewService(ghToken string, repoName string, owner string) GithubService
NewService(ghToken string, repoName string, owner string) (GithubService, error)
}

type GithubServiceProviderBasic struct{}

func (_ GithubServiceProviderBasic) NewService(ghToken string, repoName string, owner string) GithubService {
func (_ GithubServiceProviderBasic) NewService(ghToken string, repoName string, owner string) (GithubService, error) {
client := github.NewClient(nil)
if ghToken != "" {
client = client.WithAuthToken(ghToken)
Expand All @@ -30,7 +30,7 @@ func (_ GithubServiceProviderBasic) NewService(ghToken string, repoName string,
Client: client,
RepoName: repoName,
Owner: owner,
}
}, nil
}

type GithubService struct {
Expand Down
2 changes: 1 addition & 1 deletion libs/orchestrator/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestFindAllProjectsDependantOnImpactedProjects(t *testing.T) {
}

func TestFindAllChangedFilesOfPR(t *testing.T) {
githubPrService := GithubServiceProviderBasic{}.NewService("", "digger", "diggerhq")
githubPrService, _ := GithubServiceProviderBasic{}.NewService("", "digger", "diggerhq")
files, _ := githubPrService.GetChangedFiles(98)
// 45 changed files including 1 renamed file so the previous filename is included
assert.Equal(t, 46, len(files))
Expand Down
2 changes: 1 addition & 1 deletion libs/spec/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (v VCSProvider) GetPrService(vcsSpec VcsSpec) (orchestrator.PullRequestServ
if token == "" {
return nil, fmt.Errorf("failed to get githbu service: GITHUB_TOKEN not specified")
}
return github.GithubServiceProviderBasic{}.NewService(token, vcsSpec.RepoName, vcsSpec.RepoOwner), nil
return github.GithubServiceProviderBasic{}.NewService(token, vcsSpec.RepoName, vcsSpec.RepoOwner)
default:
return nil, fmt.Errorf("could not get PRService, unknown type %v", vcsSpec.VcsType)
}
Expand Down

0 comments on commit 353215e

Please sign in to comment.