Skip to content
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
60 changes: 33 additions & 27 deletions cmd/changes_submit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,39 @@ func SubmitPlan(cmd *cobra.Command, args []string) error {
title := changeTitle(viper.GetString("title"))
tfPlanOutput := tryLoadText(ctx, viper.GetString("terraform-plan-output"))
codeChangesOutput := tryLoadText(ctx, viper.GetString("code-changes-diff"))
// Detect the repository URL if it wasn't provided
repoUrl := viper.GetString("repo")
if repoUrl == "" {
repoUrl, err = DetectRepoURL(AllDetectors)
if err != nil {
log.WithContext(ctx).WithError(err).WithFields(lf).Debug("Failed to detect repository URL. Use the --repo flag to specify it manually if you require it")
}
}
tags, err := parseTagsArgument()
if err != nil {
return loggedError{
err: err,
fields: lf,
message: "Failed to parse tags",
}
}
properties := &sdp.ChangeProperties{
Title: title,
Description: viper.GetString("description"),
TicketLink: viper.GetString("ticket-link"),
Owner: viper.GetString("owner"),
RawPlan: tfPlanOutput,
CodeChanges: codeChangesOutput,
Repo: repoUrl,
Tags: tags,
}

if changeUuid == uuid.Nil {
log.WithContext(ctx).WithFields(lf).Debug("Creating a new change")

createResponse, err := client.CreateChange(ctx, &connect.Request[sdp.CreateChangeRequest]{
Msg: &sdp.CreateChangeRequest{
Properties: &sdp.ChangeProperties{
Title: title,
Description: viper.GetString("description"),
TicketLink: viper.GetString("ticket-link"),
Owner: viper.GetString("owner"),
// CcEmails: viper.GetString("cc-emails"),
RawPlan: tfPlanOutput,
CodeChanges: codeChangesOutput,
},
Properties: properties,
},
})
if err != nil {
Expand Down Expand Up @@ -177,16 +196,8 @@ func SubmitPlan(cmd *cobra.Command, args []string) error {

_, err := client.UpdateChange(ctx, &connect.Request[sdp.UpdateChangeRequest]{
Msg: &sdp.UpdateChangeRequest{
UUID: changeUuid[:],
Properties: &sdp.ChangeProperties{
Title: title,
Description: viper.GetString("description"),
TicketLink: viper.GetString("ticket-link"),
Owner: viper.GetString("owner"),
// CcEmails: viper.GetString("cc-emails"),
RawPlan: tfPlanOutput,
CodeChanges: codeChangesOutput,
},
UUID: changeUuid[:],
Properties: properties,
},
})
if err != nil {
Expand Down Expand Up @@ -287,16 +298,11 @@ func init() {
changesCmd.AddCommand(submitPlanCmd)

addAPIFlags(submitPlanCmd)
addChangeCreationFlags(submitPlanCmd)

submitPlanCmd.PersistentFlags().String("frontend", "", "The frontend base URL")
_ = submitPlanCmd.PersistentFlags().MarkDeprecated("frontend", "This flag is no longer used and will be removed in a future release. Use the '--app' flag instead.") // MarkDeprecated only errors if the flag doesn't exist, we fall back to using app
submitPlanCmd.PersistentFlags().String("title", "", "Short title for this change. If this is not specified, overmind will try to come up with one for you.")
submitPlanCmd.PersistentFlags().String("description", "", "Quick description of the change.")
submitPlanCmd.PersistentFlags().String("ticket-link", "*", "Link to the ticket for this change. Usually this would be the link to something like the pull request, since the CLI uses this as a unique identifier for the change, meaning that multiple runs with the same ticket link will update the same change.")
submitPlanCmd.PersistentFlags().String("owner", "", "The owner of this change.")
// submitPlanCmd.PersistentFlags().String("cc-emails", "", "A comma-separated list of emails to keep updated with the status of this change.")

submitPlanCmd.PersistentFlags().String("terraform-plan-output", "", "Filename of cached terraform plan output for this change.")
submitPlanCmd.PersistentFlags().String("code-changes-diff", "", "Filename of the code diff of this change.")

submitPlanCmd.PersistentFlags().Int32("blast-radius-link-depth", 0, "Used in combination with '--blast-radius-max-items' to customise how many levels are traversed when calculating the blast radius. Larger numbers will result in a more comprehensive blast radius, but may take longer to calculate. Defaults to the account level settings.")
submitPlanCmd.PersistentFlags().Int32("blast-radius-max-items", 0, "Used in combination with '--blast-radius-link-depth' to customise how many items are included in the blast radius. Larger numbers will result in a more comprehensive blast radius, but may take longer to calculate. Defaults to the account level settings.")
}
61 changes: 61 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cmd

import (
"fmt"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// This file contains re-usable sets of flags that should be used when creating
// commands

// Adds flags for selecting a change by UUID, frontend URL or ticket link
func addChangeUuidFlags(cmd *cobra.Command) {
cmd.PersistentFlags().String("change", "", "The frontend URL of the change to get")
cmd.PersistentFlags().String("ticket-link", "", "Link to the ticket for this change.")
cmd.PersistentFlags().String("uuid", "", "The UUID of the change that should be displayed.")
cmd.MarkFlagsMutuallyExclusive("change", "ticket-link", "uuid")
}

// Adds flags that should be present when creating a change
func addChangeCreationFlags(cmd *cobra.Command) {
cmd.PersistentFlags().String("title", "", "Short title for this change. If this is not specified, overmind will try to come up with one for you.")
cmd.PersistentFlags().String("description", "", "Quick description of the change.")
cmd.PersistentFlags().String("ticket-link", "*", "Link to the ticket for this change. Usually this would be the link to something like the pull request, since the CLI uses this as a unique identifier for the change, meaning that multiple runs with the same ticket link will update the same change.")
cmd.PersistentFlags().String("owner", "", "The owner of this change.")
cmd.PersistentFlags().String("repo", "", "The repository URL that this change should be linked to. This will be automatically detected is possible from the Git config or CI environment.")
cmd.PersistentFlags().String("terraform-plan-output", "", "Filename of cached terraform plan output for this change.")
cmd.PersistentFlags().String("code-changes-diff", "", "Filename of the code diff of this change.")
cmd.PersistentFlags().StringSlice("tags", []string{}, "Tags to apply to this change, these should be specified in key=value format. Multiple tags can be specified by repeating the flag or using a comma separated list.")
}

func parseTagsArgument() (map[string]string, error) {
tags := map[string]string{}
for _, tag := range viper.GetStringSlice("tags") {
parts := strings.SplitN(tag, "=", 2)
if len(parts) != 2 {
return tags, fmt.Errorf("invalid tag format: %s", tag)
}
tags[parts[0]] = parts[1]
}
return tags, nil
}

// Adds common flags to API commands e.g. timeout
func addAPIFlags(cmd *cobra.Command) {
cmd.PersistentFlags().String("timeout", "10m", "How long to wait for responses")
cmd.PersistentFlags().String("app", "https://app.overmind.tech", "The overmind instance to connect to.")
}

// Adds terraform-related flags to a command
func addTerraformBaseFlags(cmd *cobra.Command) {
cmd.PersistentFlags().Bool("reset-stored-config", false, "[deprecated: this is now autoconfigured from local terraform files] Set this to reset the sources config stored in Overmind and input fresh values.")
cmd.PersistentFlags().String("aws-config", "", "[deprecated: this is now autoconfigured from local terraform files] The chosen AWS config method, best set through the initial wizard when running the CLI. Options: 'profile_input', 'aws_profile', 'defaults', 'managed'.")
cmd.PersistentFlags().String("aws-profile", "", "[deprecated: this is now autoconfigured from local terraform files] Set this to the name of the AWS profile to use.")
cobra.CheckErr(cmd.PersistentFlags().MarkHidden("reset-stored-config"))
cobra.CheckErr(cmd.PersistentFlags().MarkHidden("aws-config"))
cobra.CheckErr(cmd.PersistentFlags().MarkHidden("aws-profile"))
cmd.PersistentFlags().Bool("only-use-managed-sources", false, "Set this to skip local autoconfiguration and only use the managed sources as configured in Overmind.")
}
Loading
Loading