Skip to content

Commit 15964c3

Browse files
coadlerkylecarbs
authored andcommitted
feat: add README parsing to template versions (#1500)
1 parent 8cc69f8 commit 15964c3

22 files changed

+213
-87
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/audit/table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var AuditableResources = auditMap(map[any]map[string]Action{
7878
"created_at": ActionIgnore, // Never changes, but is implicit and not helpful in a diff.
7979
"updated_at": ActionIgnore, // Changes, but is implicit and not helpful in a diff.
8080
"name": ActionTrack,
81-
"description": ActionTrack,
81+
"readme": ActionTrack,
8282
"job_id": ActionIgnore, // Not helpful in a diff because jobs aren't tracked in audit logs.
8383
},
8484
&database.User{}: {

coderd/coderd.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ func New(options *Options) (http.Handler, func()) {
175175
r.Use(
176176
apiKeyMiddleware,
177177
httpmw.ExtractTemplateParam(options.Database),
178-
httpmw.ExtractOrganizationParam(options.Database),
179178
)
179+
180180
r.Get("/", api.template)
181181
r.Delete("/", api.deleteTemplate)
182182
r.Route("/versions", func(r chi.Router) {
@@ -189,7 +189,6 @@ func New(options *Options) (http.Handler, func()) {
189189
r.Use(
190190
apiKeyMiddleware,
191191
httpmw.ExtractTemplateVersionParam(options.Database),
192-
httpmw.ExtractOrganizationParam(options.Database),
193192
)
194193

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

coderd/database/databasefake/databasefake.go

Lines changed: 30 additions & 13 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"
@@ -1189,7 +1190,7 @@ func (q *fakeQuerier) InsertTemplateVersion(_ context.Context, arg database.Inse
11891190
CreatedAt: arg.CreatedAt,
11901191
UpdatedAt: arg.UpdatedAt,
11911192
Name: arg.Name,
1192-
Description: arg.Description,
1193+
Readme: arg.Readme,
11931194
JobID: arg.JobID,
11941195
}
11951196
q.templateVersions = append(q.templateVersions, version)
@@ -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.Readme = arg.Readme
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/dump.sql

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE template_versions RENAME README TO description;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE template_versions RENAME description TO readme;

coderd/database/models.go

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

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: 33 additions & 13 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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ INSERT INTO
6666
created_at,
6767
updated_at,
6868
"name",
69-
description,
69+
readme,
7070
job_id
7171
)
7272
VALUES
@@ -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+
readme = $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+
Readme: 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)

0 commit comments

Comments
 (0)