Skip to content

Commit c83c6a8

Browse files
committed
Merge branch 'trunk' into repo-rename
2 parents b4d2bce + cbd6569 commit c83c6a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+621
-580
lines changed

api/export_pr.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66
)
77

8-
func (issue *Issue) ExportData(fields []string) *map[string]interface{} {
8+
func (issue *Issue) ExportData(fields []string) map[string]interface{} {
99
v := reflect.ValueOf(issue).Elem()
1010
data := map[string]interface{}{}
1111

@@ -25,10 +25,10 @@ func (issue *Issue) ExportData(fields []string) *map[string]interface{} {
2525
}
2626
}
2727

28-
return &data
28+
return data
2929
}
3030

31-
func (pr *PullRequest) ExportData(fields []string) *map[string]interface{} {
31+
func (pr *PullRequest) ExportData(fields []string) map[string]interface{} {
3232
v := reflect.ValueOf(pr).Elem()
3333
data := map[string]interface{}{}
3434

@@ -102,7 +102,7 @@ func (pr *PullRequest) ExportData(fields []string) *map[string]interface{} {
102102
}
103103
}
104104

105-
return &data
105+
return data
106106
}
107107

108108
func fieldByName(v reflect.Value, field string) reflect.Value {

api/export_repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"reflect"
55
)
66

7-
func (repo *Repository) ExportData(fields []string) *map[string]interface{} {
7+
func (repo *Repository) ExportData(fields []string) map[string]interface{} {
88
v := reflect.ValueOf(repo).Elem()
99
data := map[string]interface{}{}
1010

@@ -38,7 +38,7 @@ func (repo *Repository) ExportData(fields []string) *map[string]interface{} {
3838
}
3939
}
4040

41-
return &data
41+
return data
4242
}
4343

4444
func miniRepoExport(r *Repository) map[string]interface{} {

cmd/gh/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ check your internet connection or https://githubstatus.com
4949
{
5050
name: "Cobra flag error",
5151
args: args{
52-
err: &cmdutil.FlagError{Err: errors.New("unknown flag --foo")},
52+
err: cmdutil.FlagErrorf("unknown flag --foo"),
5353
cmd: cmd,
5454
debug: false,
5555
},

docs/project-layout.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ and talk through which code gets run in order.
6060

6161
## How to add a new command
6262

63-
0. First, check on our issue tracker to verify that our team had approved the plans for a new command.
64-
1. Create a package for the new command, e.g. for a new command `gh boom` create the following directory
63+
1. First, check on our issue tracker to verify that our team had approved the plans for a new command.
64+
2. Create a package for the new command, e.g. for a new command `gh boom` create the following directory
6565
structure: `pkg/cmd/boom/`
66-
2. The new package should expose a method, e.g. `NewCmdBoom()`, that accepts a `*cmdutil.Factory` type and
66+
3. The new package should expose a method, e.g. `NewCmdBoom()`, that accepts a `*cmdutil.Factory` type and
6767
returns a `*cobra.Command`.
6868
* Any logic specific to this command should be kept within the command's package and not added to any
6969
"global" packages like `api` or `utils`.
70-
3. Use the method from the previous step to generate the command and add it to the command tree, typically
70+
4. Use the method from the previous step to generate the command and add it to the command tree, typically
7171
somewhere in the `NewCmdRoot()` method.
7272

7373
## How to write tests

docs/releasing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ If the build fails, there is not a clean way to re-run it. The easiest way would
3131

3232
A local release can be created for testing without creating anything official on the release page.
3333

34-
0. Make sure GoReleaser is installed: `brew install goreleaser`
35-
1. `goreleaser --skip-validate --skip-publish --rm-dist`
36-
2. Find the built products under `dist/`.
34+
1. Make sure GoReleaser is installed: `brew install goreleaser`
35+
2. `goreleaser --skip-validate --skip-publish --rm-dist`
36+
3. Find the built products under `dist/`.

docs/source.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# Installation from source
22

3-
0. Verify that you have Go 1.16+ installed
3+
1. Verify that you have Go 1.16+ installed
44

55
```sh
66
$ go version
77
```
88

99
If `go` is not installed, follow instructions on [the Go website](https://golang.org/doc/install).
1010

11-
1. Clone this repository
11+
2. Clone this repository
1212

1313
```sh
1414
$ git clone https://github.com/cli/cli.git gh-cli
1515
$ cd gh-cli
1616
```
1717

18-
2. Build and install
18+
3. Build and install
1919

2020
#### Unix-like systems
2121
```sh
@@ -33,7 +33,7 @@
3333
```
3434
There is no install step available on Windows.
3535

36-
3. Run `gh version` to check if it worked.
36+
4. Run `gh version` to check if it worked.
3737

3838
#### Windows
3939
Run `bin\gh version` to check if it worked.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ require (
2323
github.com/mattn/go-colorable v0.1.11
2424
github.com/mattn/go-isatty v0.0.14
2525
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
26+
github.com/microcosm-cc/bluemonday v1.0.16 // indirect
2627
github.com/muesli/reflow v0.2.1-0.20210502190812-c80126ec2ad5
2728
github.com/muesli/termenv v0.9.0
2829
github.com/muhammadmuzzammil1998/jsonc v0.0.0-20201229145248-615b0916ca38
29-
github.com/olekukonko/tablewriter v0.0.5
3030
github.com/opentracing/opentracing-go v1.1.0
3131
github.com/shurcooL/githubv4 v0.0.0-20200928013246-d292edc3691b
3232
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh
263263
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
264264
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
265265
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
266-
github.com/microcosm-cc/bluemonday v1.0.6 h1:ZOvqHKtnx0fUpnbQm3m3zKFWE+DRC+XB1onh8JoEObE=
267266
github.com/microcosm-cc/bluemonday v1.0.6/go.mod h1:HOT/6NaBlR0f9XlxD3zolN6Z3N8Lp4pvhp+jLS5ihnI=
267+
github.com/microcosm-cc/bluemonday v1.0.16 h1:kHmAq2t7WPWLjiGvzKa5o3HzSfahUKiOq7fAPUiMNIc=
268+
github.com/microcosm-cc/bluemonday v1.0.16/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM=
268269
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
269270
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
270271
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
@@ -432,8 +433,9 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
432433
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
433434
golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
434435
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
435-
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 h1:Ugb8sMTWuWRC3+sz5WeN/4kejDx9BvIwnPUiJBjJE+8=
436436
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
437+
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
438+
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
437439
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
438440
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
439441
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

internal/codespaces/api/api.go

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"io/ioutil"
3636
"net/http"
3737
"net/url"
38+
"reflect"
3839
"regexp"
3940
"strconv"
4041
"strings"
@@ -104,8 +105,9 @@ func (a *API) GetUser(ctx context.Context) (*User, error) {
104105

105106
// Repository represents a GitHub repository.
106107
type Repository struct {
107-
ID int `json:"id"`
108-
FullName string `json:"full_name"`
108+
ID int `json:"id"`
109+
FullName string `json:"full_name"`
110+
DefaultBranch string `json:"default_branch"`
109111
}
110112

111113
// GetRepository returns the repository associated with the given owner and name.
@@ -162,6 +164,10 @@ type CodespaceGitStatus struct {
162164
const (
163165
// CodespaceStateAvailable is the state for a running codespace environment.
164166
CodespaceStateAvailable = "Available"
167+
// CodespaceStateShutdown is the state for a shutdown codespace environment.
168+
CodespaceStateShutdown = "Shutdown"
169+
// CodespaceStateStarting is the state for a starting codespace environment.
170+
CodespaceStateStarting = "Starting"
165171
)
166172

167173
type CodespaceConnection struct {
@@ -172,6 +178,44 @@ type CodespaceConnection struct {
172178
HostPublicKeys []string `json:"hostPublicKeys"`
173179
}
174180

181+
// CodespaceFields is the list of exportable fields for a codespace.
182+
var CodespaceFields = []string{
183+
"name",
184+
"owner",
185+
"repository",
186+
"state",
187+
"gitStatus",
188+
"createdAt",
189+
"lastUsedAt",
190+
}
191+
192+
func (c *Codespace) ExportData(fields []string) map[string]interface{} {
193+
v := reflect.ValueOf(c).Elem()
194+
data := map[string]interface{}{}
195+
196+
for _, f := range fields {
197+
switch f {
198+
case "owner":
199+
data[f] = c.Owner.Login
200+
case "repository":
201+
data[f] = c.Repository.FullName
202+
case "gitStatus":
203+
data[f] = map[string]interface{}{
204+
"ref": c.GitStatus.Ref,
205+
"hasUnpushedChanges": c.GitStatus.HasUnpushedChanges,
206+
"hasUncommitedChanges": c.GitStatus.HasUncommitedChanges,
207+
}
208+
default:
209+
sf := v.FieldByNameFunc(func(s string) bool {
210+
return strings.EqualFold(f, s)
211+
})
212+
data[f] = sf.Interface()
213+
}
214+
}
215+
216+
return data
217+
}
218+
175219
// ListCodespaces returns a list of codespaces for the user. Pass a negative limit to request all pages from
176220
// the API until all codespaces have been fetched.
177221
func (a *API) ListCodespaces(ctx context.Context, limit int) (codespaces []*Codespace, err error) {

internal/codespaces/codespaces.go

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ import (
1010
"github.com/cli/cli/v2/pkg/liveshare"
1111
)
1212

13-
type logger interface {
14-
Print(v ...interface{}) (int, error)
15-
Println(v ...interface{}) (int, error)
16-
}
17-
18-
// TODO(josebalius): clean this up once we standardrize
19-
// logging for codespaces
20-
type liveshareLogger interface {
21-
Println(v ...interface{})
22-
Printf(f string, v ...interface{})
23-
}
24-
2513
func connectionReady(codespace *api.Codespace) bool {
2614
return codespace.Connection.SessionID != "" &&
2715
codespace.Connection.SessionToken != "" &&
@@ -35,43 +23,43 @@ type apiClient interface {
3523
StartCodespace(ctx context.Context, name string) error
3624
}
3725

26+
type progressIndicator interface {
27+
StartProgressIndicatorWithLabel(s string)
28+
StopProgressIndicator()
29+
}
30+
31+
type logger interface {
32+
Println(v ...interface{})
33+
Printf(f string, v ...interface{})
34+
}
35+
3836
// ConnectToLiveshare waits for a Codespace to become running,
3937
// and connects to it using a Live Share session.
40-
func ConnectToLiveshare(ctx context.Context, log logger, sessionLogger liveshareLogger, apiClient apiClient, codespace *api.Codespace) (*liveshare.Session, error) {
41-
var startedCodespace bool
38+
func ConnectToLiveshare(ctx context.Context, progress progressIndicator, sessionLogger logger, apiClient apiClient, codespace *api.Codespace) (sess *liveshare.Session, err error) {
4239
if codespace.State != api.CodespaceStateAvailable {
43-
startedCodespace = true
44-
log.Print("Starting your codespace...")
40+
progress.StartProgressIndicatorWithLabel("Starting codespace")
4541
if err := apiClient.StartCodespace(ctx, codespace.Name); err != nil {
4642
return nil, fmt.Errorf("error starting codespace: %w", err)
4743
}
4844
}
4945

5046
for retries := 0; !connectionReady(codespace); retries++ {
5147
if retries > 1 {
52-
if retries%2 == 0 {
53-
log.Print(".")
54-
}
55-
5648
time.Sleep(1 * time.Second)
5749
}
5850

5951
if retries == 30 {
6052
return nil, errors.New("timed out while waiting for the codespace to start")
6153
}
6254

63-
var err error
6455
codespace, err = apiClient.GetCodespace(ctx, codespace.Name, true)
6556
if err != nil {
6657
return nil, fmt.Errorf("error getting codespace: %w", err)
6758
}
6859
}
6960

70-
if startedCodespace {
71-
fmt.Print("\n")
72-
}
73-
74-
log.Println("Connecting to your codespace...")
61+
progress.StartProgressIndicatorWithLabel("Connecting to codespace")
62+
defer progress.StopProgressIndicator()
7563

7664
return liveshare.Connect(ctx, liveshare.Options{
7765
ClientName: "gh",

0 commit comments

Comments
 (0)