Skip to content

Commit

Permalink
Merge branch 'release/v1.0.32'
Browse files Browse the repository at this point in the history
  • Loading branch information
yeyisan committed Jun 4, 2024
2 parents 6b4f343 + 120c5b3 commit ad7c17a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion client/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ type ProjectDetail struct {
// FeatureBranchRetention holds the number of days to delete the feature branch after the latest scan.
FeatureBranchRetention uint `json:"feature_branch_retention"`
// FeatureBranchInfiniteRetention holds a value that disables the feature branch retention period.
FeatureBranchInfiniteRetention bool `json:"feature_branch_no_retention"`
FeatureBranchInfiniteRetention bool `json:"feature_branch_no_retention"`
DefaultBranch string `json:"default_branch"`
}

type ProjectSource struct {
Expand Down
9 changes: 8 additions & 1 deletion cmd/createProjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ func init() {
createProjectCmd.Flags().StringP("alm-tool", "a", "", "ALM tool name")
createProjectCmd.Flags().StringP("product-name", "P", "", "name of product")
createProjectCmd.Flags().String("fork-source", "", "Sets the source branch of project's feature branches to be forked from.")
createProjectCmd.Flags().Uint("feature-branch-retention", 0, "Adds a retention(days) period to the project for feature branch delete operations")
createProjectCmd.Flags().Uint("feature-branch-retention", 0, "Adds a retention(days) period to the project for feature branch delete operations.")
createProjectCmd.Flags().Bool("feature-branch-infinite-retention", false, "Sets an infinite retention for project feature branches. Overrides --feature-branch-retention flag when set to true.")
createProjectCmd.Flags().String("default-branch", "main", "Sets the default branch for the project. When repo-id is given, this will be overridden by the repository's default branch.")
}

type Project struct {
Expand Down Expand Up @@ -133,6 +134,11 @@ func (p *Project) createProject(repo string, force bool, overwrite ...string) *c
qwe(ExitCodeError, err, "failed to parse the alm-tool flag")
}

defaultBranch, err := p.cmd.Flags().GetString("default-branch")
if err != nil {
qwe(ExitCodeError, err, "failed to parse the default branch flag")
}

forkSourceBranch, err := p.cmd.Flags().GetString("fork-source")
if err != nil {
qwe(ExitCodeError, err, "failed to parse the fork-source flag")
Expand Down Expand Up @@ -184,6 +190,7 @@ func (p *Project) createProject(repo string, force bool, overwrite ...string) *c
ForkSourceBranch: forkSourceBranch,
FeatureBranchRetention: featureBranchRetention,
FeatureBranchInfiniteRetention: featureBranchNoRetention,
DefaultBranch: defaultBranch,
}

project, err := p.client.CreateProject(pd)
Expand Down
19 changes: 18 additions & 1 deletion cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func init() {
scanCmd.Flags().StringP("product-name", "P", "", "name for product")
scanCmd.Flags().String("env", "", "application anvironment variable, allowed values: [production, staging, develop, feature]")
scanCmd.Flags().BoolP("fork-scan", "B", false, "enables a fork scan that based on project's default branch")
scanCmd.Flags().BoolP("incremental-scan", "i", false, "enables a incremental scan, only available for semgrep imports")
scanCmd.Flags().String("fork-source", "", "sets the source branch of fork scans. If the project already has a fork source branch, this parameter is not necessary to be set. only works for [feature] environment.")
scanCmd.Flags().Bool("override-fork-source", false, "overrides the project's fork source branch. only works for [feature] environment.")

Expand All @@ -79,6 +80,7 @@ func init() {
scanCmd.Flags().String("alm-tool", "A", "ALM tool name [create-project]")
scanCmd.Flags().Uint("feature-branch-retention", 0, "Adds a retention(days) to the project for feature branch delete operations [create-project]")
scanCmd.Flags().Bool("feature-branch-infinite-retention", false, "Sets an infinite retention for project feature branches. Overrides --feature-branch-retention flag when set to true [create-project]")
scanCmd.Flags().String("default-branch", "main", "Sets the default branch for the project. When repo-id is given, this will be overridden by the repository's default branch [create-project].")

scanCmd.Flags().Bool("threshold-risk", false, "set risk score of last scan as threshold")
scanCmd.Flags().Int("threshold-crit", 0, "threshold for number of vulnerabilities with critical severity")
Expand Down Expand Up @@ -147,7 +149,17 @@ type Scan struct {
}

func (s *Scan) startScan() (string, error) {
switch getScanMode(s.cmd) {
var scanMode = getScanMode(s.cmd)
incremental, err := s.cmd.Flags().GetBool("incremental-scan")
if err != nil {
return "", err
}

if incremental && scanMode != modeByFileImport {
return "", fmt.Errorf("scan mode [%d] does not support the incremental scan", scanMode)
}

switch scanMode {
case modeByFileImport:
// scan mode to start a scan by importing a file
eventID, err := s.scanByFileImport()
Expand Down Expand Up @@ -301,6 +313,10 @@ func (s *Scan) scanByFileImport() (string, error) {
if err != nil {
return "", fmt.Errorf("failed to parse fork-scan flag: %w", err)
}
incrementalScan, err := s.cmd.Flags().GetBool("incremental-scan")
if err != nil {
return "", fmt.Errorf("failed to parse incremental-scan flag: %w", err)
}
forkSourceBranch, err := s.cmd.Flags().GetString("fork-source")
if err != nil {
return "", fmt.Errorf("failed to parse fork-source flag: %w", err)
Expand All @@ -327,6 +343,7 @@ func (s *Scan) scanByFileImport() (string, error) {
"fork-source": forkSourceBranch,
"override-fork-source": strconv.FormatBool(overrideForkSourceBranch),
"override_old_analyze": strconv.FormatBool(override),
"incremental-scan": strconv.FormatBool(incrementalScan),
}

eventID, err := s.client.ImportScanResult(absoluteFilePath, form)
Expand Down

0 comments on commit ad7c17a

Please sign in to comment.