@@ -10,35 +10,66 @@ import (
1010 "github.com/stainless-sdks/gitpod-go/internal/apierror"
1111)
1212
13- type EnvironmentSandbox struct {
13+ type CreateEnvironmentOptions struct {
14+ ProjectID string
15+ ContextURL string
16+ EnvironmentClass string
17+ }
18+
19+ type StartEnvironmentOptions struct {
20+ EnvironmentID string
21+ }
22+
23+ type StopEnvironmentOptions struct {
24+ EnvironmentID string
25+ }
26+
27+ type DeleteEnvironmentOptions struct {
28+ EnvironmentID string
29+ }
30+
31+ type EnvironmentSandbox interface {
32+ // Get fetches an existing environment.
33+ Get (ctx context.Context , envID string ) (* gitpod.EnvironmentGetResponseEnvironment , error )
34+ // Create creates a new environment and waits for it to be running.
35+ Create (ctx context.Context , options * CreateEnvironmentOptions ) (* gitpod.EnvironmentGetResponseEnvironment , error )
36+ // Start starts an existing environment and waits for it to be running.
37+ Start (ctx context.Context , options * StartEnvironmentOptions ) (* gitpod.EnvironmentGetResponseEnvironment , error )
38+ // Stop stops an existing environment and waits for it to be stopped.
39+ Stop (ctx context.Context , options * StopEnvironmentOptions ) (* gitpod.EnvironmentGetResponseEnvironment , error )
40+ // Delete deletes an existing environment and waits for it to be deleted.
41+ Delete (ctx context.Context , options * DeleteEnvironmentOptions ) error
42+ }
43+
44+ type environmentSandbox struct {
1445 Client * gitpod.Client
1546}
1647
17- func NewEnvironmentSandbox (client * gitpod.Client ) * EnvironmentSandbox {
18- return & EnvironmentSandbox {
48+ func NewEnvironmentSandbox (client * gitpod.Client ) EnvironmentSandbox {
49+ return & environmentSandbox {
1950 Client : client ,
2051 }
2152}
2253
23- type CreateEnvironmentOptions struct {
24- ProjectID string
25- ContextURL string
26- EnvironmentClass string
54+ func (s * environmentSandbox ) Get (ctx context.Context , envID string ) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
55+ resp , err := s .Client .Environments .Get (ctx , gitpod.EnvironmentGetParams {
56+ EnvironmentID : gitpod .String (envID ),
57+ })
58+ if err != nil {
59+ return nil , err
60+ }
61+ return & resp .Environment , nil
2762}
2863
29- func (s * EnvironmentSandbox ) Create (ctx context.Context , options * CreateEnvironmentOptions ) (res * gitpod.EnvironmentGetResponseEnvironment , err error ) {
64+ func (s * environmentSandbox ) Create (ctx context.Context , options * CreateEnvironmentOptions ) (res * gitpod.EnvironmentGetResponseEnvironment , err error ) {
3065 envID , err := s .create (ctx , options )
3166 if err != nil {
3267 return nil , err
3368 }
3469 return s .waitForRunning (ctx , envID )
3570}
3671
37- type StartEnvironmentOptions struct {
38- EnvironmentID string
39- }
40-
41- func (s * EnvironmentSandbox ) Start (ctx context.Context , options * StartEnvironmentOptions ) (res * gitpod.EnvironmentGetResponseEnvironment , err error ) {
72+ func (s * environmentSandbox ) Start (ctx context.Context , options * StartEnvironmentOptions ) (res * gitpod.EnvironmentGetResponseEnvironment , err error ) {
4273 _ , err = s .Client .Environments .Start (ctx , gitpod.EnvironmentStartParams {
4374 EnvironmentID : gitpod .String (options .EnvironmentID ),
4475 })
@@ -48,11 +79,7 @@ func (s *EnvironmentSandbox) Start(ctx context.Context, options *StartEnvironmen
4879 return s .waitForRunning (ctx , options .EnvironmentID )
4980}
5081
51- type StopEnvironmentOptions struct {
52- EnvironmentID string
53- }
54-
55- func (s * EnvironmentSandbox ) Stop (ctx context.Context , options * StopEnvironmentOptions ) (res * gitpod.EnvironmentGetResponseEnvironment , err error ) {
82+ func (s * environmentSandbox ) Stop (ctx context.Context , options * StopEnvironmentOptions ) (res * gitpod.EnvironmentGetResponseEnvironment , err error ) {
5683 _ , err = s .Client .Environments .Stop (ctx , gitpod.EnvironmentStopParams {
5784 EnvironmentID : gitpod .String (options .EnvironmentID ),
5885 })
@@ -61,12 +88,7 @@ func (s *EnvironmentSandbox) Stop(ctx context.Context, options *StopEnvironmentO
6188 }
6289 return s .waitForStopped (ctx , options .EnvironmentID )
6390}
64-
65- type DeleteEnvironmentOptions struct {
66- EnvironmentID string
67- }
68-
69- func (s * EnvironmentSandbox ) Delete (ctx context.Context , options * DeleteEnvironmentOptions ) error {
91+ func (s * environmentSandbox ) Delete (ctx context.Context , options * DeleteEnvironmentOptions ) error {
7092 _ , err := s .Client .Environments .Delete (ctx , gitpod.EnvironmentDeleteParams {
7193 EnvironmentID : gitpod .String (options .EnvironmentID ),
7294 })
@@ -80,7 +102,7 @@ func (s *EnvironmentSandbox) Delete(ctx context.Context, options *DeleteEnvironm
80102 return s .waitForDeleted (ctx , options .EnvironmentID )
81103}
82104
83- func (s * EnvironmentSandbox ) waitForDeleted (ctx context.Context , envID string ) error {
105+ func (s * environmentSandbox ) waitForDeleted (ctx context.Context , envID string ) error {
84106 _ , err := s .waitFor (ctx , envID , func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error ) {
85107 resp , err := s .Client .Environments .Get (ctx , gitpod.EnvironmentGetParams {
86108 EnvironmentID : gitpod .String (envID ),
@@ -97,7 +119,7 @@ func (s *EnvironmentSandbox) waitForDeleted(ctx context.Context, envID string) e
97119 return err
98120}
99121
100- func (s * EnvironmentSandbox ) waitForStopped (ctx context.Context , envID string ) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
122+ func (s * environmentSandbox ) waitForStopped (ctx context.Context , envID string ) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
101123 return s .waitFor (ctx , envID , func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error ) {
102124 resp , err := s .Client .Environments .Get (ctx , gitpod.EnvironmentGetParams {
103125 EnvironmentID : gitpod .String (envID ),
@@ -114,7 +136,7 @@ func (s *EnvironmentSandbox) waitForStopped(ctx context.Context, envID string) (
114136 })
115137}
116138
117- func (s * EnvironmentSandbox ) waitForRunning (ctx context.Context , envID string ) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
139+ func (s * environmentSandbox ) waitForRunning (ctx context.Context , envID string ) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
118140 return s .waitFor (ctx , envID , func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error ) {
119141 resp , err := s .Client .Environments .Get (ctx , gitpod.EnvironmentGetParams {
120142 EnvironmentID : gitpod .String (envID ),
@@ -145,7 +167,7 @@ func (s *EnvironmentSandbox) waitForRunning(ctx context.Context, envID string) (
145167 })
146168}
147169
148- func (s * EnvironmentSandbox ) waitFor (ctx context.Context , envID string , fetch func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error )) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
170+ func (s * environmentSandbox ) waitFor (ctx context.Context , envID string , fetch func () (* gitpod.EnvironmentGetResponseEnvironment , bool , error )) (* gitpod.EnvironmentGetResponseEnvironment , error ) {
149171 env , ok , err := fetch ()
150172 if err != nil {
151173 return nil , err
@@ -178,7 +200,7 @@ func (s *EnvironmentSandbox) waitFor(ctx context.Context, envID string, fetch fu
178200 return nil , stream .Err ()
179201}
180202
181- func (s * EnvironmentSandbox ) create (ctx context.Context , options * CreateEnvironmentOptions ) (string , error ) {
203+ func (s * environmentSandbox ) create (ctx context.Context , options * CreateEnvironmentOptions ) (string , error ) {
182204 if options .ProjectID != "" {
183205 resp , err := s .Client .Environments .NewFromProject (ctx , gitpod.EnvironmentNewFromProjectParams {
184206 ProjectID : gitpod .String (options .ProjectID ),
0 commit comments