Skip to content

Commit

Permalink
feat: adds ability to create new build-deploy pipelines
Browse files Browse the repository at this point in the history
style: shortens help text and converts all to lowercase
  • Loading branch information
FredrikMWold committed Jul 18, 2024
1 parent 84035ef commit b84cbd3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 30 deletions.
3 changes: 1 addition & 2 deletions applicationDashboard/applicationDashboard.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package appllicationDashboard

import (
"github.com/FredrikMWold/radix-tui/applicationTable"
"github.com/FredrikMWold/radix-tui/commands"
"github.com/FredrikMWold/radix-tui/styles"
tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -52,7 +51,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case commands.Applications:
m.applications = msg

case applicationTable.SelectedApplication:
case commands.SelectedApplication:
m.isLoadingApplication = true
m.focused = pipeline
return m, commands.GetApplicationData(string(msg))
Expand Down
18 changes: 9 additions & 9 deletions applicationDashboard/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,44 +82,44 @@ func (k keyMap) FullHelp() [][]key.Binding {
var ApplicationTableKeys = keyMap{
Enter: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "Select Application"),
key.WithHelp("enter", "select application"),
),
Up: key.NewBinding(
key.WithKeys("up"),
key.WithHelp("up", "Move up"),
key.WithHelp("up", "move up"),
),
Down: key.NewBinding(
key.WithKeys("down"),
key.WithHelp("down", "Move down"),
key.WithHelp("down", "move down"),
),
}

var PipelineTableKeys = keyMap{
Enter: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "Open in browser"),
key.WithHelp("enter", "open"),
),
Up: key.NewBinding(
key.WithKeys("up"),
key.WithHelp("up", "Move up"),
key.WithHelp("up", "move up"),
),
Down: key.NewBinding(
key.WithKeys("down"),
key.WithHelp("down", "Move down"),
key.WithHelp("down", "move down"),
),
Esc: key.NewBinding(
key.WithKeys("esc"),
key.WithHelp("esc", "Back"),
key.WithHelp("esc", "back"),
),
BuildDeploy: key.NewBinding(
key.WithKeys("ctrl+n"),
key.WithHelp("ctrl+n", "Create build-deploy pipeline"),
key.WithHelp("ctrl+n", "build-deploy"),
),
}

var BuildDeployFormKeys = keyMap{
Esc: key.NewBinding(
key.WithKeys("esc"),
key.WithHelp("esc", "Back"),
key.WithHelp("esc", "back"),
),
}
5 changes: 2 additions & 3 deletions applicationTable/commands.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package applicationTable

import (
"github.com/FredrikMWold/radix-tui/commands"
tea "github.com/charmbracelet/bubbletea"
)

type SelectedApplication string

func selectApplication(application string) tea.Cmd {
return func() tea.Msg {
return SelectedApplication(application)
return commands.SelectedApplication(application)
}
}
15 changes: 15 additions & 0 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

type Applications []string
type SelectedApplication string

func GetApplications() tea.Msg {
result := exec.Command("rx", "get", "application")
Expand All @@ -25,6 +26,20 @@ func GetApplications() tea.Msg {
return Applications(application_list)
}

type CreatedPipelineJob string

func BuildAndDeploy(application string, branch string) tea.Cmd {
return func() tea.Msg {
result := exec.Command("rx", "create", "pipeline-job", "build-deploy", "-a", application, "-b", branch)
_, err := result.Output()
if err != nil {
fmt.Println(err)
}
return SelectedApplication(application)
}

}

func GetApplicationData(application string) tea.Cmd {
return func() tea.Msg {
result := exec.Command("rx", "get", "application", "-a", application)
Expand Down
8 changes: 3 additions & 5 deletions pipelineForm/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import (
type Model struct {
form *huh.Form
SelectedApplication string
environments []string
branches []string
branchMapping map[string]string
width int
}

func New() Model {
return Model{
environments: []string{},
branches: []string{},
form: huh.NewForm(huh.NewGroup(huh.NewInput().Key("name"))),
branchMapping: make(map[string]string),
form: huh.NewForm(huh.NewGroup(huh.NewInput().Key("name"))),
}
}
21 changes: 10 additions & 11 deletions pipelineForm/pipelineForm.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,33 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.form.WithWidth(msg.Width - 12)
m.width = msg.Width
case commands.Application:
var environments []string
var branches []string
var options []string
for _, env := range msg.Environments {
environments = append(environments, env.Name)
if env.BranchMapping != "" {
branches = append(branches, env.BranchMapping)
key := env.BranchMapping + " -> " + env.Name
m.branchMapping[key] = env.BranchMapping
options = append(options, key)
}
}
m.form = huh.NewForm(
huh.NewGroup(
huh.NewSelect[string]().
Key("environment").
Options(huh.NewOptions(environments...)...).
Options(huh.NewOptions(options...)...).
Title("Environment").
Description("Select the environment you want to deploy to").
WithTheme(huh.ThemeCatppuccin()),
huh.NewSelect[string]().
Key("branch").
Options(huh.NewOptions(branches...)...).
Title("Pipeline Type").
Description("Select the type of pipeline you want to create").
WithTheme(huh.ThemeCatppuccin()),
).WithWidth(m.width),
)
m.SelectedApplication = msg.Name
return m, m.form.Init()
}

if m.form.State == huh.StateCompleted {
m.form.State = huh.StateAborted
return m, commands.BuildAndDeploy(m.SelectedApplication, m.branchMapping[m.form.GetString("environment")])
}

form, cmd := m.form.Update(msg)
if f, ok := form.(*huh.Form); ok {
m.form = f
Expand Down

0 comments on commit b84cbd3

Please sign in to comment.