Skip to content

Commit

Permalink
fix:[ASSMT-285]: Add Project Check for pipelines.go (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritek01 authored Apr 2, 2024
1 parent 8395c52 commit 5b30b5c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
13 changes: 0 additions & 13 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,6 @@ func migrateSpinnakerApplication() error {
if len(pipelines) == 0 {
log.Info("No pipelines found to be migrated")
return nil
} else {
// Check if the project already exists for the given input project name in the given org
projects := getProjects()
id := findProjectIdByName(projects, migrationReq.ProjectIdentifier)

if len(id) > 0 {
log.Info("Project already exists with the given name")
} else {
log.Info("Creating project....")
if err := createAProject(migrationReq.OrgIdentifier, migrationReq.ProjectIdentifier, formatString(migrationReq.ProjectIdentifier)); err != nil {
log.Error(err)
}
}
}

payload := map[string][]map[string]interface{}{"pipelines": pipelines}
Expand Down
4 changes: 4 additions & 0 deletions pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ func createSpinnakerPipelines(pipelines interface{}) (reqId string, err error) {
OrgIdentifier: migrationReq.OrgIdentifier,
AccountIdentifier: migrationReq.Account,
}
err = CheckProjectExistsAndCreate()
if err != nil {
return "", err
}
j, err := json.MarshalIndent(pipelines, "", " ")
if err != nil {
return "", fmt.Errorf("failed to marshal pipelines JSON: %v", err)
Expand Down
26 changes: 26 additions & 0 deletions projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,29 @@ func CreateProjectsUsingCSV() (err error) {
}
return
}

func CheckProjectExistsAndCreate() error {
if len(migrationReq.ProjectIdentifier) == 0 {
migrationReq.ProjectIdentifier = TextInput("Identifier for the Project - ")
}

log.WithFields(log.Fields{
"Account": migrationReq.Account,
"OrgIdentifier": migrationReq.OrgIdentifier,
"ProjectIdentifier": migrationReq.ProjectIdentifier,
}).Info("Project check details : ")

projects := getProjects()
id := findProjectIdByName(projects, migrationReq.ProjectIdentifier)

if len(id) > 0 {
log.Infof("Project with identifier %s exists", migrationReq.ProjectIdentifier)
} else {
log.Infof("Project with identifier %s does not exist", migrationReq.ProjectIdentifier)
if err := createAProject(migrationReq.OrgIdentifier, migrationReq.ProjectIdentifier, formatString(migrationReq.ProjectIdentifier)); err != nil {
log.Error(err)
}
log.Infof("Project with identifier %s created", migrationReq.ProjectIdentifier)
}
return nil
}

0 comments on commit 5b30b5c

Please sign in to comment.