X Tutup
Skip to content

Commit 514448d

Browse files
committed
Merge branch 'main' of github.com:github/ghcs into jg/ssh-cmd-flags
2 parents c5bd8c4 + 10ad854 commit 514448d

File tree

12 files changed

+58
-52
lines changed

12 files changed

+58
-52
lines changed

cmd/ghcs/code.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/url"
77
"os"
88

9-
"github.com/github/ghcs/api"
9+
"github.com/github/ghcs/internal/api"
1010
"github.com/skratchdot/open-golang/open"
1111
"github.com/spf13/cobra"
1212
)

cmd/ghcs/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/AlecAivazis/survey/v2"
1313
"github.com/AlecAivazis/survey/v2/terminal"
14-
"github.com/github/ghcs/api"
14+
"github.com/github/ghcs/internal/api"
1515
"golang.org/x/term"
1616
)
1717

cmd/ghcs/create.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
"github.com/AlecAivazis/survey/v2"
1111
"github.com/fatih/camelcase"
12-
"github.com/github/ghcs/api"
1312
"github.com/github/ghcs/cmd/ghcs/output"
13+
"github.com/github/ghcs/internal/api"
1414
"github.com/github/ghcs/internal/codespaces"
1515
"github.com/spf13/cobra"
1616
)
@@ -105,12 +105,16 @@ func create(opts *createOptions) error {
105105
return nil
106106
}
107107

108+
// showStatus polls the codespace for a list of post create states and their status. It will keep polling
109+
// until all states have finished. Once all states have finished, we poll once more to check if any new
110+
// states have been introduced and stop polling otherwise.
108111
func showStatus(ctx context.Context, log *output.Logger, apiClient *api.API, user *api.User, codespace *api.Codespace) error {
109112
var lastState codespaces.PostCreateState
110113
var breakNextState bool
111114

112115
finishedStates := make(map[string]bool)
113116
ctx, stopPolling := context.WithCancel(ctx)
117+
defer stopPolling()
114118

115119
poller := func(states []codespaces.PostCreateState) {
116120
var inProgress bool
@@ -153,7 +157,12 @@ func showStatus(ctx context.Context, log *output.Logger, apiClient *api.API, use
153157
}
154158
}
155159

156-
if err := codespaces.PollPostCreateStates(ctx, log, apiClient, user, codespace, poller); err != nil {
160+
err := codespaces.PollPostCreateStates(ctx, log, apiClient, user, codespace, poller)
161+
if err != nil {
162+
if errors.Is(err, context.Canceled) && breakNextState {
163+
return nil // we cancelled the context to stop polling, we can ignore the error
164+
}
165+
157166
return fmt.Errorf("failed to poll state changes from codespace: %v", err)
158167
}
159168

cmd/ghcs/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"os"
88
"strings"
99

10-
"github.com/github/ghcs/api"
1110
"github.com/github/ghcs/cmd/ghcs/output"
11+
"github.com/github/ghcs/internal/api"
1212
"github.com/spf13/cobra"
1313
)
1414

cmd/ghcs/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/github/ghcs/api"
98
"github.com/github/ghcs/cmd/ghcs/output"
9+
"github.com/github/ghcs/internal/api"
1010
"github.com/spf13/cobra"
1111
)
1212

cmd/ghcs/logs.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"net"
77
"os"
88

9-
"github.com/github/ghcs/api"
109
"github.com/github/ghcs/cmd/ghcs/output"
10+
"github.com/github/ghcs/internal/api"
1111
"github.com/github/ghcs/internal/codespaces"
1212
"github.com/github/go-liveshare"
1313
"github.com/spf13/cobra"
@@ -70,7 +70,8 @@ func logs(ctx context.Context, log *output.Logger, codespaceName string, follow
7070
defer listen.Close()
7171
localPort := listen.Addr().(*net.TCPAddr).Port
7272

73-
remoteSSHServerPort, sshUser, err := codespaces.StartSSHServer(ctx, session, log)
73+
log.Println("Fetching SSH Details...")
74+
remoteSSHServerPort, sshUser, err := session.StartSSHServer(ctx)
7475
if err != nil {
7576
return fmt.Errorf("error getting ssh server details: %v", err)
7677
}

cmd/ghcs/ports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"strconv"
1212
"strings"
1313

14-
"github.com/github/ghcs/api"
1514
"github.com/github/ghcs/cmd/ghcs/output"
15+
"github.com/github/ghcs/internal/api"
1616
"github.com/github/ghcs/internal/codespaces"
1717
"github.com/github/go-liveshare"
1818
"github.com/muhammadmuzzammil1998/jsonc"

cmd/ghcs/ssh.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"net"
77
"os"
88

9-
"github.com/github/ghcs/api"
109
"github.com/github/ghcs/cmd/ghcs/output"
10+
"github.com/github/ghcs/internal/api"
1111
"github.com/github/ghcs/internal/codespaces"
1212
"github.com/github/go-liveshare"
1313
"github.com/spf13/cobra"
@@ -59,7 +59,8 @@ func ssh(ctx context.Context, sshArgs []string, sshProfile, codespaceName string
5959
return fmt.Errorf("error connecting to Live Share: %v", err)
6060
}
6161

62-
remoteSSHServerPort, sshUser, err := codespaces.StartSSHServer(ctx, session, log)
62+
log.Println("Fetching SSH Details...")
63+
remoteSSHServerPort, sshUser, err := session.StartSSHServer(ctx)
6364
if err != nil {
6465
return fmt.Errorf("error getting ssh server details: %v", err)
6566
}

api/api.go renamed to internal/api/api.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// TODO(adonovan): rename to package codespaces, and codespaces.Client.
21
package api
32

43
// For descriptions of service interfaces, see:
@@ -7,6 +6,24 @@ package api
76
// - https://github.com/github/github/blob/master/app/api/codespaces.rb (for vscs_internal)
87
// TODO(adonovan): replace the last link with a public doc URL when available.
98

9+
// TODO(adonovan): a possible reorganization would be to split this
10+
// file into three internal packages, one per backend service, and to
11+
// rename api.API to github.Client:
12+
//
13+
// - github.GetUser(github.Client)
14+
// - github.GetRepository(Client)
15+
// - github.ReadFile(Client, nwo, branch, path) // was GetCodespaceRepositoryContents
16+
// - codespaces.Create(Client, user, repo, sku, branch, location)
17+
// - codespaces.Delete(Client, user, token, name)
18+
// - codespaces.Get(Client, token, owner, name)
19+
// - codespaces.GetMachineTypes(Client, user, repo, branch, location)
20+
// - codespaces.GetToken(Client, login, name)
21+
// - codespaces.List(Client, user)
22+
// - codespaces.Start(Client, token, codespace)
23+
// - visualstudio.GetRegionLocation(http.Client) // no dependency on github
24+
//
25+
// This would make the meaning of each operation clearer.
26+
1027
import (
1128
"bytes"
1229
"context"

internal/codespaces/codespaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77
"time"
88

9-
"github.com/github/ghcs/api"
9+
"github.com/github/ghcs/internal/api"
1010
"github.com/github/go-liveshare"
1111
)
1212

0 commit comments

Comments
 (0)
X Tutup