Skip to content

Commit

Permalink
fix(reviewapp): Don't fail reviewapp commands if account flag is pass…
Browse files Browse the repository at this point in the history
…ed (#68)
  • Loading branch information
CuriousLearner authored Aug 28, 2024
1 parent cf06763 commit e8915a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Limits the number of custom domains to 4.
* `ps resize` raises a warning for non-existent service.
* `reviewapps` cmd optionally accepts `-c`/ `account` flag.

## [4.5.0] - 2024-05-16

Expand Down
24 changes: 21 additions & 3 deletions cmd/reviewapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@ import (
"github.com/spf13/cobra"
)

func accountFlagIgnoredWarning() {
if AccountIDorAlias != "" {
fmt.Println(aurora.Yellow("Warning: The 'account' flag is ignored for reviewapps and all its subcommands. Reviewapps depend on access to the pipeline rather than access to the account."))
}
}

// reviewappsCmd represents the reviewapps command
var reviewappsCmd = &cobra.Command{
Use: "reviewapps <pipeline>",
Short: "list deployed review apps",
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
ui.StartSpinner()
accountFlagIgnoredWarning()
a, err := app.Init(args[0], UseAWSCredentials, SessionDurationSeconds)
checkErr(err)
reviewApps, err := a.GetReviewApps()
Expand All @@ -62,8 +69,9 @@ var reviewappsCreateCmd = &cobra.Command{
Long: `Creates a review app from a pull request on the pipeline repository and triggers the iniital build`,
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
ui.StartSpinner()
accountFlagIgnoredWarning()
name := args[0]
if len(strings.Split(name, ":")) != 2 {
checkErr(fmt.Errorf("invalid review app name -- must be in format <pipeline>:<pr-number>"))
Expand Down Expand Up @@ -122,8 +130,9 @@ var reviewappsDestroyCmd = &cobra.Command{
Short: "destroys the review app",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
ui.StartSpinner()
accountFlagIgnoredWarning()
a, err := app.Init(args[0], UseAWSCredentials, SessionDurationSeconds)
checkErr(err)
if !a.IsReviewApp() { // TODO: validate
Expand All @@ -140,4 +149,13 @@ func init() {
reviewappsCreateCmd.Flags().StringVar(&release, "release", "", "Specify a specific pre-release stack")
upgradeCmd.PersistentFlags().MarkHidden("release")
reviewappsCmd.AddCommand(reviewappsDestroyCmd)

reviewappsCmd.PersistentFlags().StringVarP(
&AccountIDorAlias,
"account",
"c",
"",
"AWS account ID or alias (not needed if you are only the administrator of one account)",
)
reviewappsCmd.PersistentFlags().MarkHidden("account")
}

0 comments on commit e8915a2

Please sign in to comment.