Skip to content

Commit

Permalink
Process criticality as integer
Browse files Browse the repository at this point in the history
  • Loading branch information
canack committed Nov 6, 2024
1 parent 25d764f commit 5f5be8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
2 changes: 1 addition & 1 deletion client/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type ProjectDetail struct {
// FeatureBranchInfiniteRetention holds a value that disables the feature branch retention period.
FeatureBranchInfiniteRetention bool `json:"feature_branch_no_retention"`
DefaultBranch string `json:"default_branch"`
Criticality string `json:"criticality"`
CriticalityLevel int `json:"criticality_level"`
}

type ProjectSource struct {
Expand Down
39 changes: 11 additions & 28 deletions cmd/createProjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func init() {
createCmd.AddCommand(createProjectCmd)

createProjectCmd.Flags().String("project-name", "", "name of the project")
createProjectCmd.Flags().String("criticality", "", "business criticality of the project, possible values are [ Major, High, Medium, Low, None, Auto ]. Default is [None]")
createProjectCmd.Flags().Int("criticality-level", 0, "business criticality of the project, possible values are [ 4 = Major, 3 = High, 2 = Medium, 1 = Low, 0 = None, -1 = Auto ]. Default is [0]")
createProjectCmd.Flags().Bool("force-create", false, "ignore if the URL is used by another Kondukto project")
createProjectCmd.Flags().StringP("overwrite", "w", "", "rename the project name when creating a new project")
createProjectCmd.Flags().StringP("labels", "l", "", "comma separated label names")
Expand Down Expand Up @@ -193,38 +193,21 @@ func (p *Project) createProject(repo, projectName string, force bool, overwrite
qwe(ExitCodeError, err, "failed to parse the scope-included-files flag")
}

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

businessCriticality := func() string {
const (
criticalityMajor = "Major"
criticalityHigh = "High"
criticalityMedium = "Medium"
criticalityLow = "Low"
criticalityNone = "None"
criticalityAuto = "Auto"
)

switch strings.ToLower(criticality) {
case strings.ToLower(criticalityMajor):
return criticalityMajor
case strings.ToLower(criticalityHigh):
return criticalityHigh
case strings.ToLower(criticalityMedium):
return criticalityMedium
case strings.ToLower(criticalityLow):
return criticalityLow
case strings.ToLower(criticalityNone):
return criticalityNone
case strings.ToLower(criticalityAuto):
return criticalityAuto
default:
return criticalityNone
businessCriticalityLevel, err := func() (int, error) {
if criticality < -1 || criticality > 4 {
return 0, fmt.Errorf("invalid criticality level: %d", criticality)
}

return criticality, nil
}()
if err != nil {
qwe(ExitCodeError, err, "business criticality level must be between -1, 0, 1, 2, 3 or 4")
}

projectSource := func() client.ProjectSource {
s := client.ProjectSource{Tool: tool}
Expand Down Expand Up @@ -269,7 +252,7 @@ func (p *Project) createProject(repo, projectName string, force bool, overwrite
FeatureBranchRetention: featureBranchRetention,
FeatureBranchInfiniteRetention: featureBranchNoRetention,
DefaultBranch: defaultBranch,
Criticality: businessCriticality,
CriticalityLevel: businessCriticalityLevel,
}

project, err := p.client.CreateProject(pd)
Expand Down

0 comments on commit 5f5be8f

Please sign in to comment.