@@ -116,7 +116,8 @@ func jsonErrorResponse(b []byte) error {
116116
117117// Repository represents a GitHub repository.
118118type Repository struct {
119- ID int `json:"id"`
119+ ID int `json:"id"`
120+ FullName string `json:"full_name"`
120121}
121122
122123// GetRepository returns the repository associated with the given owner and name.
@@ -152,37 +153,27 @@ func (a *API) GetRepository(ctx context.Context, nwo string) (*Repository, error
152153
153154// Codespace represents a codespace.
154155type Codespace struct {
155- Name string `json:"name"`
156- CreatedAt string `json:"created_at"`
157- LastUsedAt string `json:"last_used_at"`
158- State string `json:"state"`
159- Branch string `json:"branch"`
160- RepositoryName string `json:"repository_name"`
161- RepositoryNWO string `json:"repository_nwo"`
162- OwnerLogin string `json:"owner_login"`
163- Environment CodespaceEnvironment `json:"environment"`
164- Connection CodespaceConnection `json:"connection"`
156+ Name string `json:"name"`
157+ CreatedAt string `json:"created_at"`
158+ LastUsedAt string `json:"last_used_at"`
159+ Owner User `json:"owner"`
160+ Repository Repository `json:"repository"`
161+ State string `json:"state"`
162+ GitStatus CodespaceGitStatus `json:"git_status"`
163+ Connection CodespaceConnection `json:"connection"`
165164}
166165
167- const CodespaceStateProvisioned = "provisioned"
168-
169- type CodespaceEnvironment struct {
170- State string `json:"state"`
171- GitStatus CodespaceEnvironmentGitStatus `json:"gitStatus"`
172- }
173-
174- type CodespaceEnvironmentGitStatus struct {
166+ type CodespaceGitStatus struct {
175167 Ahead int `json:"ahead"`
176168 Behind int `json:"behind"`
177- Branch string `json:"branch"`
178- Commit string `json:"commit"`
169+ Ref string `json:"ref"`
179170 HasUnpushedChanges bool `json:"hasUnpushedChanges"`
180171 HasUncommitedChanges bool `json:"hasUncommitedChanges"`
181172}
182173
183174const (
184- // CodespaceEnvironmentStateAvailable is the state for a running codespace environment.
185- CodespaceEnvironmentStateAvailable = "Available"
175+ // CodespaceStateAvailable is the state for a running codespace environment.
176+ CodespaceStateAvailable = "Available"
186177)
187178
188179type CodespaceConnection struct {
@@ -459,7 +450,7 @@ func (a *API) CreateCodespace(ctx context.Context, params *CreateCodespaceParams
459450 }
460451
461452 // we continue to poll until the codespace shows as provisioned
462- if codespace .State != CodespaceStateProvisioned {
453+ if codespace .State != CodespaceStateAvailable {
463454 continue
464455 }
465456
@@ -549,13 +540,13 @@ type getCodespaceRepositoryContentsResponse struct {
549540}
550541
551542func (a * API ) GetCodespaceRepositoryContents (ctx context.Context , codespace * Codespace , path string ) ([]byte , error ) {
552- req , err := http .NewRequest (http .MethodGet , a .githubAPI + "/repos/" + codespace .RepositoryNWO + "/contents/" + path , nil )
543+ req , err := http .NewRequest (http .MethodGet , a .githubAPI + "/repos/" + codespace .Repository . FullName + "/contents/" + path , nil )
553544 if err != nil {
554545 return nil , fmt .Errorf ("error creating request: %w" , err )
555546 }
556547
557548 q := req .URL .Query ()
558- q .Add ("ref" , codespace .Branch )
549+ q .Add ("ref" , codespace .GitStatus . Ref )
559550 req .URL .RawQuery = q .Encode ()
560551
561552 a .setHeaders (req )
0 commit comments