| 149 | } |
| 150 | |
| 151 | func (co *CloneOptions) Commit() error { |
| 152 | sourceProject, err := co.Client.Projects.GetByIdentifier(co.Source.Value) |
| 153 | if err != nil { |
| 154 | return err |
| 155 | } |
| 156 | |
| 157 | var lifecycleID string |
| 158 | if co.Lifecycle.Value != "" { |
| 159 | lifecycle, err := co.Client.Lifecycles.GetByIDOrName(co.Lifecycle.Value) |
| 160 | if err != nil { |
| 161 | return err |
| 162 | } |
| 163 | lifecycleID = lifecycle.GetID() |
| 164 | } else { |
| 165 | lifecycleID = sourceProject.LifecycleID |
| 166 | } |
| 167 | |
| 168 | var projectGroupID string |
| 169 | if co.Group.Value != "" { |
| 170 | projectGroup, err := co.Client.ProjectGroups.GetByIDOrName(co.Group.Value) |
| 171 | if err != nil { |
| 172 | return err |
| 173 | } |
| 174 | projectGroupID = projectGroup.GetID() |
| 175 | } else { |
| 176 | projectGroupID = sourceProject.ProjectGroupID |
| 177 | } |
| 178 | |
| 179 | clonedProject, err := co.Client.Projects.Clone(sourceProject, projects.ProjectCloneRequest{Name: co.Name.Value, Description: co.Description.Value, ProjectGroupID: projectGroupID, LifecycleID: lifecycleID}) |
| 180 | if err != nil { |
| 181 | return err |
| 182 | } |
| 183 | |
| 184 | _, err = fmt.Fprintf(co.Out, "\nSuccessfully cloned project '%s' (%s), with lifecycle '%s' in project group '%s'.\n", clonedProject.Name, clonedProject.Slug, lifecycleID, projectGroupID) |
| 185 | if err != nil { |
| 186 | return err |
| 187 | } |
| 188 | |
| 189 | link := output.Bluef("%s/app#/%s/projects/%s", co.Host, co.Space.GetID(), clonedProject.GetID()) |
| 190 | fmt.Fprintf(co.Out, "View this project on Octopus Deploy: %s\n", link) |
| 191 | |
| 192 | return nil |
| 193 | } |
| 194 | |
| 195 | func (co *CloneOptions) GenerateAutomationCmd() { |
| 196 | if !co.NoPrompt { |