Skip to content

Commit

Permalink
fix: improved story commands
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveRuble committed Aug 10, 2021
1 parent 8ba6e68 commit 715bc63
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 52 deletions.
2 changes: 1 addition & 1 deletion cmd/git_pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var gitPullRequestCmd = addCommand(gitCmd, &cobra.Command{
return err
}

b := MustGetBosun()
b := MustGetBosunNoEnvironment()
issueSvc, err := b.GetIssueService()
if err != nil {
return errors.New("get issue service")
Expand Down
42 changes: 25 additions & 17 deletions cmd/git_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func StartFeatureDevelopment(taskName string, body string, storyID string) error
return err
}

ctx := b.NewContext()

currentBranch := g.Branch()

branch, err := app.Branching.RenderFeature(issue.Slug(), storyID)
Expand All @@ -136,22 +138,28 @@ func StartFeatureDevelopment(taskName string, body string, storyID string) error
}
check(g.Push())

//if storyHandler != nil {
//
// event, validationErr := stories.Event{
// Payload: stories.EventBranchCreated{},
// StoryID: storyID,
// Story: story,
// Issue: issue.RefPtr(),
// }.Validated()
// if validationErr != nil {
// return validationErr
// }
// err = storyHandler.HandleEvent(event)
// if err != nil {
// return err
// }
// }

if storyHandler == nil {
ctx.Log().Info("No story handler, will not attempt to move story to In Development")
} else {
ctx.Log().Info("Attempting to to move story to In Development")
event, validationErr := stories.Event{
Payload: stories.EventBranchCreated{},
StoryID: storyID,
Story: story,
Issue: issue.RefPtr(),
}.Validated()
if validationErr != nil {
return validationErr
}
err = storyHandler.HandleEvent(event)
if err != nil {
return err
}
ctx.Log().Info("Story moved to In Development")
}
} else {
ctx.Log().Info("No story found, will not attempt to create initial commit or move story")
}

return nil
Expand Down Expand Up @@ -203,7 +211,7 @@ func createStoryCommit(g git.GitWrapper, baseBranch string, branch string, story
%s
`, message, issueMetadata.String(), task.Body)

_, err := g.Exec("commit", "-m", message, "--allow-empty")
_, err := g.Exec("commit", "-m", message, "--allow-empty", "--no-verify")

core.Log.Info("Created initial commit.")
color.Green("%s\n", message)
Expand Down
43 changes: 25 additions & 18 deletions cmd/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ var stackEnsureCmd = addCommand(stackCmd, &cobra.Command{
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {

return configureStack(args, func(stack *kube.Stack) error {
return configureStack(args, func(stack *kube.Stack) (bool, error) {
err := stack.ConfigureNamespaces()
if err != nil {
color.Red("Could not configure namespaces: %+v", err)
Expand All @@ -145,7 +145,7 @@ var stackEnsureCmd = addCommand(stackCmd, &cobra.Command{
}

err = stack.Save()
return err
return false, err
})
},
})
Expand All @@ -157,8 +157,9 @@ var stackEnsureCertsCmd = addCommand(stackEnsureCmd, &cobra.Command{
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {

return configureStack(args, func(stack *kube.Stack) error {
return stack.ConfigureCerts()
return configureStack(args, func(stack *kube.Stack) (bool, error) {
err := stack.ConfigureCerts()
return true, err
})
},
})
Expand All @@ -170,8 +171,9 @@ var stackEnsureNamespacesCmd = addCommand(stackEnsureCmd, &cobra.Command{
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {

return configureStack(args, func(stack *kube.Stack) error {
return stack.ConfigureNamespaces()
return configureStack(args, func(stack *kube.Stack) (bool, error) {
err := stack.ConfigureNamespaces()
return true, err
})
},
})
Expand All @@ -183,13 +185,14 @@ var stackEnsurePullSecretsCmd = addCommand(stackEnsureCmd, &cobra.Command{
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {

return configureStack(args, func(stack *kube.Stack) error {
return stack.ConfigureNamespaces()
return configureStack(args, func(stack *kube.Stack) (bool, error) {
err := stack.ConfigureNamespaces()
return true, err
})
},
})

func configureStack(args []string, fn func(stack *kube.Stack) error) error {
func configureStack(args []string, fn func(stack *kube.Stack) (bool, error)) error {
b, _ := MustGetPlatform()
env := b.GetCurrentEnvironment()

Expand All @@ -206,17 +209,20 @@ func configureStack(args []string, fn func(stack *kube.Stack) error) error {
stack = env.Stack()
}

err = fn(stack)
var save bool
save, err = fn(stack)
if err != nil {
return err
}

err = stack.Save()
if err != nil {
return err
}
if save {
err = stack.Save()
if err != nil {
return err
}

fmt.Println("Stack configured and saved.")
fmt.Println("Stack configured and saved.")
}

return nil

Expand All @@ -230,15 +236,16 @@ var stackDestroyCmd = addCommand(stackCmd, &cobra.Command{
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {

return configureStack(args, func(stack *kube.Stack) error {
return configureStack(args, func(stack *kube.Stack) (bool, error) {

confirmed := cli.RequestConfirmFromUser("Are you sure you want to delete the stack %q and all of its resources", stack.Name)

if !confirmed {
return nil
return false, nil
}

return stack.Destroy()
err := stack.Destroy()
return false, err
})
},
})
Expand Down
21 changes: 21 additions & 0 deletions cmd/story.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ var storyCmd = addCommand(rootCmd, &cobra.Command{
Short: "Commands related to stories development.",
})

var storyHandlersCmd = addCommand(storyCmd, &cobra.Command{
Use: "handlers",
Short: "Show story handler configs.",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {

b := MustGetBosun(cli.Parameters{NoEnvironment: true})

configs := b.GetStoryHandlerConfiguration()

y, _ := yaml.MarshalString(configs)

fmt.Println(y)

return nil

},
}, func(cmd *cobra.Command) {
})


var storyShowtCmd = addCommand(storyCmd, &cobra.Command{
Use: "show {story}",
Short: "Show information about a story.",
Expand Down
33 changes: 30 additions & 3 deletions pkg/bosun/bosun.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ func (b *Bosun) GetScript(name string) (*script.Script, error) {
return nil, errors.Errorf("no script found with name %q", name)
}

func (b *Bosun) ProvideApp(req AppProviderRequest) (*App, error){
func (b *Bosun) ProvideApp(req AppProviderRequest) (*App, error) {
app, err := b.appProvider.GetApp(req)

return app, err
}

func (b *Bosun) GetApp(name string, providerPriority ...string) (*App, error) {
return b.ProvideApp(AppProviderRequest{
Name: name,
Name: name,
ProviderPriority: providerPriority,
})
}
Expand Down Expand Up @@ -1216,7 +1216,34 @@ func (b *Bosun) GetIssueService() (issues.IssueService, error) {

func (b *Bosun) GetStoryHandlerConfiguration() []values.Values {
w := b.GetWorkspace()
return w.StoryHandlers

storyHandlers := map[string]values.Values{}

for k, s := range w.StoryHandlers {
storyHandlers[k] = s
}

p, err := b.GetCurrentPlatform()
if err == nil {
// Merge in story handler configs from the platform
for k, s := range p.StoryHandlers {
mergedStoryHandler, ok := storyHandlers[k]
if !ok {
mergedStoryHandler = values.Values{}
}

mergedStoryHandler = mergedStoryHandler.Merge(s)
storyHandlers[k] = mergedStoryHandler
}
}

var configs []values.Values

for _, s := range storyHandlers {
configs = append(configs, s)
}

return configs
}

func (b *Bosun) GetGithubToken() (string, error) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/bosun/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Platform struct {
MasterBranch_OBSOLETE string `yaml:"masterBranch,omitempty"`
ReleaseDirectory string `yaml:"releaseDirectory" json:"releaseDirectory"`
AppConfigDirectory string `yaml:"appConfigDirectory,omitempty"`
EnvironmentDirectory string `yaml:"environmentDirectory,omitempty" json:"environmentPaths"`
EnvironmentDirectory string `yaml:"environmentDirectory,omitempty" json:"environmentDirectory"`
BundleDirectory string `yaml:"bundleDirectory,omitempty" json:"bundleDirectory"`
EnvironmentPaths []string `yaml:"environmentPaths,omitempty" json:"environmentPaths"`
ClusterPaths []string `yaml:"clusterPaths,omitempty" json:"clusterPaths"`
Expand All @@ -61,6 +61,7 @@ type Platform struct {
ValueOverrides *values.ValueSetCollection `yaml:"valueOverrides,omitempty"`
ReleaseMetadata []*ReleaseMetadata `yaml:"releases" json:"releases"`
Apps PlatformAppConfigs `yaml:"apps,omitempty"`
StoryHandlers map[string]values.Values `yaml:"storyHandlers"`
releaseManifests map[string]*ReleaseManifest `yaml:"-"`
environmentConfigs []*environment.Config `yaml:"-" json:"-"`
_clusterConfigs kube.ClusterConfigs `yaml:"-" json:"-"`
Expand Down
36 changes: 35 additions & 1 deletion pkg/bosun/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,44 @@ type Workspace struct {
Minikube *kube.MinikubeConfig `yaml:"minikube,omitempty" json:"minikube,omitempty"`
LocalRepos map[string]*vcs.LocalRepo `yaml:"localRepos" json:"localRepos"`
GithubCloneProtocol string `yaml:"githubCloneProtocol"`
StoryHandlers []values.Values `yaml:"storyHandlers"`
StoryHandlers StoryHandlers `yaml:"storyHandlers"`
ClusterKubeconfigPaths map[string]string `yaml:"clusterKubeconfigPaths"`
}

type StoryHandlers map[string]values.Values

func (s *StoryHandlers) UnmarshalYAML(unmarshal func(interface{}) error) error {

var m map[string]values.Values

var arr []values.Values
if err := unmarshal(&arr); err == nil {

// migrate array to map

m = StoryHandlers{}

for i, config := range arr {
provider, providerErr := config.GetAtPath("provider")
if providerErr != nil {
return errors.Errorf("could not parse story handler config at index %d, expected it to have a provider element", i)
}

m[provider.(string)] = config
}
} else {
err = unmarshal(&m)
if err != nil {
return err
}
}

*s = m

return nil

}

func (w *Workspace) UnmarshalYAML(unmarshal func(interface{}) error) error {
type proxyType Workspace
var proxy proxyType
Expand Down
1 change: 1 addition & 0 deletions pkg/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type ExecutionContext interface {
templating.TemplateValuer
util.WithLogFielder
core.Ctxer
GetWorkspaceCommand(name string, hint string) *CommandValue
}

func (d *Command) String() string {
Expand Down
27 changes: 18 additions & 9 deletions pkg/command/command_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
)

type CommandValue struct {
Comment string `yaml:"comment,omitempty" json:"comment,omitempty"`
Value string `yaml:"value" json:"value"`
Command `yaml:"-" json:"-"`
OS map[string]*CommandValue `yaml:"os,omitempty" json:"os,omitempty"`
Comment string `yaml:"comment,omitempty" json:"comment,omitempty"`
Value string `yaml:"value" json:"value"`
Command `yaml:"-" json:"-"`
OS map[string]*CommandValue `yaml:"os,omitempty" json:"os,omitempty"`
WorkspaceCommand string `yaml:"workspaceCommand,omitempty"`
WorkspaceCommandHint string `yaml:"workspaceCommandHint,omitempty"`

resolvedValue string
}
Expand Down Expand Up @@ -127,12 +129,19 @@ func (c *CommandValue) Resolve(ctx ExecutionContext) (string, error) {

c.resolved = true

if c.Value != "" {
c.resolvedValue, err = templating.RenderTemplate(c.Value, ctx.TemplateValues())
if c.WorkspaceCommandHint != "" {

realCommandValue := ctx.GetWorkspaceCommand(c.WorkspaceCommand, c.WorkspaceCommandHint)
c.resolvedValue, err = realCommandValue.Resolve(ctx)
} else {
c.resolvedValue, err = c.Command.Execute(ctx, CommandOpts{IgnoreDryRun: true, StreamOutput:ctx.GetParameters().Verbose})
// trim whitespace, as script output may contain line breaks at the end
c.resolvedValue = strings.TrimSpace(c.resolvedValue)

if c.Value != "" {
c.resolvedValue, err = templating.RenderTemplate(c.Value, ctx.TemplateValues())
} else {
c.resolvedValue, err = c.Command.Execute(ctx, CommandOpts{IgnoreDryRun: true, StreamOutput: ctx.GetParameters().Verbose})
// trim whitespace, as script output may contain line breaks at the end
c.resolvedValue = strings.TrimSpace(c.resolvedValue)
}
}

return c.resolvedValue, err
Expand Down
1 change: 0 additions & 1 deletion pkg/environmentvariables/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type Variable struct {
type Dependencies interface {
command.ExecutionContext
workspace.Contexter
GetWorkspaceCommand(name string, hint string) *command.CommandValue
}

// Ensure sets Value using the From CommandValue.
Expand Down
2 changes: 1 addition & 1 deletion pkg/jira/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Transitions struct {
InDevelopment string `yaml:"development,omitempty"`
CodeReview string `yaml:"codeReview,omitempty"`
QA string `yaml:"qa,omitempty"`
UAT string `yaml:"qa,omitempty"`
UAT string `yaml:"uat,omitempty"`
}

type CompiledTransitions struct {
Expand Down

0 comments on commit 715bc63

Please sign in to comment.