Skip to content
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

Create project option without alm settings necessary fix #107

Merged
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
45 changes: 26 additions & 19 deletions cmd/createProjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ var createProjectCmd = &cobra.Command{
func init() {
createCmd.AddCommand(createProjectCmd)

createProjectCmd.Flags().String("project-name", "", "name of the project")
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")
createProjectCmd.Flags().StringP("team", "t", "", "project team name")
createProjectCmd.Flags().String("repo-id", "r", "URL or ID of ALM repository")
createProjectCmd.Flags().StringP("repo-id", "r", "", "URL or ID of ALM repository")
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.")
Expand Down Expand Up @@ -62,25 +63,34 @@ func createProjectsRootCommand(cmd *cobra.Command, _ []string) {
qwe(ExitCodeError, err, "failed to parse the repo url flag")
}

if repositoryID == "" {
qwm(ExitCodeError, "missing required flag repo-id")
projectName, err := cmd.Flags().GetString("project-name")
if err != nil {
qwe(ExitCodeError, err, "failed to parse the project name flag")
}

overwrite, err := p.cmd.Flags().GetString("overwrite")
if err != nil {
qwe(ExitCodeError, err, "failed to parse the overwrite flag: %v")
}

force, err := p.cmd.Flags().GetBool("force-create")
if err != nil {
qwm(ExitCodeError, fmt.Sprintf("failed to parse the force-create flag: %v", err))
}

overwrite, err := p.cmd.Flags().GetString("overwrite")
if err != nil {
qwe(ExitCodeError, err, "failed to parse the overwrite flag: %v")
if (repositoryID != "" && projectName != "") || (repositoryID == "" && projectName == "") {
qwm(ExitCodeError, "please provide either the repo-id or name flag, but not both")
}

if projectName != "" && overwrite != "" {
qwm(ExitCodeError, "please provide either the project-name or overwrite flag, but not both")
}

p.overwriteOrForce(force, overwrite) // Check if overwrite and force flags are used together.

p.checkProjectIfExist(repositoryID, force, overwrite) // Check if the project already exists.
p.checkProjectIfExist(repositoryID, projectName, force, overwrite) // Check if the project already exists.

project := p.createProject(repositoryID, force, overwrite) // Create the project.
project := p.createProject(repositoryID, projectName, force, overwrite) // Create the project.

if !p.cmd.Flags().Changed("product-name") {
qwm(ExitCodeSuccess, "project created successfully")
Expand All @@ -105,7 +115,7 @@ func createProjectsRootCommand(cmd *cobra.Command, _ []string) {
qwm(ExitCodeSuccess, "the project assigned to the product")
}

func (p *Project) createProject(repo string, force bool, overwrite ...string) *client.Project {
func (p *Project) createProject(repo, projectName string, force bool, overwrite string) *client.Project {
klog.Debugf("creating project with repo-id: %s", repo)
if len(p.printRows) == 0 {
p.printRows = projectPrintHeaders()
Expand Down Expand Up @@ -169,13 +179,10 @@ func (p *Project) createProject(repo string, force bool, overwrite ...string) *c
return s
}()

var isOverwrite bool
var overwriteName = ""
if len(overwrite) > 0 {
overwriteName = overwrite[0]
}
if overwriteName != "" {
isOverwrite = true
isOverwrite := len(overwrite) > 0
overwriteName := projectName
if isOverwrite {
overwriteName = overwrite
}

pd := client.ProjectDetail{
Expand Down Expand Up @@ -237,7 +244,7 @@ func (p *Project) overwriteOrForce(force bool, overwrite string) {
}
}

func (p *Project) checkProjectIfExist(repositoryID string, force bool, overwrite string) {
func (p *Project) checkProjectIfExist(repositoryID, projectName string, force bool, overwrite string) {
var isOverwrite bool
if len(overwrite) > 0 {
isOverwrite = true
Expand All @@ -247,7 +254,7 @@ func (p *Project) checkProjectIfExist(repositoryID string, force bool, overwrite
return
}

projects, err := p.client.ListProjects("", repositoryID)
projects, err := p.client.ListProjects(projectName, repositoryID)
if err != nil {
qwe(ExitCodeError, err, "failed to check project with alm info")
}
Expand All @@ -257,7 +264,7 @@ func (p *Project) checkProjectIfExist(repositoryID string, force bool, overwrite
p.printRows = append(p.printRows, Row{Columns: project.FieldsAsRow()})
}
TableWriter(p.printRows...)
qwm(ExitCodeError, fmt.Sprintf("%d project(s) with the same repo-id already exists. for force creation pass --force-create flag or rename project with --overwrite flag", len(projects)))
qwm(ExitCodeError, fmt.Sprintf("%d project(s) with the same project already exists. for force creation pass --force-create flag or rename project with --overwrite flag", len(projects)))
}
}

Expand Down
21 changes: 16 additions & 5 deletions cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func init() {
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.")

scanCmd.Flags().String("project-name", "", "name of the project [create-project]")
scanCmd.Flags().StringP("labels", "l", "", "comma separated label names [create-project]")
scanCmd.Flags().StringP("team", "T", "", "project team name [create-project]")
scanCmd.Flags().StringP("repo-id", "r", "", "URL or ID of ALM repository [create-project]")
Expand Down Expand Up @@ -1056,21 +1057,27 @@ func (s *Scan) checkForRescanOnlyTool() (bool, *client.ScannerInfo, error) {
}

func (s *Scan) findORCreateProject() (*client.Project, error) {
if !s.cmd.Flags().Changed("repo-id") && !s.cmd.Flags().Changed("project") {
if !(s.cmd.Flags().Changed("repo-id") || s.cmd.Flags().Changed("project-name")) && !s.cmd.Flags().Changed("project") {
return nil, errors.New("missing a required flag(repo or project) to get project detail")
}

repo, err := s.cmd.Flags().GetString("repo-id")
if err != nil {
return nil, fmt.Errorf("failed to get repo flag: %w", err)
}
projectName, err := s.cmd.Flags().GetString("project-name")
if err != nil {
return nil, fmt.Errorf("failed to get project-name flag: %w", err)
}
var name string
if repo == "" {
if repo == "" && projectName == "" {
project, err := getSanitizedFlagStr(s.cmd, "project")
if err != nil {
return nil, fmt.Errorf("failed to get project flag: %w", err)
}
name = project
} else {
name = projectName
}

projects, err := s.client.ListProjects(name, repo)
Expand All @@ -1095,16 +1102,20 @@ func (s *Scan) findORCreateProject() (*client.Project, error) {
return nil, errors.New("no projects were found according to the given parameters")
}

if !s.cmd.Flags().Changed("repo-id") {
return nil, errors.New("missing a required repo flag to create project")
if !(s.cmd.Flags().Changed("repo-id") || s.cmd.Flags().Changed("project-name")) {
return nil, errors.New("missing a required repo or project-name flag to create a project")
}

if s.cmd.Flags().Changed("repo-id") && s.cmd.Flags().Changed("project-name") {
return nil, errors.New("both repo and project-name flags cannot be used together")
}

var p = Project{
cmd: s.cmd,
client: s.client,
}

var project = p.createProject(repo, false)
var project = p.createProject(repo, name, false, "")

if !p.cmd.Flags().Changed("product-name") {
return project, nil
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.22

require (
github.com/google/go-querystring v1.1.0
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/go-version v1.7.0
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
go.mongodb.org/mongo-driver v1.15.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
go.mongodb.org/mongo-driver v1.16.1
)

require (
Expand All @@ -17,7 +17,7 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
Expand All @@ -28,7 +28,7 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
34 changes: 18 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand All @@ -8,12 +8,12 @@ github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand All @@ -28,8 +28,8 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -46,32 +46,34 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
go.mongodb.org/mongo-driver v1.15.0 h1:rJCKC8eEliewXjZGf0ddURtl7tTVy1TK3bfl0gkUSLc=
go.mongodb.org/mongo-driver v1.15.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4l8=
go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
Loading