@@ -112,15 +112,17 @@ func (a *App) Create(ctx context.Context, opts createOptions) error {
112112 return errors .New ("there are no available machine types for this repository" )
113113 }
114114
115- a .StartProgressIndicatorWithLabel ("Creating codespace" )
116- codespace , err := a .apiClient .CreateCodespace (ctx , & api.CreateCodespaceParams {
115+ createParams := & api.CreateCodespaceParams {
117116 RepositoryID : repository .ID ,
118117 Branch : branch ,
119118 Machine : machine ,
120119 Location : locationResult .Location ,
121120 IdleTimeoutMinutes : int (opts .idleTimeout .Minutes ()),
122121 PermissionsOptOut : opts .permissionsOptOut ,
123- })
122+ }
123+
124+ a .StartProgressIndicatorWithLabel ("Creating codespace" )
125+ codespace , err := a .apiClient .CreateCodespace (ctx , createParams )
124126 a .StopProgressIndicator ()
125127
126128 if err != nil {
@@ -129,27 +131,11 @@ func (a *App) Create(ctx context.Context, opts createOptions) error {
129131 return fmt .Errorf ("error creating codespace: %w" , err )
130132 }
131133
132- if err := a .handleAdditionalPermissions (ctx , aerr .AllowPermissionsURL ); err != nil {
134+ codespace , err = a .handleAdditionalPermissions (ctx , createParams , aerr .AllowPermissionsURL )
135+ if err != nil {
133136 // this error could be a cmdutil.SilentError (in the case that the user opened the browser) so we don't want to wrap it
134137 return err
135138 }
136-
137- // if the user chose to create the codespace without the permissions,
138- // we can continue with the create opting out of the additional permissions
139- a .StartProgressIndicatorWithLabel ("Creating codespace" )
140- codespace , err = a .apiClient .CreateCodespace (ctx , & api.CreateCodespaceParams {
141- RepositoryID : repository .ID ,
142- Branch : branch ,
143- Machine : machine ,
144- Location : locationResult .Location ,
145- IdleTimeoutMinutes : int (opts .idleTimeout .Minutes ()),
146- PermissionsOptOut : true ,
147- })
148- a .StopProgressIndicator ()
149-
150- if err != nil {
151- return fmt .Errorf ("error creating codespace: %w" , err )
152- }
153139 }
154140
155141 if opts .showStatus {
@@ -162,7 +148,7 @@ func (a *App) Create(ctx context.Context, opts createOptions) error {
162148 return nil
163149}
164150
165- func (a * App ) handleAdditionalPermissions (ctx context.Context , allowPermissionsURL string ) error {
151+ func (a * App ) handleAdditionalPermissions (ctx context.Context , createParams * api. CreateCodespaceParams , allowPermissionsURL string ) ( * api. Codespace , error ) {
166152 var (
167153 isInteractive = a .io .CanPrompt ()
168154 cs = a .io .ColorScheme ()
@@ -174,7 +160,7 @@ func (a *App) handleAdditionalPermissions(ctx context.Context, allowPermissionsU
174160 if ! isInteractive {
175161 fmt .Fprintf (a .io .ErrOut , "%s to continue in your web browser to accept: %s\n " , cs .Bold ("Open this URL" ), displayURL )
176162 fmt .Fprintf (a .io .ErrOut , "Alternatively, you can run %q with the %q option to create the codespace without these additional permissions.\n " , a .io .ColorScheme ().Bold ("create" ), cs .Bold ("--default-permissions" ))
177- return nil
163+ return nil , cmdutil . SilentError
178164 }
179165
180166 choices := []string {
@@ -199,20 +185,32 @@ func (a *App) handleAdditionalPermissions(ctx context.Context, allowPermissionsU
199185 }
200186
201187 if err := ask (permsSurvey , & answers ); err != nil {
202- return fmt .Errorf ("error getting answers: %w" , err )
188+ return nil , fmt .Errorf ("error getting answers: %w" , err )
203189 }
204190
205191 // if the user chose to continue in the browser, open the URL
206192 if answers .Accept == choices [0 ] {
207193 if err := a .browser .Browse (allowPermissionsURL ); err != nil {
208- return fmt .Errorf ("error opening browser: %w" , err )
194+ return nil , fmt .Errorf ("error opening browser: %w" , err )
209195 }
210196 // browser opened successfully but we do not know if they accepted the permissions
211197 // so we must exit and wait for the user to attempt the create again
212- return cmdutil .SilentError
198+ return nil , cmdutil .SilentError
213199 }
214200
215- return nil
201+ // if the user chose to create the codespace without the permissions,
202+ // we can continue with the create opting out of the additional permissions
203+ createParams .PermissionsOptOut = true
204+
205+ a .StartProgressIndicatorWithLabel ("Creating codespace" )
206+ codespace , err := a .apiClient .CreateCodespace (ctx , createParams )
207+ a .StopProgressIndicator ()
208+
209+ if err != nil {
210+ return nil , fmt .Errorf ("error creating codespace: %w" , err )
211+ }
212+
213+ return codespace , nil
216214}
217215
218216// showStatus polls the codespace for a list of post create states and their status. It will keep polling
0 commit comments