-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sub-commands for specific promotion paths
These new sub-commands simplify the interface when promoting between branches in a repository, between environments in a repository, or between two "simple" repositories. The previous behavior is preserved if no sub-command is given: the user can specify any combination of repository, branch and environment folder (even a local repo). For #92
- Loading branch information
Showing
6 changed files
with
342 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/rhd-gitops-example/services/pkg/promotion" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var promoteBranchCmd = &cobra.Command{ | ||
Use: "branch", | ||
Short: "promote between branches within one repository", | ||
RunE: promoteBranchAction, | ||
} | ||
|
||
func init() { | ||
promoteCmd.AddCommand(promoteBranchCmd) | ||
|
||
promoteBranchCmd.Flags().String(fromFlag, "", "the source branch") | ||
promoteBranchCmd.Flags().String(toFlag, "", "the destination branch") | ||
promoteBranchCmd.Flags().String(serviceFlag, "", "the name of the service to promote") | ||
promoteBranchCmd.Flags().String(repoFlag, "", "the URL of the Git repository") | ||
|
||
logIfError(promoteBranchCmd.MarkFlagRequired(fromFlag)) | ||
logIfError(promoteBranchCmd.MarkFlagRequired(toFlag)) | ||
logIfError(promoteBranchCmd.MarkFlagRequired(serviceFlag)) | ||
logIfError(promoteBranchCmd.MarkFlagRequired(repoFlag)) | ||
} | ||
|
||
func promoteBranchAction(c *cobra.Command, args []string) error { | ||
bindFlags(c.Flags(), []string{ | ||
fromFlag, | ||
toFlag, | ||
serviceFlag, | ||
repoFlag, | ||
}) | ||
|
||
fromBranch := viper.GetString(fromFlag) | ||
toBranch := viper.GetString(toFlag) | ||
service := viper.GetString(serviceFlag) | ||
repo := viper.GetString(repoFlag) | ||
|
||
newBranchName := viper.GetString(branchNameFlag) | ||
msg := viper.GetString(msgFlag) | ||
keepCache := viper.GetBool(keepCacheFlag) | ||
|
||
from := promotion.EnvLocation{ | ||
RepoPath: repo, | ||
Branch: fromBranch, | ||
Folder: "", | ||
} | ||
to := promotion.EnvLocation{ | ||
RepoPath: repo, | ||
Branch: toBranch, | ||
Folder: "", | ||
} | ||
|
||
sm, err := newServiceManager() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if msg == "" { | ||
msg = fmt.Sprintf("Promote branch %s to %s", fromBranch, toBranch) | ||
} | ||
|
||
return sm.Promote(service, from, to, newBranchName, msg, keepCache) | ||
} |
Oops, something went wrong.