MCPcopy Index your code
hub / github.com/coder/coder / autoCreateWorkspace

Function autoCreateWorkspace

site/src/api/queries/workspaces.ts:153–194  ·  view source on GitHub ↗
(queryClient: QueryClient)

Source from the content-addressed store, hash-verified

151};
152
153export const autoCreateWorkspace = (queryClient: QueryClient) => {
154 return {
155 mutationFn: async ({
156 organizationId,
157 templateName,
158 workspaceName,
159 templateVersionId,
160 buildParameters,
161 match,
162 }: AutoCreateWorkspaceOptions) => {
163 if (match) {
164 const matchWorkspace = await findMatchWorkspace(
165 `owner:me template:${templateName} ${match}`,
166 );
167 if (matchWorkspace) {
168 return matchWorkspace;
169 }
170 }
171
172 let templateVersionParameters: Partial<CreateWorkspaceRequest>;
173
174 if (templateVersionId) {
175 templateVersionParameters = { template_version_id: templateVersionId };
176 } else {
177 const template = await API.getTemplateByName(
178 organizationId,
179 templateName,
180 );
181 templateVersionParameters = { template_id: template.id };
182 }
183
184 return API.createWorkspace("me", {
185 ...templateVersionParameters,
186 name: workspaceName,
187 rich_parameter_values: buildParameters,
188 });
189 },
190 onSuccess: async () => {
191 await invalidateWorkspaceListQueries(queryClient);
192 },
193 };
194};
195
196async function findMatchWorkspace(q: string): Promise<Workspace | undefined> {
197 try {

Callers 2

CreateWorkspacePageFunction · 0.90
workspaces.test.tsFile · 0.90

Calls 3

findMatchWorkspaceFunction · 0.85
createWorkspaceMethod · 0.80

Tested by

no test coverage detected