Skip to content

Commit 6dc1320

Browse files
authored
Merge pull request #2022 from appwrite/fix-detections
Fix detections not called on functions
2 parents d563aa6 + 96a1c69 commit 6dc1320

File tree

6 files changed

+88
-36
lines changed

6 files changed

+88
-36
lines changed

src/routes/(console)/project-[region]-[project]/functions/create-function/(components)/aside.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { Card, SvgIcon } from '$lib/components';
3-
import { Icon, Layout, Typography } from '@appwrite.io/pink-svelte';
3+
import { Icon, Layout, Skeleton, Typography } from '@appwrite.io/pink-svelte';
44
import { IconGithub, IconGitBranch } from '@appwrite.io/pink-icons-svelte';
55
import type { Models, Runtime } from '@appwrite.io/console';
66
@@ -10,6 +10,7 @@
1010
export let rootDir: string = undefined;
1111
export let showGitData = true;
1212
export let runtimes: Models.RuntimeList;
13+
export let loading = false;
1314
1415
$: selectedRuntime = runtimes?.runtimes.find((r) => r.$id === runtime);
1516
</script>
@@ -18,7 +19,7 @@
1819
<Layout.Stack gap="xl">
1920
<slot />
2021
<Layout.Stack gap="l">
21-
{#if selectedRuntime?.name}
22+
{#if selectedRuntime?.name && !loading}
2223
<Layout.Stack gap="xxxs">
2324
<Typography.Caption variant="400">Runtime</Typography.Caption>
2425
<Layout.Stack gap="xxs" alignItems="center" direction="row">
@@ -30,6 +31,11 @@
3031
</Typography.Text>
3132
</Layout.Stack>
3233
</Layout.Stack>
34+
{:else if loading}
35+
<Layout.Stack gap="xs">
36+
<Skeleton variant="line" width={100} height={16} />
37+
<Skeleton variant="line" width="100%" height={20} />
38+
</Layout.Stack>
3339
{/if}
3440
{#if showGitData}
3541
{#if repositoryName}

src/routes/(console)/project-[region]-[project]/functions/create-function/(components)/details.svelte

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { organization } from '$lib/stores/organization';
88
import { isCloud } from '$lib/system';
99
import { IconPencil } from '@appwrite.io/pink-icons-svelte';
10-
import { Fieldset, Icon, Input, Layout, Tag } from '@appwrite.io/pink-svelte';
10+
import { Fieldset, Icon, Input, Layout, Skeleton, Tag } from '@appwrite.io/pink-svelte';
1111
import type { ComponentType } from 'svelte';
1212
1313
export let name: string;
@@ -25,6 +25,7 @@
2525
value: string;
2626
label: string;
2727
}[] = [];
28+
export let loading = false;
2829
2930
let showCustomId = false;
3031
</script>
@@ -51,13 +52,20 @@
5152
{/if}
5253
</Layout.Stack>
5354
{#key runtime}
54-
<InputSelect
55-
id="runtime"
56-
label="Runtime"
57-
placeholder="Select runtime"
58-
bind:value={runtime}
59-
required
60-
{options} />
55+
{#if loading}
56+
<Layout.Stack gap="xs">
57+
<Skeleton variant="line" width={100} height={20} />
58+
<Skeleton variant="line" width="100%" height={32} />
59+
</Layout.Stack>
60+
{:else}
61+
<InputSelect
62+
id="runtime"
63+
label="Runtime"
64+
placeholder="Select runtime"
65+
bind:value={runtime}
66+
required
67+
{options} />
68+
{/if}
6169
{/key}
6270

6371
{#if isCloud}
@@ -79,12 +87,19 @@
7987
</Layout.Stack>
8088
{/if}
8189
{#if showEntrypoint}
82-
<InputText
83-
label="Entrypoint"
84-
id="entrypoint"
85-
bind:value={entrypoint}
86-
required
87-
placeholder="Enter entrypoint" />
90+
{#if loading}
91+
<Layout.Stack gap="xs">
92+
<Skeleton variant="line" width={100} height={20} />
93+
<Skeleton variant="line" width="100%" height={32} />
94+
</Layout.Stack>
95+
{:else}
96+
<InputText
97+
label="Entrypoint"
98+
id="entrypoint"
99+
bind:value={entrypoint}
100+
required
101+
placeholder="Enter entrypoint" />
102+
{/if}
88103
{/if}
89104
</Layout.Stack>
90105
</Fieldset>

src/routes/(console)/project-[region]-[project]/functions/create-function/repository-[repository]/+page.svelte

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { installation, repository } from '$lib/stores/vcs';
1111
import { Layout } from '@appwrite.io/pink-svelte';
1212
import { writable } from 'svelte/store';
13-
import { ID, Runtime, VCSDeploymentType } from '@appwrite.io/console';
13+
import { ID, Runtime, VCSDeploymentType, VCSDetectionType } from '@appwrite.io/console';
1414
import type { Models } from '@appwrite.io/console';
1515
import { onMount } from 'svelte';
1616
import Details from '../(components)/details.svelte';
@@ -57,12 +57,40 @@
5757
let silentMode = false;
5858
let specification = specificationOptions[0].value;
5959
60+
let detectingRuntime = true;
61+
6062
onMount(async () => {
6163
installation.set(data.installation);
6264
repository.set(data.repository);
6365
name = data.repository.name;
66+
67+
await detectRuntime();
6468
});
6569
70+
async function detectRuntime() {
71+
try {
72+
detectingRuntime = true;
73+
74+
const detections = (await sdk
75+
.forProject(page.params.regionn, page.params.project)
76+
.vcs.createRepositoryDetection(
77+
data.installation.$id,
78+
page.params.repository,
79+
VCSDetectionType.Runtime
80+
)) as unknown as Models.DetectionRuntime; /* SDK return type is wrong atm */
81+
82+
entrypoint = detections.entrypoint;
83+
buildCommand = detections.commands;
84+
runtime = detections.runtime as Runtime;
85+
86+
trackEvent(Submit.FrameworkDetect, { runtime, source: 'repository' });
87+
} catch (error) {
88+
trackError(error, Submit.FrameworkDetect);
89+
} finally {
90+
detectingRuntime = false;
91+
}
92+
}
93+
6694
async function create() {
6795
try {
6896
const func = await sdk
@@ -154,7 +182,8 @@
154182
bind:specification
155183
{specificationOptions}
156184
options={runtimeOptions}
157-
showEntrypoint />
185+
showEntrypoint
186+
loading={detectingRuntime} />
158187

159188
<ProductionBranchFieldset
160189
bind:branch
@@ -173,7 +202,8 @@
173202
runtimes={data.runtimesList}
174203
repositoryName={data.repository.name}
175204
{branch}
176-
{rootDir} />
205+
{rootDir}
206+
loading={detectingRuntime} />
177207
</svelte:fragment>
178208

179209
<svelte:fragment slot="footer">

src/routes/(console)/project-[region]-[project]/functions/create-function/repository-[repository]/+page.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { sdk } from '$lib/stores/sdk';
33
export const load = async ({ parent, params, url }) => {
44
const { installations, runtimesList, specificationsList } = await parent();
55

6-
const [repository] = await Promise.all([
7-
sdk
8-
.forProject(params.region, params.project)
9-
.vcs.getRepository(url.searchParams.get('installation'), params.repository)
10-
]);
6+
const repository = await sdk
7+
.forProject(params.region, params.project)
8+
.vcs.getRepository(url.searchParams.get('installation'), params.repository);
9+
10+
const installation = installations.installations.find(
11+
(installation) => installation.$id === url.searchParams.get('installation')
12+
);
1113

1214
return {
15+
installation,
1316
installations,
14-
installation: installations.installations.find(
15-
(installation) => installation.$id === url.searchParams.get('installation')
16-
),
1717
repository,
1818
runtimesList,
1919
specificationsList

src/routes/(console)/project-[region]-[project]/sites/create-site/repositories/repository-[repository]/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
.forProject(page.params.region, page.params.project)
6363
.vcs.createRepositoryDetection(
6464
$installation.$id,
65-
data.repository.id,
65+
page.params.repository,
6666
VCSDetectionType.Framework,
6767
rootDir
6868
);

src/routes/(console)/project-[region]-[project]/sites/create-site/repositories/repository-[repository]/+page.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ import { buildVerboseDomain } from '../../store';
55
export const load = async ({ parent, params, url }) => {
66
const { installations, frameworks, project, organization, regionalConsoleVariables } =
77
await parent();
8-
const [repository] = await Promise.all([
9-
sdk
10-
.forProject(params.region, params.project)
11-
.vcs.getRepository(url.searchParams.get('installation'), params.repository)
12-
]);
8+
9+
const repository = await sdk
10+
.forProject(params.region, params.project)
11+
.vcs.getRepository(url.searchParams.get('installation'), params.repository);
12+
13+
const installation = installations.installations.find(
14+
(installation) => installation.$id === url.searchParams.get('installation')
15+
);
1316

1417
const domain = await buildVerboseDomain(
1518
regionalConsoleVariables._APP_DOMAIN_SITES,
@@ -21,9 +24,7 @@ export const load = async ({ parent, params, url }) => {
2124

2225
return {
2326
installations,
24-
installation: installations.installations.find(
25-
(installation) => installation.$id === url.searchParams.get('installation')
26-
),
27+
installation,
2728
repository,
2829
frameworks,
2930
domain

0 commit comments

Comments
 (0)