Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add has-ai-task filters to the /workspaces and /templates endpoints #18387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 18, 2025

Conversation

hugodutka
Copy link
Contributor

This PR allows filtering templates and workspaces with the has-ai-task filter as described in the Coder Tasks RFC.

@hugodutka hugodutka changed the base branch from main to hugodutka/insert-workspace-build-ai-task June 16, 2025 13:02
@hugodutka hugodutka force-pushed the hugodutka/has-ai-task-filters branch 2 times, most recently from fb3b8ec to d32f3e4 Compare June 16, 2025 13:49
Base automatically changed from hugodutka/insert-workspace-build-ai-task to main June 16, 2025 14:07
@hugodutka hugodutka force-pushed the hugodutka/has-ai-task-filters branch from 41eebab to 31aa2b2 Compare June 16, 2025 14:09
@hugodutka hugodutka marked this pull request as ready for review June 16, 2025 15:20
@hugodutka hugodutka requested a review from dannykopping June 16, 2025 15:20
Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with a couple nits.

@@ -25,7 +25,7 @@ func userACLMatcher(m sqltypes.VariableMatcher) sqltypes.VariableMatcher {
func TemplateConverter() *sqltypes.VariableConverter {
matcher := sqltypes.NewVariableConverter().RegisterMatcher(
resourceIDMatcher(),
organizationOwnerMatcher(),
sqltypes.StringVarMatcher("t.organization_id :: text", []string{"input", "object", "org_owner"}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only case where we need to update the organization_id alias?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry about that - yes, that's the only place. Only the SQL filter of the GetTemplates query is affected, and TemplateConverter is only used for GetTemplates.

@hugodutka hugodutka force-pushed the hugodutka/has-ai-task-filters branch from 0adf1f2 to 32cc427 Compare June 18, 2025 14:46
return false, xerrors.Errorf("get workspace build parameters: %w", err)
}
for _, param := range parameters {
if param.Name == "AI Prompt" && param.Value != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: this should use the const I'm introducing in the provider: https://github.com/coder/terraform-provider-coder/blob/dk/coder-ai-task-res/provider/ai_task.go#L22

SELECT 1
FROM workspace_build_parameters
WHERE workspace_build_parameters.workspace_build_id = latest_build.id
AND workspace_build_parameters.name = 'AI Prompt'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm we may want to accept this name as an arg, but could get tricky since this is used in a few places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to enforce that this constant matches the constant in go code, I'd rather define a helper function:

CREATE FUNCTION ai_prompt_param_name() RETURNS TEXT AS $$
BEGIN
    RETURN 'AI Prompt';
END;
$$ LANGUAGE plpgsql IMMUTABLE;

Then use that function in the query, and add a test that checks if the result of that function matches the constant in go code.

@@ -25,7 +25,7 @@ func userACLMatcher(m sqltypes.VariableMatcher) sqltypes.VariableMatcher {
func TemplateConverter() *sqltypes.VariableConverter {
matcher := sqltypes.NewVariableConverter().RegisterMatcher(
resourceIDMatcher(),
organizationOwnerMatcher(),
sqltypes.StringVarMatcher("t.organization_id :: text", []string{"input", "object", "org_owner"}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump

@hugodutka hugodutka merged commit 591f5db into main Jun 18, 2025
36 checks passed
@hugodutka hugodutka deleted the hugodutka/has-ai-task-filters branch June 18, 2025 16:22
@github-actions github-actions bot locked and limited conversation to collaborators Jun 18, 2025
@hugodutka
Copy link
Contributor Author

related to #18158

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants