@@ -9,13 +9,12 @@ import (
99
1010 "github.com/MakeNowJust/heredoc"
1111 bkErrors "github.com/buildkite/cli/v3/internal/errors"
12- "github.com/buildkite/cli/v3/internal/io"
12+ bk_io "github.com/buildkite/cli/v3/internal/io"
1313 "github.com/buildkite/cli/v3/internal/pipeline/resolver"
1414 "github.com/buildkite/cli/v3/internal/util"
1515 "github.com/buildkite/cli/v3/internal/validation/scopes"
1616 "github.com/buildkite/cli/v3/pkg/cmd/factory"
1717 buildkite "github.com/buildkite/go-buildkite/v4"
18- "github.com/charmbracelet/huh/spinner"
1918 "github.com/spf13/cobra"
2019 "github.com/spf13/pflag"
2120)
@@ -99,7 +98,7 @@ func NewCmdBuildNew(f *factory.Factory) *cobra.Command {
9998 )
10099 }
101100
102- err = io .Confirm (& confirmed , fmt .Sprintf ("Create new build on %s?" , resolvedPipeline .Name ))
101+ err = bk_io .Confirm (& confirmed , fmt .Sprintf ("Create new build on %s?" , resolvedPipeline .Name ))
103102 if err != nil {
104103 return bkErrors .NewUserAbortedError (err , "confirmation canceled" )
105104 }
@@ -179,47 +178,44 @@ func NewCmdBuildNew(f *factory.Factory) *cobra.Command {
179178func newBuild (ctx context.Context , org string , pipeline string , f * factory.Factory , message string , commit string , branch string , web bool , env map [string ]string , metaData map [string ]string , ignoreBranchFilters bool ) error {
180179 var actionErr error
181180 var build buildkite.Build
182- spinErr := spinner .New ().
183- Title (fmt .Sprintf ("Starting new build for %s" , pipeline )).
184- Action (func () {
185- branch = strings .TrimSpace (branch )
186- if len (branch ) == 0 {
187- p , _ , err := f .RestAPIClient .Pipelines .Get (ctx , org , pipeline )
188- if err != nil {
189- actionErr = bkErrors .WrapAPIError (err , "fetching pipeline information" )
190- return
191- }
192-
193- // Check if the pipeline has a default branch set
194- if p .DefaultBranch == "" {
195- actionErr = bkErrors .NewValidationError (
196- nil ,
197- fmt .Sprintf ("No default branch set for pipeline %s" , pipeline ),
198- "Please specify a branch using --branch (-b)" ,
199- "Set a default branch in your pipeline settings on Buildkite" ,
200- )
201- return
202- }
203- branch = p .DefaultBranch
204- }
205-
206- newBuild := buildkite.CreateBuild {
207- Message : message ,
208- Commit : commit ,
209- Branch : branch ,
210- Env : env ,
211- MetaData : metaData ,
212- IgnorePipelineBranchFilters : ignoreBranchFilters ,
181+ spinErr := bk_io .SpinWhile (fmt .Sprintf ("Starting new build for %s" , pipeline ), func () {
182+ branch = strings .TrimSpace (branch )
183+ if len (branch ) == 0 {
184+ p , _ , err := f .RestAPIClient .Pipelines .Get (ctx , org , pipeline )
185+ if err != nil {
186+ actionErr = bkErrors .WrapAPIError (err , "fetching pipeline information" )
187+ return
213188 }
214189
215- var err error
216- build , _ , err = f .RestAPIClient .Builds .Create (ctx , org , pipeline , newBuild )
217- if err != nil {
218- actionErr = bkErrors .WrapAPIError (err , "creating build" )
190+ // Check if the pipeline has a default branch set
191+ if p .DefaultBranch == "" {
192+ actionErr = bkErrors .NewValidationError (
193+ nil ,
194+ fmt .Sprintf ("No default branch set for pipeline %s" , pipeline ),
195+ "Please specify a branch using --branch (-b)" ,
196+ "Set a default branch in your pipeline settings on Buildkite" ,
197+ )
219198 return
220199 }
221- }).
222- Run ()
200+ branch = p .DefaultBranch
201+ }
202+
203+ newBuild := buildkite.CreateBuild {
204+ Message : message ,
205+ Commit : commit ,
206+ Branch : branch ,
207+ Env : env ,
208+ MetaData : metaData ,
209+ IgnorePipelineBranchFilters : ignoreBranchFilters ,
210+ }
211+
212+ var err error
213+ build , _ , err = f .RestAPIClient .Builds .Create (ctx , org , pipeline , newBuild )
214+ if err != nil {
215+ actionErr = bkErrors .WrapAPIError (err , "creating build" )
216+ return
217+ }
218+ })
223219 if spinErr != nil {
224220 return bkErrors .NewInternalError (spinErr , "error in spinner UI" )
225221 }
0 commit comments