X Tutup
Skip to content

Commit 4d5ce7a

Browse files
authored
Adds internal codespace developer flags (cli#5287)
1 parent e0045f2 commit 4d5ce7a

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

.devcontainer/devcontainer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extensions": [
3+
"golang.go"
4+
]
5+
}

internal/codespaces/api/api.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ type CreateCodespaceParams struct {
579579
Branch string
580580
Machine string
581581
Location string
582+
VSCSTarget string
583+
VSCSTargetURL string
582584
PermissionsOptOut bool
583585
}
584586

@@ -625,6 +627,8 @@ type startCreateRequest struct {
625627
Ref string `json:"ref"`
626628
Location string `json:"location"`
627629
Machine string `json:"machine"`
630+
VSCSTarget string `json:"vscs_target,omitempty"`
631+
VSCSTargetURL string `json:"vscs_target_url,omitempty"`
628632
PermissionsOptOut bool `json:"devcontainer_permissions_opt_out"`
629633
}
630634

@@ -654,8 +658,11 @@ func (a *API) startCreate(ctx context.Context, params *CreateCodespaceParams) (*
654658
Ref: params.Branch,
655659
Location: params.Location,
656660
Machine: params.Machine,
661+
VSCSTarget: params.VSCSTarget,
662+
VSCSTargetURL: params.VSCSTargetURL,
657663
PermissionsOptOut: params.PermissionsOptOut,
658664
})
665+
659666
if err != nil {
660667
return nil, fmt.Errorf("error marshaling request: %w", err)
661668
}

pkg/cmd/codespace/create.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"os"
78
"time"
89

910
"github.com/AlecAivazis/survey/v2"
@@ -47,7 +48,13 @@ func newCreateCmd(app *App) *cobra.Command {
4748

4849
// Create creates a new Codespace
4950
func (a *App) Create(ctx context.Context, opts createOptions) error {
50-
locationCh := getLocation(ctx, a.apiClient)
51+
52+
// Overrides for Codespace developers to target test environments
53+
vscsLocation := os.Getenv("VSCS_LOCATION")
54+
vscsTarget := os.Getenv("VSCS_TARGET")
55+
vscsTargetUrl := os.Getenv("VSCS_TARGET_URL")
56+
57+
locationCh := getLocation(ctx, vscsLocation, a.apiClient)
5158

5259
userInputs := struct {
5360
Repository string
@@ -117,6 +124,8 @@ func (a *App) Create(ctx context.Context, opts createOptions) error {
117124
Branch: branch,
118125
Machine: machine,
119126
Location: locationResult.Location,
127+
VSCSTarget: vscsTarget,
128+
VSCSTargetURL: vscsTargetUrl,
120129
IdleTimeoutMinutes: int(opts.idleTimeout.Minutes()),
121130
PermissionsOptOut: opts.permissionsOptOut,
122131
}
@@ -282,9 +291,18 @@ type locationResult struct {
282291
Err error
283292
}
284293

285-
// getLocation fetches the closest Codespace datacenter region/location to the user.
286-
func getLocation(ctx context.Context, apiClient apiClient) <-chan locationResult {
294+
// getLocation fetches the closest Codespace datacenter
295+
// region/location to the user, unless the 'vscsLocationOverride' override is set
296+
func getLocation(ctx context.Context, vscsLocationOverride string, apiClient apiClient) <-chan locationResult {
287297
ch := make(chan locationResult, 1)
298+
299+
// Developer override is set, return the override
300+
if vscsLocationOverride != "" {
301+
ch <- locationResult{vscsLocationOverride, nil}
302+
return ch
303+
}
304+
305+
// Dynamically fetch the region location
288306
go func() {
289307
location, err := apiClient.GetCodespaceRegionLocation(ctx)
290308
ch <- locationResult{location, err}

0 commit comments

Comments
 (0)
X Tutup