MCPcopy Create free account
hub / github.com/coder/coder / TemplateVersionsByTemplate

Method TemplateVersionsByTemplate

codersdk/templates.go:438–453  ·  view source on GitHub ↗

TemplateVersionsByTemplate lists versions associated with a template.

(ctx context.Context, req TemplateVersionsByTemplateRequest)

Source from the content-addressed store, hash-verified

436
437// TemplateVersionsByTemplate lists versions associated with a template.
438func (c *Client) TemplateVersionsByTemplate(ctx context.Context, req TemplateVersionsByTemplateRequest) ([]TemplateVersion, error) {
439 u := fmt.Sprintf("/api/v2/templates/%s/versions", req.TemplateID)
440 if req.IncludeArchived {
441 u += "?include_archived=true"
442 }
443 res, err := c.Request(ctx, http.MethodGet, u, nil, req.Pagination.asRequestOption())
444 if err != nil {
445 return nil, err
446 }
447 defer res.Body.Close()
448 if res.StatusCode != http.StatusOK {
449 return nil, ReadBodyAsError(res)
450 }
451 var templateVersion []TemplateVersion
452 return templateVersion, json.NewDecoder(res.Body).Decode(&templateVersion)
453}
454
455// TemplateVersionByName returns a template version by it's friendly name.
456// This is used for path-based routing. Like: /templates/example/versions/helloworld

Callers 8

TestTemplatePushFunction · 0.80
templatePullMethod · 0.80
templateVersionsListMethod · 0.80
TestTemplatePresetsFunction · 0.80

Calls 4

RequestMethod · 0.95
ReadBodyAsErrorFunction · 0.85
CloseMethod · 0.65
asRequestOptionMethod · 0.45

Tested by 6

TestTemplatePushFunction · 0.64
TestTemplatePresetsFunction · 0.64