Skip to content

Commit 9ab1f96

Browse files
committed
chore: Merge branch 'main' of github.com:coder/coder into bq/755/account-page
2 parents 19579eb + d9d4599 commit 9ab1f96

23 files changed

+332
-105
lines changed

.github/workflows/coder.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ concurrency:
2626
jobs:
2727
style-lint-golangci:
2828
name: style/lint/golangci
29+
timeout-minutes: 5
2930
runs-on: ubuntu-latest
3031
steps:
3132
- uses: actions/checkout@v3
@@ -39,6 +40,7 @@ jobs:
3940

4041
style-lint-typescript:
4142
name: "style/lint/typescript"
43+
timeout-minutes: 5
4244
runs-on: ubuntu-latest
4345
steps:
4446
- name: Checkout
@@ -64,6 +66,7 @@ jobs:
6466

6567
gen:
6668
name: "style/gen"
69+
timeout-minutes: 5
6770
runs-on: ubuntu-latest
6871
steps:
6972
- uses: actions/checkout@v3
@@ -87,6 +90,7 @@ jobs:
8790
style-fmt:
8891
name: "style/fmt"
8992
runs-on: ubuntu-latest
93+
timeout-minutes: 5
9094
steps:
9195
- name: Checkout
9296
uses: actions/checkout@v3
@@ -114,6 +118,7 @@ jobs:
114118
test-go:
115119
name: "test/go"
116120
runs-on: ${{ matrix.os }}
121+
timeout-minutes: 20
117122
strategy:
118123
matrix:
119124
os:
@@ -192,6 +197,7 @@ jobs:
192197
test-go-postgres:
193198
name: "test/go/postgres"
194199
runs-on: ubuntu-latest
200+
timeout-minutes: 20
195201
steps:
196202
- uses: actions/checkout@v3
197203

@@ -277,6 +283,7 @@ jobs:
277283
deploy:
278284
name: "deploy"
279285
runs-on: ubuntu-latest
286+
timeout-minutes: 20
280287
if: github.ref == 'refs/heads/main' && github.repository_owner == 'coder'
281288
permissions:
282289
contents: read
@@ -352,6 +359,7 @@ jobs:
352359
test-js:
353360
name: "test/js"
354361
runs-on: ubuntu-latest
362+
timeout-minutes: 20
355363
steps:
356364
- uses: actions/checkout@v3
357365

@@ -404,6 +412,7 @@ jobs:
404412
test-e2e:
405413
name: "test/e2e/${{ matrix.os }}"
406414
runs-on: ${{ matrix.os }}
415+
timeout-minutes: 20
407416
strategy:
408417
matrix:
409418
os:

coderd/coderd.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"time"
1010

1111
"github.com/go-chi/chi/v5"
12-
"github.com/go-chi/render"
1312
"google.golang.org/api/idtoken"
1413

1514
chitrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi.v5"
@@ -67,8 +66,7 @@ func New(options *Options) (http.Handler, func()) {
6766
})
6867
r.Route("/buildinfo", func(r chi.Router) {
6968
r.Get("/", func(rw http.ResponseWriter, r *http.Request) {
70-
render.Status(r, http.StatusOK)
71-
render.JSON(rw, r, codersdk.BuildInfoResponse{
69+
httpapi.Write(rw, http.StatusOK, codersdk.BuildInfoResponse{
7270
ExternalURL: buildinfo.ExternalURL(),
7371
Version: buildinfo.Version(),
7472
})
@@ -150,6 +148,7 @@ func New(options *Options) (http.Handler, func()) {
150148
r.Route("/{user}", func(r chi.Router) {
151149
r.Use(httpmw.ExtractUserParam(options.Database))
152150
r.Get("/", api.userByName)
151+
r.Put("/profile", api.putUserProfile)
153152
r.Get("/organizations", api.organizationsByUser)
154153
r.Post("/organizations", api.postOrganizationsByUser)
155154
r.Post("/keys", api.postAPIKey)

coderd/database/databasefake/databasefake.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,23 @@ func (q *fakeQuerier) InsertUser(_ context.Context, arg database.InsertUserParam
10501050
return user, nil
10511051
}
10521052

1053+
func (q *fakeQuerier) UpdateUserProfile(_ context.Context, arg database.UpdateUserProfileParams) (database.User, error) {
1054+
q.mutex.Lock()
1055+
defer q.mutex.Unlock()
1056+
1057+
for index, user := range q.users {
1058+
if user.ID != arg.ID {
1059+
continue
1060+
}
1061+
user.Name = arg.Name
1062+
user.Email = arg.Email
1063+
user.Username = arg.Username
1064+
q.users[index] = user
1065+
return user, nil
1066+
}
1067+
return database.User{}, sql.ErrNoRows
1068+
}
1069+
10531070
func (q *fakeQuerier) InsertWorkspace(_ context.Context, arg database.InsertWorkspaceParams) (database.Workspace, error) {
10541071
q.mutex.Lock()
10551072
defer q.mutex.Unlock()

coderd/database/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

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

coderd/database/queries/users.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,14 @@ INSERT INTO
4040
)
4141
VALUES
4242
($1, $2, $3, $4, FALSE, $5, $6, $7, $8) RETURNING *;
43+
44+
-- name: UpdateUserProfile :one
45+
UPDATE
46+
users
47+
SET
48+
email = $2,
49+
"name" = $3,
50+
username = $4,
51+
updated_at = $5
52+
WHERE
53+
id = $1 RETURNING *;

coderd/files.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"net/http"
1111

1212
"github.com/go-chi/chi/v5"
13-
"github.com/go-chi/render"
1413

1514
"github.com/coder/coder/coderd/database"
1615
"github.com/coder/coder/coderd/httpapi"
@@ -44,8 +43,7 @@ func (api *api) postFile(rw http.ResponseWriter, r *http.Request) {
4443
file, err := api.Database.GetFileByHash(r.Context(), hash)
4544
if err == nil {
4645
// The file already exists!
47-
render.Status(r, http.StatusOK)
48-
render.JSON(rw, r, codersdk.UploadResponse{
46+
httpapi.Write(rw, http.StatusOK, codersdk.UploadResponse{
4947
Hash: file.Hash,
5048
})
5149
return
@@ -63,8 +61,8 @@ func (api *api) postFile(rw http.ResponseWriter, r *http.Request) {
6361
})
6462
return
6563
}
66-
render.Status(r, http.StatusCreated)
67-
render.JSON(rw, r, codersdk.UploadResponse{
64+
65+
httpapi.Write(rw, http.StatusCreated, codersdk.UploadResponse{
6866
Hash: file.Hash,
6967
})
7068
}

coderd/gitsshkey.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"fmt"
55
"net/http"
66

7-
"github.com/go-chi/render"
8-
97
"github.com/coder/coder/coderd/database"
108
"github.com/coder/coder/coderd/gitsshkey"
119
"github.com/coder/coder/coderd/httpapi"
@@ -44,8 +42,7 @@ func (api *api) regenerateGitSSHKey(rw http.ResponseWriter, r *http.Request) {
4442
return
4543
}
4644

47-
render.Status(r, http.StatusOK)
48-
render.JSON(rw, r, codersdk.GitSSHKey{
45+
httpapi.Write(rw, http.StatusOK, codersdk.GitSSHKey{
4946
UserID: newKey.UserID,
5047
CreatedAt: newKey.CreatedAt,
5148
UpdatedAt: newKey.UpdatedAt,
@@ -64,8 +61,7 @@ func (api *api) gitSSHKey(rw http.ResponseWriter, r *http.Request) {
6461
return
6562
}
6663

67-
render.Status(r, http.StatusOK)
68-
render.JSON(rw, r, codersdk.GitSSHKey{
64+
httpapi.Write(rw, http.StatusOK, codersdk.GitSSHKey{
6965
UserID: gitSSHKey.UserID,
7066
CreatedAt: gitSSHKey.CreatedAt,
7167
UpdatedAt: gitSSHKey.UpdatedAt,
@@ -108,8 +104,7 @@ func (api *api) agentGitSSHKey(rw http.ResponseWriter, r *http.Request) {
108104
return
109105
}
110106

111-
render.Status(r, http.StatusOK)
112-
render.JSON(rw, r, codersdk.AgentGitSSHKey{
107+
httpapi.Write(rw, http.StatusOK, codersdk.AgentGitSSHKey{
113108
PrivateKey: gitSSHKey.PrivateKey,
114109
})
115110
}

coderd/httpapi/httpapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type Error struct {
6363
}
6464

6565
// Write outputs a standardized format to an HTTP response body.
66-
func Write(rw http.ResponseWriter, status int, response Response) {
66+
func Write(rw http.ResponseWriter, status int, response interface{}) {
6767
buf := &bytes.Buffer{}
6868
enc := json.NewEncoder(buf)
6969
enc.SetEscapeHTML(true)

coderd/httpmw/ratelimit.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"time"
66

77
"github.com/go-chi/httprate"
8-
"github.com/go-chi/render"
98

109
"github.com/coder/coder/coderd/database"
1110
"github.com/coder/coder/coderd/httpapi"
@@ -26,8 +25,7 @@ func RateLimitPerMinute(count int) func(http.Handler) http.Handler {
2625
return httprate.KeyByIP(r)
2726
}, httprate.KeyByEndpoint),
2827
httprate.WithLimitHandler(func(w http.ResponseWriter, r *http.Request) {
29-
render.Status(r, http.StatusTooManyRequests)
30-
render.JSON(w, r, httpapi.Response{
28+
httpapi.Write(w, http.StatusTooManyRequests, httpapi.Response{
3129
Message: "You've been rate limited for sending too many requests!",
3230
})
3331
}),

0 commit comments

Comments
 (0)