Skip to content

Commit 48511e8

Browse files
authored
feat: Add source directory to Sonarqube project name (#456)
1 parent 7227750 commit 48511e8

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

launch.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,21 @@ func launch(api screwdriver.API, buildID int, rootDir, emitterPath, metaSpace, s
442442
oldJobName := job.Name
443443
pr := prNumber(job.Name)
444444

445+
scm, err := parseScmURI(pipeline.ScmURI, pipeline.ScmRepo.Name)
446+
if err != nil {
447+
return err, "", ""
448+
}
449+
450+
pipelineName := pipeline.ScmRepo.Name
451+
if scm.RootDir != "" {
452+
pipelineName += ":" + scm.RootDir
453+
}
454+
445455
coverageScope := ""
446456
if len(job.Permutations) > 0 {
447457
coverageScope = job.Permutations[0].Annotations.CoverageScope
448458
}
449-
coverageInfo, coverageErr := api.GetCoverageInfo(job.ID, job.PipelineID, job.Name, pipeline.ScmRepo.Name, coverageScope, pr, strconv.Itoa(job.PrParentJobID))
459+
coverageInfo, coverageErr := api.GetCoverageInfo(job.ID, job.PipelineID, job.Name, pipelineName, coverageScope, pr, strconv.Itoa(job.PrParentJobID))
450460

451461
parentBuildIDs := convertToArray(build.ParentBuildID)
452462

@@ -553,11 +563,6 @@ func launch(api screwdriver.API, buildID int, rootDir, emitterPath, metaSpace, s
553563
return fmt.Errorf("Writing Parent %v Meta JSON: %v", metaLog, err), "", ""
554564
}
555565

556-
scm, err := parseScmURI(pipeline.ScmURI, pipeline.ScmRepo.Name)
557-
if err != nil {
558-
return err, "", ""
559-
}
560-
561566
log.Printf("Creating Workspace in %v", rootDir)
562567
w, err := createWorkspace(isLocal, rootDir, scm.Host, scm.Org, scm.Repo)
563568
if err != nil {

launch_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,12 @@ func TestParseScmURI(t *testing.T) {
419419
wantOrg := "screwdriver-cd"
420420
wantRepo := "launcher"
421421
wantBranch := "master"
422+
wantRootDir := "childDirectory"
422423

423-
scmURI := "github.com:123456:master"
424+
scmURI := "github.com:123456:master:childDirectory"
424425
scmName := "screwdriver-cd/launcher"
425426
parsedURL, err := parseScmURI(scmURI, scmName)
426-
host, org, repo, branch := parsedURL.Host, parsedURL.Org, parsedURL.Repo, parsedURL.Branch
427+
host, org, repo, branch, rootDir := parsedURL.Host, parsedURL.Org, parsedURL.Repo, parsedURL.Branch, parsedURL.RootDir
427428
if err != nil {
428429
t.Errorf("Unexpected error parsing SCM URI %q: %v", scmURI, err)
429430
}
@@ -443,6 +444,10 @@ func TestParseScmURI(t *testing.T) {
443444
if branch != wantBranch {
444445
t.Errorf("branch = %q, want %q", branch, wantBranch)
445446
}
447+
448+
if rootDir != wantRootDir {
449+
t.Errorf("rootDir = %q, want %q", rootDir, wantRootDir)
450+
}
446451
}
447452

448453
func TestCreateWorkspace(t *testing.T) {

0 commit comments

Comments
 (0)