@@ -38,7 +38,9 @@ func (s *environmentService) Create(ctx context.Context, options *CreateOptions)
3838 if err != nil {
3939 return nil , err
4040 }
41- return s .waitForRunning (ctx , envID )
41+ return waitForRunning (ctx , s .Client , envID , func (env * gitpod.EnvironmentGetResponseEnvironment ) (bool , error ) {
42+ return true , nil
43+ })
4244}
4345
4446func (s * environmentService ) Start (ctx context.Context , environmentID string ) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
@@ -48,7 +50,9 @@ func (s *environmentService) Start(ctx context.Context, environmentID string) (*
4850 if err != nil {
4951 return nil , err
5052 }
51- return s .waitForRunning (ctx , environmentID )
53+ return waitForRunning (ctx , s .Client , environmentID , func (env * gitpod.EnvironmentGetResponseEnvironment ) (bool , error ) {
54+ return true , nil
55+ })
5256}
5357
5458func (s * environmentService ) Stop (ctx context.Context , environmentID string ) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
@@ -58,7 +62,7 @@ func (s *environmentService) Stop(ctx context.Context, environmentID string) (*g
5862 if err != nil {
5963 return nil , err
6064 }
61- return s . waitForStopped (ctx , environmentID )
65+ return waitForStopped (ctx , s . Client , environmentID )
6266}
6367
6468func (s * environmentService ) Delete (ctx context.Context , environmentID string ) error {
@@ -72,12 +76,12 @@ func (s *environmentService) Delete(ctx context.Context, environmentID string) e
7276 }
7377 return err
7478 }
75- return s . waitForDeleted (ctx , environmentID )
79+ return waitForDeleted (ctx , s . Client , environmentID )
7680}
7781
78- func ( s * environmentService ) waitForDeleted (ctx context.Context , envID string ) error {
79- _ , err := s . waitForEnvironment (ctx , envID , func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error ) {
80- resp , err := s . Client .Environments .Get (ctx , gitpod.EnvironmentGetParams {
82+ func waitForDeleted (ctx context.Context , client * gitpod. Client , envID string ) error {
83+ _ , err := waitForEnvironment (ctx , client , envID , func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error ) {
84+ resp , err := client .Environments .Get (ctx , gitpod.EnvironmentGetParams {
8185 EnvironmentID : gitpod .String (envID ),
8286 })
8387 if err != nil {
@@ -92,9 +96,9 @@ func (s *environmentService) waitForDeleted(ctx context.Context, envID string) e
9296 return err
9397}
9498
95- func ( s * environmentService ) waitForStopped (ctx context.Context , envID string ) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
96- return s . waitForEnvironment (ctx , envID , func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error ) {
97- resp , err := s . Client .Environments .Get (ctx , gitpod.EnvironmentGetParams {
99+ func waitForStopped (ctx context.Context , client * gitpod. Client , envID string ) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
100+ return waitForEnvironment (ctx , client , envID , func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error ) {
101+ resp , err := client .Environments .Get (ctx , gitpod.EnvironmentGetParams {
98102 EnvironmentID : gitpod .String (envID ),
99103 })
100104 if err != nil {
@@ -109,9 +113,9 @@ func (s *environmentService) waitForStopped(ctx context.Context, envID string) (
109113 })
110114}
111115
112- func ( s * environmentService ) waitForRunning (ctx context.Context , envID string ) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
113- return s . waitForEnvironment (ctx , envID , func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error ) {
114- resp , err := s . Client .Environments .Get (ctx , gitpod.EnvironmentGetParams {
116+ func waitForRunning (ctx context.Context , client * gitpod. Client , envID string , check func ( * gitpod. EnvironmentGetResponseEnvironment ) ( bool , error ) ) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
117+ return waitForEnvironment (ctx , client , envID , func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error ) {
118+ resp , err := client .Environments .Get (ctx , gitpod.EnvironmentGetParams {
115119 EnvironmentID : gitpod .String (envID ),
116120 })
117121 if err != nil {
@@ -122,7 +126,11 @@ func (s *environmentService) waitForRunning(ctx context.Context, envID string) (
122126 return nil , false , fmt .Errorf ("environment creation failed: %s" , fm )
123127 }
124128 if resp .Environment .Status .Phase == gitpod .EnvironmentGetResponseEnvironmentStatusPhaseEnvironmentPhaseRunning {
125- return & resp .Environment , true , nil
129+ ok , err := check (& resp .Environment )
130+ if err != nil {
131+ return nil , false , err
132+ }
133+ return & resp .Environment , ok , nil
126134 }
127135 if resp .Environment .Status .Phase == gitpod .EnvironmentGetResponseEnvironmentStatusPhaseEnvironmentPhaseStopping {
128136 return nil , false , errors .New ("environment creation failed: environment is stopping" )
@@ -140,11 +148,11 @@ func (s *environmentService) waitForRunning(ctx context.Context, envID string) (
140148 })
141149}
142150
143- func ( s * environmentService ) waitForEnvironment (ctx context.Context , envID string , check func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error )) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
144- return waitFor (ctx , s . Client , envID , gitpod .EventWatchResponseResourceTypeResourceTypeEnvironment , envID , check )
151+ func waitForEnvironment (ctx context.Context , client * gitpod. Client , envID string , check func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error )) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
152+ return WaitFor (ctx , client , envID , gitpod .EventWatchResponseResourceTypeResourceTypeEnvironment , envID , check )
145153}
146154
147- func waitFor [T any ](ctx context.Context , client * gitpod.Client , envID string , resourceType gitpod.EventWatchResponseResourceType , resourceID string , check func () (* T , bool , error )) (* T , error ) {
155+ func WaitFor [T any ](ctx context.Context , client * gitpod.Client , envID string , resourceType gitpod.EventWatchResponseResourceType , resourceID string , check func () (* T , bool , error )) (* T , error ) {
148156 env , ok , err := check ()
149157 if err != nil {
150158 return nil , err
0 commit comments