feat(coderd): add support for provisioner job id and tag filter (#16556)

This change adds to new filters to the provisionerjobs endpoint, id
(array) and tags (map).

Updates #15084
Updates #15192
Related #16532
This commit is contained in:
Mathias Fredriksson
2025-02-13 18:24:27 +02:00
committed by GitHub
parent ade0a53ddb
commit e38bd27183
10 changed files with 110 additions and 7 deletions
+20
View File
@@ -346,7 +346,9 @@ func (c *Client) OrganizationProvisionerDaemons(ctx context.Context, organizatio
type OrganizationProvisionerJobsOptions struct {
Limit int
IDs []uuid.UUID
Status []ProvisionerJobStatus
Tags map[string]string
}
func (c *Client) OrganizationProvisionerJobs(ctx context.Context, organizationID uuid.UUID, opts *OrganizationProvisionerJobsOptions) ([]ProvisionerJob, error) {
@@ -355,9 +357,19 @@ func (c *Client) OrganizationProvisionerJobs(ctx context.Context, organizationID
if opts.Limit > 0 {
qp.Add("limit", strconv.Itoa(opts.Limit))
}
if len(opts.IDs) > 0 {
qp.Add("ids", joinSliceStringer(opts.IDs))
}
if len(opts.Status) > 0 {
qp.Add("status", joinSlice(opts.Status))
}
if len(opts.Tags) > 0 {
tagsRaw, err := json.Marshal(opts.Tags)
if err != nil {
return nil, xerrors.Errorf("marshal tags: %w", err)
}
qp.Add("tags", string(tagsRaw))
}
}
res, err := c.Request(ctx, http.MethodGet,
@@ -401,6 +413,14 @@ func joinSlice[T ~string](s []T) string {
return strings.Join(ss, ",")
}
func joinSliceStringer[T fmt.Stringer](s []T) string {
var ss []string
for _, v := range s {
ss = append(ss, v.String())
}
return strings.Join(ss, ",")
}
// CreateTemplateVersion processes source-code and optionally associates the version with a template.
// Executing without a template is useful for validating source-code.
func (c *Client) CreateTemplateVersion(ctx context.Context, organizationID uuid.UUID, req CreateTemplateVersionRequest) (TemplateVersion, error) {