mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user