Skip to content

Commit f606a51

Browse files
committed
Merge branch 'main' into workspacepage
2 parents 53781e9 + b06ef0a commit f606a51

File tree

34 files changed

+1138
-222
lines changed

34 files changed

+1138
-222
lines changed

.github/workflows/coder.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
with:
4141
go-version: "~1.18"
4242
- name: golangci-lint
43-
uses: golangci/golangci-lint-action@v3.1.0
43+
uses: golangci/golangci-lint-action@v3.2.0
4444
with:
4545
version: v1.46.0
4646

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
fetch-depth: 0
2121

2222
- name: Set up QEMU
23-
uses: docker/setup-qemu-action@v1
23+
uses: docker/setup-qemu-action@v2
2424

2525
- name: Docker Login
2626
uses: docker/login-action@v1

cli/autostart.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ func autostartShow() *cobra.Command {
6363
return nil
6464
}
6565

66-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "schedule: %s\nnext: %s\n", workspace.AutostartSchedule, validSchedule.Next(time.Now()))
66+
next := validSchedule.Next(time.Now())
67+
loc, _ := time.LoadLocation(validSchedule.Timezone())
68+
69+
_, _ = fmt.Fprintf(cmd.OutOrStdout(),
70+
"schedule: %s\ntimezone: %s\nnext: %s\n",
71+
validSchedule.Cron(),
72+
validSchedule.Timezone(),
73+
next.In(loc),
74+
)
6775

6876
return nil
6977
},

cli/autostart_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func TestAutostart(t *testing.T) {
4545

4646
err = cmd.Execute()
4747
require.NoError(t, err, "unexpected error")
48-
require.Contains(t, stdoutBuf.String(), "schedule: "+sched)
48+
// CRON_TZ gets stripped
49+
require.Contains(t, stdoutBuf.String(), "schedule: 30 17 * * 1-5")
4950
})
5051

5152
t.Run("EnableDisableOK", func(t *testing.T) {

cli/autostop.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ func autostopShow() *cobra.Command {
6363
return nil
6464
}
6565

66-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "schedule: %s\nnext: %s\n", workspace.AutostopSchedule, validSchedule.Next(time.Now()))
66+
next := validSchedule.Next(time.Now())
67+
loc, _ := time.LoadLocation(validSchedule.Timezone())
68+
69+
_, _ = fmt.Fprintf(cmd.OutOrStdout(),
70+
"schedule: %s\ntimezone: %s\nnext: %s\n",
71+
validSchedule.Cron(),
72+
validSchedule.Timezone(),
73+
next.In(loc),
74+
)
6775

6876
return nil
6977
},

cli/autostop_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func TestAutostop(t *testing.T) {
4545

4646
err = cmd.Execute()
4747
require.NoError(t, err, "unexpected error")
48-
require.Contains(t, stdoutBuf.String(), "schedule: "+sched)
48+
// CRON_TZ gets stripped
49+
require.Contains(t, stdoutBuf.String(), "schedule: 30 17 * * 1-5")
4950
})
5051

5152
t.Run("EnableDisableOK", func(t *testing.T) {

cli/list.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/spf13/cobra"
1111

1212
"github.com/coder/coder/cli/cliui"
13+
"github.com/coder/coder/coderd/autobuild/schedule"
1314
"github.com/coder/coder/coderd/database"
1415
"github.com/coder/coder/codersdk"
1516
)
@@ -108,14 +109,18 @@ func list() *cobra.Command {
108109
durationDisplay = durationDisplay[:len(durationDisplay)-2]
109110
}
110111

111-
autostartDisplay := "not enabled"
112+
autostartDisplay := "-"
112113
if workspace.AutostartSchedule != "" {
113-
autostartDisplay = workspace.AutostartSchedule
114+
if sched, err := schedule.Weekly(workspace.AutostartSchedule); err == nil {
115+
autostartDisplay = sched.Cron()
116+
}
114117
}
115118

116-
autostopDisplay := "not enabled"
119+
autostopDisplay := "-"
117120
if workspace.AutostopSchedule != "" {
118-
autostopDisplay = workspace.AutostopSchedule
121+
if sched, err := schedule.Weekly(workspace.AutostopSchedule); err == nil {
122+
autostopDisplay = sched.Cron()
123+
}
119124
}
120125

121126
user := usersByID[workspace.OwnerID]

coderd/audit/diff.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package audit
22

33
import (
4+
"database/sql"
45
"fmt"
56
"reflect"
7+
8+
"github.com/google/uuid"
69
)
710

811
// TODO: this might need to be in the database package.
@@ -64,6 +67,11 @@ func diffValues[T any](left, right T, table Table) Map {
6467
continue
6568
}
6669

70+
// coerce struct types that would produce bad diffs.
71+
if leftI, rightI, ok = convertDiffType(leftI, rightI); ok {
72+
leftF, rightF = reflect.ValueOf(leftI), reflect.ValueOf(rightI)
73+
}
74+
6775
// If the field is a pointer, dereference it. Nil pointers are coerced
6876
// to the zero value of their underlying type.
6977
if leftF.Kind() == reflect.Ptr && rightF.Kind() == reflect.Ptr {
@@ -90,6 +98,36 @@ func diffValues[T any](left, right T, table Table) Map {
9098
return baseDiff
9199
}
92100

101+
// convertDiffType converts external struct types to primitive types.
102+
//nolint:forcetypeassert
103+
func convertDiffType(left, right any) (newLeft, newRight any, changed bool) {
104+
switch typed := left.(type) {
105+
case uuid.UUID:
106+
return typed.String(), right.(uuid.UUID).String(), true
107+
108+
case uuid.NullUUID:
109+
leftStr, _ := typed.MarshalText()
110+
rightStr, _ := right.(uuid.NullUUID).MarshalText()
111+
return string(leftStr), string(rightStr), true
112+
113+
case sql.NullString:
114+
leftStr := typed.String
115+
if !typed.Valid {
116+
leftStr = "null"
117+
}
118+
119+
rightStr := right.(sql.NullString).String
120+
if !right.(sql.NullString).Valid {
121+
rightStr = "null"
122+
}
123+
124+
return leftStr, rightStr, true
125+
126+
default:
127+
return left, right, false
128+
}
129+
}
130+
93131
// derefPointer deferences a reflect.Value that is a pointer to its underlying
94132
// value. It dereferences recursively until it finds a non-pointer value. If the
95133
// pointer is nil, it will be coerced to the zero value of the underlying type.

0 commit comments

Comments
 (0)