Skip to content

Commit 61d3729

Browse files
committed
feat: add README parsing to template versions
1 parent 9b1ef29 commit 61d3729

File tree

15 files changed

+214
-96
lines changed

15 files changed

+214
-96
lines changed

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
{
7474
"match": "database/queries/*.sql",
7575
"cmd": "make gen"
76+
},
77+
{
78+
"match": "provisionerd/proto/provisionerd.proto",
79+
"cmd": "make provisionerd/proto/provisionerd.pb.go",
7680
}
7781
]
7882
},

coderd/coderd.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ func New(options *Options) (http.Handler, func()) {
182182
r.Use(
183183
apiKeyMiddleware,
184184
httpmw.ExtractTemplateParam(options.Database),
185-
httpmw.ExtractOrganizationParam(options.Database),
186185
)
186+
187187
r.Get("/", api.template)
188188
r.Delete("/", api.deleteTemplate)
189189
r.Route("/versions", func(r chi.Router) {
@@ -196,7 +196,6 @@ func New(options *Options) (http.Handler, func()) {
196196
r.Use(
197197
apiKeyMiddleware,
198198
httpmw.ExtractTemplateVersionParam(options.Database),
199-
httpmw.ExtractOrganizationParam(options.Database),
200199
)
201200

202201
r.Get("/", api.templateVersion)

coderd/database/databasefake/databasefake.go

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sort"
77
"strings"
88
"sync"
9+
"time"
910

1011
"github.com/google/uuid"
1112
"golang.org/x/exp/slices"
@@ -1478,7 +1479,7 @@ func (q *fakeQuerier) UpdateTemplateActiveVersionByID(_ context.Context, arg dat
14781479
defer q.mutex.Unlock()
14791480

14801481
for index, template := range q.templates {
1481-
if template.ID.String() != arg.ID.String() {
1482+
if template.ID != arg.ID {
14821483
continue
14831484
}
14841485
template.ActiveVersionID = arg.ActiveVersionID
@@ -1493,7 +1494,7 @@ func (q *fakeQuerier) UpdateTemplateDeletedByID(_ context.Context, arg database.
14931494
defer q.mutex.Unlock()
14941495

14951496
for index, template := range q.templates {
1496-
if template.ID.String() != arg.ID.String() {
1497+
if template.ID != arg.ID {
14971498
continue
14981499
}
14991500
template.Deleted = arg.Deleted
@@ -1508,7 +1509,7 @@ func (q *fakeQuerier) UpdateTemplateVersionByID(_ context.Context, arg database.
15081509
defer q.mutex.Unlock()
15091510

15101511
for index, templateVersion := range q.templateVersions {
1511-
if templateVersion.ID.String() != arg.ID.String() {
1512+
if templateVersion.ID != arg.ID {
15121513
continue
15131514
}
15141515
templateVersion.TemplateID = arg.TemplateID
@@ -1519,12 +1520,28 @@ func (q *fakeQuerier) UpdateTemplateVersionByID(_ context.Context, arg database.
15191520
return sql.ErrNoRows
15201521
}
15211522

1523+
func (q *fakeQuerier) UpdateTemplateVersionDescriptionByJobID(_ context.Context, arg database.UpdateTemplateVersionDescriptionByJobIDParams) error {
1524+
q.mutex.Lock()
1525+
defer q.mutex.Unlock()
1526+
1527+
for index, templateVersion := range q.templateVersions {
1528+
if templateVersion.JobID != arg.JobID {
1529+
continue
1530+
}
1531+
templateVersion.Description = arg.Description
1532+
templateVersion.UpdatedAt = time.Now()
1533+
q.templateVersions[index] = templateVersion
1534+
return nil
1535+
}
1536+
return sql.ErrNoRows
1537+
}
1538+
15221539
func (q *fakeQuerier) UpdateProvisionerDaemonByID(_ context.Context, arg database.UpdateProvisionerDaemonByIDParams) error {
15231540
q.mutex.Lock()
15241541
defer q.mutex.Unlock()
15251542

15261543
for index, daemon := range q.provisionerDaemons {
1527-
if arg.ID.String() != daemon.ID.String() {
1544+
if arg.ID != daemon.ID {
15281545
continue
15291546
}
15301547
daemon.UpdatedAt = arg.UpdatedAt
@@ -1540,7 +1557,7 @@ func (q *fakeQuerier) UpdateWorkspaceAgentConnectionByID(_ context.Context, arg
15401557
defer q.mutex.Unlock()
15411558

15421559
for index, agent := range q.provisionerJobAgents {
1543-
if agent.ID.String() != arg.ID.String() {
1560+
if agent.ID != arg.ID {
15441561
continue
15451562
}
15461563
agent.FirstConnectedAt = arg.FirstConnectedAt
@@ -1557,7 +1574,7 @@ func (q *fakeQuerier) UpdateProvisionerJobByID(_ context.Context, arg database.U
15571574
defer q.mutex.Unlock()
15581575

15591576
for index, job := range q.provisionerJobs {
1560-
if arg.ID.String() != job.ID.String() {
1577+
if arg.ID != job.ID {
15611578
continue
15621579
}
15631580
job.UpdatedAt = arg.UpdatedAt
@@ -1572,7 +1589,7 @@ func (q *fakeQuerier) UpdateProvisionerJobWithCancelByID(_ context.Context, arg
15721589
defer q.mutex.Unlock()
15731590

15741591
for index, job := range q.provisionerJobs {
1575-
if arg.ID.String() != job.ID.String() {
1592+
if arg.ID != job.ID {
15761593
continue
15771594
}
15781595
job.CanceledAt = arg.CanceledAt
@@ -1587,7 +1604,7 @@ func (q *fakeQuerier) UpdateProvisionerJobWithCompleteByID(_ context.Context, ar
15871604
defer q.mutex.Unlock()
15881605

15891606
for index, job := range q.provisionerJobs {
1590-
if arg.ID.String() != job.ID.String() {
1607+
if arg.ID != job.ID {
15911608
continue
15921609
}
15931610
job.UpdatedAt = arg.UpdatedAt
@@ -1604,7 +1621,7 @@ func (q *fakeQuerier) UpdateWorkspaceAutostart(_ context.Context, arg database.U
16041621
defer q.mutex.Unlock()
16051622

16061623
for index, workspace := range q.workspaces {
1607-
if workspace.ID.String() != arg.ID.String() {
1624+
if workspace.ID != arg.ID {
16081625
continue
16091626
}
16101627
workspace.AutostartSchedule = arg.AutostartSchedule
@@ -1620,7 +1637,7 @@ func (q *fakeQuerier) UpdateWorkspaceAutostop(_ context.Context, arg database.Up
16201637
defer q.mutex.Unlock()
16211638

16221639
for index, workspace := range q.workspaces {
1623-
if workspace.ID.String() != arg.ID.String() {
1640+
if workspace.ID != arg.ID {
16241641
continue
16251642
}
16261643
workspace.AutostopSchedule = arg.AutostopSchedule
@@ -1636,7 +1653,7 @@ func (q *fakeQuerier) UpdateWorkspaceBuildByID(_ context.Context, arg database.U
16361653
defer q.mutex.Unlock()
16371654

16381655
for index, workspaceBuild := range q.workspaceBuilds {
1639-
if workspaceBuild.ID.String() != arg.ID.String() {
1656+
if workspaceBuild.ID != arg.ID {
16401657
continue
16411658
}
16421659
workspaceBuild.UpdatedAt = arg.UpdatedAt
@@ -1653,7 +1670,7 @@ func (q *fakeQuerier) UpdateWorkspaceDeletedByID(_ context.Context, arg database
16531670
defer q.mutex.Unlock()
16541671

16551672
for index, workspace := range q.workspaces {
1656-
if workspace.ID.String() != arg.ID.String() {
1673+
if workspace.ID != arg.ID {
16571674
continue
16581675
}
16591676
workspace.Deleted = arg.Deleted

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: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templateversions.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,12 @@ SET
8080
updated_at = $3
8181
WHERE
8282
id = $1;
83+
84+
-- name: UpdateTemplateVersionDescriptionByJobID :exec
85+
UPDATE
86+
template_versions
87+
SET
88+
description = $2,
89+
updated_at = now()
90+
WHERE
91+
job_id = $1;

coderd/provisionerdaemons.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,16 @@ func (server *provisionerdServer) UpdateJob(ctx context.Context, request *proto.
348348
}
349349
}
350350

351+
if len(request.Readme) > 0 {
352+
err := server.Database.UpdateTemplateVersionDescriptionByJobID(ctx, database.UpdateTemplateVersionDescriptionByJobIDParams{
353+
JobID: job.ID,
354+
Description: string(request.Readme),
355+
})
356+
if err != nil {
357+
return nil, xerrors.Errorf("update template version description: %w", err)
358+
}
359+
}
360+
351361
if len(request.ParameterSchemas) > 0 {
352362
for _, protoParameter := range request.ParameterSchemas {
353363
validationTypeSystem, err := convertValidationTypeSystem(protoParameter.ValidationTypeSystem)

coderd/templateversions.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,12 @@ func (api *api) templateVersionLogs(rw http.ResponseWriter, r *http.Request) {
401401

402402
func convertTemplateVersion(version database.TemplateVersion, job codersdk.ProvisionerJob) codersdk.TemplateVersion {
403403
return codersdk.TemplateVersion{
404-
ID: version.ID,
405-
TemplateID: &version.TemplateID.UUID,
406-
CreatedAt: version.CreatedAt,
407-
UpdatedAt: version.UpdatedAt,
408-
Name: version.Name,
409-
Job: job,
404+
ID: version.ID,
405+
TemplateID: &version.TemplateID.UUID,
406+
CreatedAt: version.CreatedAt,
407+
UpdatedAt: version.UpdatedAt,
408+
Name: version.Name,
409+
Job: job,
410+
Description: version.Description,
410411
}
411412
}

coderd/workspaceagents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (api *api) workspaceAgentListen(rw http.ResponseWriter, r *http.Request) {
216216
if err != nil {
217217
return err
218218
}
219-
if build.ID.String() != latestBuild.ID.String() {
219+
if build.ID != latestBuild.ID {
220220
return xerrors.New("build is outdated")
221221
}
222222
return nil

coderd/workspaceresourceauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (api *api) handleAuthInstanceID(rw http.ResponseWriter, r *http.Request, in
144144
})
145145
return
146146
}
147-
if latestHistory.ID.String() != resourceHistory.ID.String() {
147+
if latestHistory.ID != resourceHistory.ID {
148148
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
149149
Message: fmt.Sprintf("resource found for id %q, but isn't registered on the latest history", instanceID),
150150
})

codersdk/templateversions.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ import (
1515

1616
// TemplateVersion represents a single version of a template.
1717
type TemplateVersion struct {
18-
ID uuid.UUID `json:"id"`
19-
TemplateID *uuid.UUID `json:"template_id,omitempty"`
20-
CreatedAt time.Time `json:"created_at"`
21-
UpdatedAt time.Time `json:"updated_at"`
22-
Name string `json:"name"`
23-
Job ProvisionerJob `json:"job"`
18+
ID uuid.UUID `json:"id"`
19+
TemplateID *uuid.UUID `json:"template_id,omitempty"`
20+
CreatedAt time.Time `json:"created_at"`
21+
UpdatedAt time.Time `json:"updated_at"`
22+
Name string `json:"name"`
23+
Job ProvisionerJob `json:"job"`
24+
Description string `json:"description"`
2425
}
2526

2627
// TemplateVersionParameterSchema represents a parameter parsed from template version source.

0 commit comments

Comments
 (0)