Skip to content

Commit 353215e

Browse files
authored
fix the error calling cli (#1585)
* fix the error calling cli * fix build
1 parent db110f1 commit 353215e

File tree

8 files changed

+25
-17
lines changed

8 files changed

+25
-17
lines changed

cli/cmd/digger/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func (r *RunConfig) GetServices() (*orchestrator.PullRequestService, *orchestrat
3636
switch r.Reporter {
3737
case "github":
3838
repoOwner, repositoryName := utils.ParseRepoNamespace(r.RepoNamespace)
39-
prService = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, repositoryName, repoOwner)
40-
orgService = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, r.RepoNamespace, r.Actor)
39+
prService, _ = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, repositoryName, repoOwner)
40+
orgService, _ = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, r.RepoNamespace, r.Actor)
4141
reporter = &reporting.CiReporter{
4242
CiService: prService,
4343
ReportStrategy: ReportStrategy,

cli/pkg/github/github.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ func GitHubCI(lock core_locking.Lock, policyChecker core_policy.Checker, backend
8080
}
8181

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

8588
currentDir, err := os.Getwd()
8689
if err != nil {

cli/pkg/integration/integration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func getProjectLockForTests() (error, *locking.PullRequestLock) {
4343
repoOwner := "diggerhq"
4444
repositoryName := "test_dynamodb_lock"
4545
ghToken := "token"
46-
githubPrService := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)
46+
githubPrService, _ := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)
4747
reporter := reporting.CiReporter{
4848
CiService: &githubPrService,
4949
PrNumber: 1,
@@ -388,7 +388,7 @@ func TestHappyPath(t *testing.T) {
388388
ghEvent := parsedNewPullRequestContext.Event
389389
repoOwner := parsedNewPullRequestContext.RepositoryOwner
390390
repositoryName := parsedNewPullRequestContext.Repository
391-
githubPrService := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)
391+
githubPrService, _ := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)
392392

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

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

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

@@ -765,7 +765,7 @@ workflows:
765765
ghEvent := parsedNewPullRequestContext.Event
766766
repoOwner := parsedNewPullRequestContext.RepositoryOwner
767767
repositoryName := parsedNewPullRequestContext.Repository
768-
githubPrService := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)
768+
githubPrService, _ := dg_github.GithubServiceProviderBasic{}.NewService(ghToken, repositoryName, repoOwner)
769769
diggerProjectNamespace := repoOwner + "/" + repositoryName
770770

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

ee/cli/cmd/digger/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func (r *RunConfig) GetServices() (*orchestrator.PullRequestService, *orchestrat
3636
switch r.Reporter {
3737
case "github":
3838
repoOwner, repositoryName := utils.ParseRepoNamespace(r.RepoNamespace)
39-
prService = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, repositoryName, repoOwner)
40-
orgService = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, r.RepoNamespace, r.Actor)
39+
prService, _ = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, repositoryName, repoOwner)
40+
orgService, _ = orchestrator_github.GithubServiceProviderBasic{}.NewService(r.GithubToken, r.RepoNamespace, r.Actor)
4141
reporter = &reporting.CiReporter{
4242
CiService: prService,
4343
ReportStrategy: ReportStrategy,

ee/cli/pkg/github/providers.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,28 @@ import (
1010

1111
type GithubServiceProviderAdvanced struct{}
1212

13-
func (_ GithubServiceProviderAdvanced) NewService(ghToken string, repoName string, owner string) dg_github.GithubService {
13+
func (_ GithubServiceProviderAdvanced) NewService(ghToken string, repoName string, owner string) (dg_github.GithubService, error) {
1414
client := github.NewClient(nil)
1515
if ghToken != "" {
1616
client = client.WithAuthToken(ghToken)
1717
}
1818

1919
githubHostname := os.Getenv("DIGGER_GITHUB_HOSTNAME")
20+
var err error
2021
if githubHostname != "" {
2122
log.Printf("info: using github hostname: %v", githubHostname)
2223
githubEnterpriseBaseUrl := fmt.Sprintf("https://%v/api/v3/", githubHostname)
2324
githubEnterpriseUploadUrl := fmt.Sprintf("https://%v/api/uploads/", githubHostname)
24-
client.WithEnterpriseURLs(githubEnterpriseBaseUrl, githubEnterpriseUploadUrl)
25+
client, err = client.WithEnterpriseURLs(githubEnterpriseBaseUrl, githubEnterpriseUploadUrl)
26+
if err != nil {
27+
log.Printf("error: could not create enterprise client: %v", err)
28+
return dg_github.GithubService{}, fmt.Errorf("could not create enterprise client: %v", err)
29+
}
2530
}
2631

2732
return dg_github.GithubService{
2833
Client: client,
2934
RepoName: repoName,
3035
Owner: owner,
31-
}
36+
}, nil
3237
}

libs/orchestrator/github/github.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515
)
1616

1717
type GithubServiceProvider interface {
18-
NewService(ghToken string, repoName string, owner string) GithubService
18+
NewService(ghToken string, repoName string, owner string) (GithubService, error)
1919
}
2020

2121
type GithubServiceProviderBasic struct{}
2222

23-
func (_ GithubServiceProviderBasic) NewService(ghToken string, repoName string, owner string) GithubService {
23+
func (_ GithubServiceProviderBasic) NewService(ghToken string, repoName string, owner string) (GithubService, error) {
2424
client := github.NewClient(nil)
2525
if ghToken != "" {
2626
client = client.WithAuthToken(ghToken)
@@ -30,7 +30,7 @@ func (_ GithubServiceProviderBasic) NewService(ghToken string, repoName string,
3030
Client: client,
3131
RepoName: repoName,
3232
Owner: owner,
33-
}
33+
}, nil
3434
}
3535

3636
type GithubService struct {

libs/orchestrator/github/github_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestFindAllProjectsDependantOnImpactedProjects(t *testing.T) {
115115
}
116116

117117
func TestFindAllChangedFilesOfPR(t *testing.T) {
118-
githubPrService := GithubServiceProviderBasic{}.NewService("", "digger", "diggerhq")
118+
githubPrService, _ := GithubServiceProviderBasic{}.NewService("", "digger", "diggerhq")
119119
files, _ := githubPrService.GetChangedFiles(98)
120120
// 45 changed files including 1 renamed file so the previous filename is included
121121
assert.Equal(t, 46, len(files))

libs/spec/providers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (v VCSProvider) GetPrService(vcsSpec VcsSpec) (orchestrator.PullRequestServ
175175
if token == "" {
176176
return nil, fmt.Errorf("failed to get githbu service: GITHUB_TOKEN not specified")
177177
}
178-
return github.GithubServiceProviderBasic{}.NewService(token, vcsSpec.RepoName, vcsSpec.RepoOwner), nil
178+
return github.GithubServiceProviderBasic{}.NewService(token, vcsSpec.RepoName, vcsSpec.RepoOwner)
179179
default:
180180
return nil, fmt.Errorf("could not get PRService, unknown type %v", vcsSpec.VcsType)
181181
}

0 commit comments

Comments
 (0)