Skip to content

Commit b07a7ce

Browse files
committed
Merge branch 'main' of https://github.com/coder/coder into bq/show-build-logs-on-template-create
2 parents e355d4c + da37654 commit b07a7ce

File tree

74 files changed

+2123
-1050
lines changed

Some content is hidden

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

74 files changed

+2123
-1050
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ coderd/apidoc/swagger.json linguist-generated=true
66
coderd/database/dump.sql linguist-generated=true
77
peerbroker/proto/*.go linguist-generated=true
88
provisionerd/proto/*.go linguist-generated=true
9+
provisionerd/proto/version.go linguist-generated=false
910
provisionersdk/proto/*.go linguist-generated=true
1011
*.tfplan.json linguist-generated=true
1112
*.tfstate.json linguist-generated=true
1213
*.tfstate.dot linguist-generated=true
1314
*.tfplan.dot linguist-generated=true
15+
site/e2e/provisionerGenerated.ts linguist-generated=true
1416
site/src/api/typesGenerated.ts linguist-generated=true
1517
site/src/pages/SetupPage/countries.tsx linguist-generated=true

cli/clitest/golden.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ func prepareTestData(t *testing.T) (*codersdk.Client, map[string]string) {
167167
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
168168
defer cancel()
169169

170-
db, pubsub := dbtestutil.NewDB(t)
170+
// This needs to be a fixed timezone because timezones increase the length
171+
// of timestamp strings. The increased length can pad table formatting's
172+
// and differ the table header spacings.
173+
//nolint:gocritic
174+
db, pubsub := dbtestutil.NewDB(t, dbtestutil.WithTimezone("UTC"))
171175
rootClient := coderdtest.New(t, &coderdtest.Options{
172176
Database: db,
173177
Pubsub: pubsub,

cli/cliui/output.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TableFormat(out any, defaultColumns []string) OutputFormat {
106106
}
107107

108108
// Get the list of table column headers.
109-
headers, defaultSort, err := typeToTableHeaders(v.Type().Elem())
109+
headers, defaultSort, err := typeToTableHeaders(v.Type().Elem(), true)
110110
if err != nil {
111111
panic("parse table headers: " + err.Error())
112112
}

cli/cliui/table.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func DisplayTable(out any, sort string, filterColumns []string) (string, error)
7070
}
7171

7272
// Get the list of table column headers.
73-
headersRaw, defaultSort, err := typeToTableHeaders(v.Type().Elem())
73+
headersRaw, defaultSort, err := typeToTableHeaders(v.Type().Elem(), true)
7474
if err != nil {
7575
return "", xerrors.Errorf("get table headers recursively for type %q: %w", v.Type().Elem().String(), err)
7676
}
@@ -230,7 +230,11 @@ func isStructOrStructPointer(t reflect.Type) bool {
230230
// typeToTableHeaders converts a type to a slice of column names. If the given
231231
// type is invalid (not a struct or a pointer to a struct, has invalid table
232232
// tags, etc.), an error is returned.
233-
func typeToTableHeaders(t reflect.Type) ([]string, string, error) {
233+
//
234+
// requireDefault is only needed for the root call. This is recursive, so nested
235+
// structs do not need the default sort name.
236+
// nolint:revive
237+
func typeToTableHeaders(t reflect.Type, requireDefault bool) ([]string, string, error) {
234238
if !isStructOrStructPointer(t) {
235239
return nil, "", xerrors.Errorf("typeToTableHeaders called with a non-struct or a non-pointer-to-a-struct type")
236240
}
@@ -246,6 +250,12 @@ func typeToTableHeaders(t reflect.Type) ([]string, string, error) {
246250
if err != nil {
247251
return nil, "", xerrors.Errorf("parse struct tags for field %q in type %q: %w", field.Name, t.String(), err)
248252
}
253+
254+
if name == "" && (recursive && skip) {
255+
return nil, "", xerrors.Errorf("a name is required for the field %q. "+
256+
"recursive_line will ensure this is never shown to the user, but is still needed", field.Name)
257+
}
258+
// If recurse and skip is set, the name is intentionally empty.
249259
if name == "" {
250260
continue
251261
}
@@ -262,7 +272,7 @@ func typeToTableHeaders(t reflect.Type) ([]string, string, error) {
262272
return nil, "", xerrors.Errorf("field %q in type %q is marked as recursive but does not contain a struct or a pointer to a struct", field.Name, t.String())
263273
}
264274

265-
childNames, _, err := typeToTableHeaders(fieldType)
275+
childNames, defaultSort, err := typeToTableHeaders(fieldType, false)
266276
if err != nil {
267277
return nil, "", xerrors.Errorf("get child field header names for field %q in type %q: %w", field.Name, fieldType.String(), err)
268278
}
@@ -273,13 +283,16 @@ func typeToTableHeaders(t reflect.Type) ([]string, string, error) {
273283
}
274284
headers = append(headers, fullName)
275285
}
286+
if defaultSortName == "" {
287+
defaultSortName = defaultSort
288+
}
276289
continue
277290
}
278291

279292
headers = append(headers, name)
280293
}
281294

282-
if defaultSortName == "" {
295+
if defaultSortName == "" && requireDefault {
283296
return nil, "", xerrors.Errorf("no field marked as default_sort in type %q", t.String())
284297
}
285298

cli/cliui/table_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ type tableTest2 struct {
4646

4747
type tableTest3 struct {
4848
NotIncluded string // no table tag
49-
Sub tableTest2 `table:"inner,recursive,default_sort"`
49+
Sub tableTest2 `table:"inner,recursive"`
5050
}
5151

5252
type tableTest4 struct {
5353
Inline tableTest2 `table:"ignored,recursive_inline"`
54-
SortField string `table:"sort_field,default_sort"`
54+
SortField string `table:"sort_field"`
5555
}
5656

5757
func Test_DisplayTable(t *testing.T) {

cli/config/file.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"io"
55
"os"
66
"path/filepath"
7+
"strings"
78

89
"github.com/kirsle/configdir"
910
"golang.org/x/xerrors"
@@ -85,13 +86,14 @@ func (f File) Write(s string) error {
8586
return write(string(f), 0o600, []byte(s))
8687
}
8788

88-
// Read reads the file to a string.
89+
// Read reads the file to a string. All leading and trailing whitespace
90+
// is removed.
8991
func (f File) Read() (string, error) {
9092
if f == "" {
9193
return "", xerrors.Errorf("empty file path")
9294
}
9395
byt, err := read(string(f))
94-
return string(byt), err
96+
return strings.TrimSpace(string(byt)), err
9597
}
9698

9799
// open opens a file in the configuration directory,

cli/create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ func TestCreateWithGitAuth(t *testing.T) {
803803
{
804804
Type: &proto.Response_Plan{
805805
Plan: &proto.PlanComplete{
806-
ExternalAuthProviders: []string{"github"},
806+
ExternalAuthProviders: []*proto.ExternalAuthProviderResource{{Id: "github"}},
807807
},
808808
},
809809
},

cli/root_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func TestCommandHelp(t *testing.T) {
5151
Name: "coder users list --output json",
5252
Cmd: []string{"users", "list", "--output", "json"},
5353
},
54+
clitest.CommandHelpCase{
55+
Name: "coder users list",
56+
Cmd: []string{"users", "list"},
57+
},
5458
))
5559
}
5660

cli/ssh_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,9 @@ func TestSSH(t *testing.T) {
455455
assert.NoError(t, err)
456456
})
457457

458-
tGo(t, func() {
459-
// When the agent connects, the workspace was started, and we should
460-
// have access to the shell.
461-
_ = agenttest.New(t, client.URL, authToken)
462-
coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
463-
})
458+
// When the agent connects, the workspace was started, and we should
459+
// have access to the shell.
460+
_ = agenttest.New(t, client.URL, authToken)
464461

465462
conn, channels, requests, err := ssh.NewClientConn(&stdioConn{
466463
Reader: proxyCommandStdoutR,

cli/testdata/coder_users_list.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
USERNAME EMAIL CREATED AT STATUS
2+
testuser testuser@coder.com [timestamp] active
3+
testuser2 testuser2@coder.com [timestamp] dormant

cli/testdata/coder_users_list_--output_json.golden

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
{
33
"id": "[first user ID]",
44
"username": "testuser",
5+
"avatar_url": "",
56
"name": "",
67
"email": "testuser@coder.com",
78
"created_at": "[timestamp]",
89
"last_seen_at": "[timestamp]",
910
"status": "active",
11+
"login_type": "password",
12+
"theme_preference": "",
1013
"organization_ids": [
1114
"[first org ID]"
1215
],
@@ -15,25 +18,22 @@
1518
"name": "owner",
1619
"display_name": "Owner"
1720
}
18-
],
19-
"avatar_url": "",
20-
"login_type": "password",
21-
"theme_preference": ""
21+
]
2222
},
2323
{
2424
"id": "[second user ID]",
2525
"username": "testuser2",
26+
"avatar_url": "",
2627
"name": "",
2728
"email": "testuser2@coder.com",
2829
"created_at": "[timestamp]",
2930
"last_seen_at": "[timestamp]",
3031
"status": "dormant",
32+
"login_type": "password",
33+
"theme_preference": "",
3134
"organization_ids": [
3235
"[first org ID]"
3336
],
34-
"roles": [],
35-
"avatar_url": "",
36-
"login_type": "password",
37-
"theme_preference": ""
37+
"roles": []
3838
}
3939
]

coderd/apidoc/docs.go

Lines changed: 59 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 51 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)