Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pending command from pipeline create #313

Merged
Merged
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
61 changes: 27 additions & 34 deletions pkg/cmd/pipeline/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (

"github.com/AlecAivazis/survey/v2"
"github.com/MakeNowJust/heredoc"
"github.com/buildkite/cli/v3/internal/io"
"github.com/buildkite/cli/v3/pkg/cmd/factory"
"github.com/buildkite/go-buildkite/v3/buildkite"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/huh/spinner"
"github.com/charmbracelet/lipgloss"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -60,8 +59,6 @@ func NewCmdPipelineCreate(f *factory.Factory) *cobra.Command {
}
}

fmt.Printf("Creating pipeline %s with description %s, repo %s\n", answers.Pipeline, answers.Description, repoURL)

return createPipeline(f.RestAPIClient, f.Config.OrganizationSlug(), answers.Pipeline, answers.Description, repoURL)
},
}
Expand All @@ -86,35 +83,31 @@ func getRepoURLS(f *factory.Factory) []string {
}

func createPipeline(client *buildkite.Client, org, pipelineName, description, repoURL string) error {
l := io.NewPendingCommand(func() tea.Msg {
createPipeline := buildkite.CreatePipeline{
Name: *buildkite.String(pipelineName),
Repository: *buildkite.String(repoURL),
Description: *buildkite.String(description),
Configuration: *buildkite.String("steps:\n - label: \":pipeline:\"\n command: buildkite-agent pipeline upload"),
}

pipeline, resp, err := client.Pipelines.Create(org, &createPipeline)
if err != nil {
// return renderOutput(fmt.Sprintf("Unable to create pipeline.: %s", err.Error()))
return io.PendingOutput(lipgloss.JoinVertical(lipgloss.Top,
lipgloss.NewStyle().Padding(1, 1).Render(fmt.Sprintf("Unable to create pipeline.: %s", err.Error()))))
}

if resp == nil {
return io.PendingOutput(lipgloss.JoinVertical(lipgloss.Top,
lipgloss.NewStyle().Padding(1, 1).Render("Unable to create pipeline.")))
}

if resp.StatusCode != 201 {
return io.PendingOutput(lipgloss.JoinVertical(lipgloss.Top,
lipgloss.NewStyle().Padding(1, 1).Render(fmt.Sprintf("Unable to create pipeline. %d: %s", resp.StatusCode, resp.Status))))
}

return io.PendingOutput(lipgloss.JoinVertical(lipgloss.Top,
lipgloss.NewStyle().Padding(1, 1).Render(fmt.Sprintf("Pipeline created: %s", *pipeline.WebURL))))
}, fmt.Sprintf("Creating new pipeline %s for %s", pipelineName, org))
p := tea.NewProgram(l)
_, err := p.Run()
var err error
var output string

spinErr := spinner.New().
Title(fmt.Sprintf("Creating new pipeline %s for %s", pipelineName, org)).
Action(func() {
createPipeline := buildkite.CreatePipeline{
Name: *buildkite.String(pipelineName),
Repository: *buildkite.String(repoURL),
Description: *buildkite.String(description),
Configuration: *buildkite.String("steps:\n - label: \":pipeline:\"\n command: buildkite-agent pipeline upload"),
}

var pipeline *buildkite.Pipeline
pipeline, _, err = client.Pipelines.Create(org, &createPipeline)

output = lipgloss.JoinVertical(lipgloss.Top, lipgloss.NewStyle().Padding(1, 1).Render(fmt.Sprintf("Pipeline created: %s", *pipeline.WebURL)))
}).
Run()

fmt.Println(output)

if spinErr != nil {
return spinErr
}

return err
}