@@ -38,6 +38,7 @@ import (
3838 "strings"
3939 "time"
4040
41+ "github.com/cli/cli/v2/internal/codespaces/codespace"
4142 "github.com/opentracing/opentracing-go"
4243)
4344
@@ -140,46 +141,7 @@ func (a *API) GetRepository(ctx context.Context, nwo string) (*Repository, error
140141 return & response , nil
141142}
142143
143- type Codespace struct {
144- Name string `json:"name"`
145- GUID string `json:"guid"`
146- CreatedAt string `json:"created_at"`
147- LastUsedAt string `json:"last_used_at"`
148- Branch string `json:"branch"`
149- RepositoryName string `json:"repository_name"`
150- RepositoryNWO string `json:"repository_nwo"`
151- OwnerLogin string `json:"owner_login"`
152- Environment CodespaceEnvironment `json:"environment"`
153- }
154-
155- type CodespaceEnvironment struct {
156- State string `json:"state"`
157- Connection CodespaceEnvironmentConnection `json:"connection"`
158- GitStatus CodespaceEnvironmentGitStatus `json:"gitStatus"`
159- }
160-
161- type CodespaceEnvironmentGitStatus struct {
162- Ahead int `json:"ahead"`
163- Behind int `json:"behind"`
164- Branch string `json:"branch"`
165- Commit string `json:"commit"`
166- HasUnpushedChanges bool `json:"hasUnpushedChanges"`
167- HasUncommitedChanges bool `json:"hasUncommitedChanges"`
168- }
169-
170- const (
171- CodespaceEnvironmentStateAvailable = "Available"
172- )
173-
174- type CodespaceEnvironmentConnection struct {
175- SessionID string `json:"sessionId"`
176- SessionToken string `json:"sessionToken"`
177- RelayEndpoint string `json:"relayEndpoint"`
178- RelaySAS string `json:"relaySas"`
179- HostPublicKeys []string `json:"hostPublicKeys"`
180- }
181-
182- func (a * API ) ListCodespaces (ctx context.Context ) ([]* Codespace , error ) {
144+ func (a * API ) ListCodespaces (ctx context.Context ) ([]* codespace.Codespace , error ) {
183145 req , err := http .NewRequest (
184146 http .MethodGet , a .githubAPI + "/user/codespaces" , nil ,
185147 )
@@ -204,7 +166,7 @@ func (a *API) ListCodespaces(ctx context.Context) ([]*Codespace, error) {
204166 }
205167
206168 var response struct {
207- Codespaces []* Codespace `json:"codespaces"`
169+ Codespaces []* codespace. Codespace `json:"codespaces"`
208170 }
209171 if err := json .Unmarshal (b , & response ); err != nil {
210172 return nil , fmt .Errorf ("error unmarshaling response: %w" , err )
@@ -267,10 +229,10 @@ func (a *API) GetCodespaceToken(ctx context.Context, ownerLogin, codespaceName s
267229 return response .RepositoryToken , nil
268230}
269231
270- func (a * API ) GetCodespace (ctx context.Context , token , owner , codespace string ) (* Codespace , error ) {
232+ func (a * API ) GetCodespace (ctx context.Context , token , owner , codespaceName string ) (* codespace. Codespace , error ) {
271233 req , err := http .NewRequest (
272234 http .MethodGet ,
273- a .githubAPI + "/vscs_internal/user/" + owner + "/codespaces/" + codespace ,
235+ a .githubAPI + "/vscs_internal/user/" + owner + "/codespaces/" + codespaceName ,
274236 nil ,
275237 )
276238 if err != nil {
@@ -294,15 +256,15 @@ func (a *API) GetCodespace(ctx context.Context, token, owner, codespace string)
294256 return nil , jsonErrorResponse (b )
295257 }
296258
297- var response Codespace
259+ var response codespace. Codespace
298260 if err := json .Unmarshal (b , & response ); err != nil {
299261 return nil , fmt .Errorf ("error unmarshaling response: %w" , err )
300262 }
301263
302264 return & response , nil
303265}
304266
305- func (a * API ) StartCodespace (ctx context.Context , token string , codespace * Codespace ) error {
267+ func (a * API ) StartCodespace (ctx context.Context , token string , codespace * codespace. Codespace ) error {
306268 req , err := http .NewRequest (
307269 http .MethodPost ,
308270 a .githubAPI + "/vscs_internal/proxy/environments/" + codespace .GUID + "/start" ,
@@ -429,7 +391,7 @@ type CreateCodespaceParams struct {
429391
430392// CreateCodespace creates a codespace with the given parameters and returns a non-nil error if it
431393// fails to create.
432- func (a * API ) CreateCodespace (ctx context.Context , params * CreateCodespaceParams ) (* Codespace , error ) {
394+ func (a * API ) CreateCodespace (ctx context.Context , params * CreateCodespaceParams ) (* codespace. Codespace , error ) {
433395 codespace , err := a .startCreate (ctx , params .RepositoryID , params .Machine , params .Branch , params .Location )
434396 if err != errProvisioningInProgress {
435397 return codespace , err
@@ -482,7 +444,7 @@ var errProvisioningInProgress = errors.New("provisioning in progress")
482444// It may return success or an error, or errProvisioningInProgress indicating that the operation
483445// did not complete before the GitHub API's time limit for RPCs (10s), in which case the caller
484446// must poll the server to learn the outcome.
485- func (a * API ) startCreate (ctx context.Context , repoID int , machine , branch , location string ) (* Codespace , error ) {
447+ func (a * API ) startCreate (ctx context.Context , repoID int , machine , branch , location string ) (* codespace. Codespace , error ) {
486448 requestBody , err := json .Marshal (startCreateRequest {repoID , branch , location , machine })
487449 if err != nil {
488450 return nil , fmt .Errorf ("error marshaling request: %w" , err )
@@ -512,7 +474,7 @@ func (a *API) startCreate(ctx context.Context, repoID int, machine, branch, loca
512474 return nil , errProvisioningInProgress // RPC finished before result of creation known
513475 }
514476
515- var response Codespace
477+ var response codespace. Codespace
516478 if err := json .Unmarshal (b , & response ); err != nil {
517479 return nil , fmt .Errorf ("error unmarshaling response: %w" , err )
518480 }
@@ -554,7 +516,7 @@ type getCodespaceRepositoryContentsResponse struct {
554516 Content string `json:"content"`
555517}
556518
557- func (a * API ) GetCodespaceRepositoryContents (ctx context.Context , codespace * Codespace , path string ) ([]byte , error ) {
519+ func (a * API ) GetCodespaceRepositoryContents (ctx context.Context , codespace * codespace. Codespace , path string ) ([]byte , error ) {
558520 req , err := http .NewRequest (http .MethodGet , a .githubAPI + "/repos/" + codespace .RepositoryNWO + "/contents/" + path , nil )
559521 if err != nil {
560522 return nil , fmt .Errorf ("error creating request: %w" , err )
0 commit comments