8000 fix(codeScan): optimize code scan by zhujian7 · Pull Request #647 · caicloud/cyclone · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(codeScan): optimize code scan #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2018
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: 2 additions & 0 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
_ "github.com/caicloud/cyclone/pkg/scm/provider/github"
_ "github.com/caicloud/cyclone/pkg/scm/provider/gitlab"
_ "github.com/caicloud/cyclone/pkg/scm/provider/svn"

_ "github.com/caicloud/cyclone/pkg/integrate/provider/sonar"
)

// NeverStop may be passed to Until to make it never stop.
Expand Down
8 changes: 6 additions & 2 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ type ScanSonarQubeConfig struct {
SourcePath string `bson:"sourcePath,omitempty" json:"sourcePath,omitempty" description:"path of the code used to be scanned"`
EncodingStyle string `bson:"encodingStyle,omitempty" json:"encodingStyle,omitempty" description:"encoding style of the source code"`
Language string `bson:"language,omitempty" json:"language,omitempty" description:"language of the source code"`
Threshold string `bson:"threshold,omitempty" json:"threshold,omitempty" description:"sonarqube threshold"`
Threshold int `bson:"threshold,omitempty" json:"threshold,omitempty" description:"sonarqube threshold"`
}

// PackageStage represents the config of package stage.
Expand Down Expand Up @@ -503,8 +503,9 @@ type ImageReleaseTaskStatus struct {

// ScanStatusSonarQube including status of sonarqube scanning result overview.
type ScanStatusSonarQube struct {
// including 'reliability_rating, sqale_rating, security_rating, coverage, duplicated_lines_density'
// including 'reliability_rating, sqale_rating, security_rating, coverage, duplicated_lines_density, quality_gate_details'
Measures []*SonarMeasure `bson:"measures,omitempty" json:"measures,omitempty" description:"measures of this project from sonarqube"`
QGStatus string `bson:"qgstatus,omitempty" json:"qgstatus,omitempty" description:"quality gate status of this project from sonarqube"`
OverviewLink string `bson:"overviewLink,omitempty" json:"overviewLink,omitempty" description:"link to sonarqube result website"`
}

Expand Down Expand Up @@ -822,6 +823,9 @@ const (

// NodeRepoType represents the repository type NodeJS.
NodeRepoType string = "NodeJS"

// GolangType represents Go language.
GolangType string = "Go"
)

// NotificationContent contains some pipeline record infomation.
Expand Down
11 changes: 11 additions & 0 deletions pkg/common/constant.go
< 8000 table class=" diff-table js-diff-table tab-size " data-tab-size="8" data-diff-anchor="diff-dde4ab882c726be1c0f7665a63c836bf8a6a6bec38e91f18d1c4477a8b4747b4" data-paste-markdown-skip> Original file line number Diff line number Diff line change @@ -0,0 +1,11 @@ package common
const ( // CloneDir represents the dir which the repo clone to. CloneDir = "/tmp/code"
// GoTestReport represents the file name of golang test report. // If user configured the golang test report in unit-test commands (eg: go test -coverprofile=coverage.out), // We will cp the file(coverage.out) to go_test_report.cyclone, and use it at code-scan stage. GoTestReport = "go_test_report.cyclone" )
56 changes: 55 additions & 1 deletion pkg/worker/integrate/manager.go → pkg/integrate/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@ import (
"fmt"

"github.com/caicloud/cyclone/pkg/api"
"github.com/caicloud/cyclone/pkg/util/http/errors"
)

// ITGProvider is an interface for ingetration.
type ITGProvider interface {
// CodeScan execute code analysis.
CodeScan(url, token string, config *CodeScanConfig) (string, error)

// SetCodeScanStatus sets status for CodeScanStageStatus.
SetCodeScanStatus(url, token string, pid string, s *api.CodeScanStageStatus) error

// CreateProject create a project.
CreateProject(url, token string, projectKey, projectName string) error

// SetQualityGate sets the project's quality gate.
SetQualityGate(url, token string, projectKey string, gateId int) error

// Validate validate the token.
Validate(url, token string) (bool, error)
}

// itgProviders represents the set of integration providers.
Expand Down Expand Up @@ -46,7 +57,7 @@ type CodeScanConfig struct {
SourcePath string `bson:"sourcePath,omitempty" json:"sourcePath,omitempty"`
EncodingStyle string `bson:"encodingStyle,omitempty" json:"encodingStyle,omitempty"`
Language string `bson:"language,omitempty" json:"language,omitempty"`
Threshold string `bson:"threshold,omitempty" json:"threshold,omitempty"`
Threshold int `bson:"threshold,omitempty" json:"threshold,omitempty"`
ExtensionAgrs []string `bson:"extensionArgs,omitempty" json:"extensionArgs,omitempty"`
ProjectName string `bson:"projectName,omitempty" json:"projectName,omitempty"`
ProjectKey string `bson:"projectKey,omitempty" json:"projectKey,omitempty"`
Expand Down Expand Up @@ -75,3 +86,46 @@ func SetCodeScanStatus(itype api.IntegrationType, url, token string, projectID s

return p.SetCodeScanStatus(url, token, projectID, s)
}

// CreateProject create a project.
func CreateProject(itype api.IntegrationType, url, token string, projectKey, projectName string) error {
p, err := GetProvider(itype)
if err != nil {
return err
}
return p.CreateProject(url, token, projectKey, projectName)
}

// SetQualityGate sets the project's quality gate.
func SetQualityGate(itype api.IntegrationType, url, token string, projectKey string, gateId int) error {
p, err := GetProvider(itype)
if err != nil {
return err
}
return p.SetQualityGate(url, token, projectKey, gateId)
}

// Validate validate the token.
func Validate(it *api.Integration) (bool, error) {
p, err := GetProvider(it.Type)
if err != nil {
return false, err
}

var url, token string

switch it.Type {
case api.IntegrationTypeSonar:
if it.SonarQube == nil {
return false, fmt.Errorf("integration type is SonarQube, so SonarQube info can not be empty")
}
url = it.SonarQube.Address
token = it.SonarQube.Token

default:
return false, errors.ErrorNotImplemented.Error(
fmt.Sprintf("Validate token for %s type integration", it.Type))
}

return p.Validate(url, token)
}
Loading
0