diff --git a/src/lib/wizards/functions/components/repositories.svelte b/src/lib/wizards/functions/components/repositories.svelte index 0637e336f..914a8e439 100644 --- a/src/lib/wizards/functions/components/repositories.svelte +++ b/src/lib/wizards/functions/components/repositories.svelte @@ -31,7 +31,17 @@ let search = ''; async function loadRepositories(installationId: string, search: string) { - return sdk.forProject.vcs.listRepositories(installationId, search || undefined); + const repositories = await sdk.forProject.vcs.listRepositories( + installationId, + search || undefined + ); + + if (repositories.providerRepositories.length) { + selectedRepository = repositories.providerRepositories[0].id; + $repository = repositories.providerRepositories[0]; + } + + return repositories; } function connectGitHub() { @@ -104,7 +114,7 @@ repository.set(repo)} value={repo.id} /> diff --git a/src/lib/wizards/functions/cover.svelte b/src/lib/wizards/functions/cover.svelte index 8113734fa..1da64a759 100644 --- a/src/lib/wizards/functions/cover.svelte +++ b/src/lib/wizards/functions/cover.svelte @@ -38,7 +38,16 @@ } templateStore.set(template); - templateConfig.set({ $id: null, runtime, name: template.name, variables }); + templateConfig.set({ + $id: null, + runtime, + name: template.name, + variables, + repositoryBehaviour: 'new', + repositoryName: template.id, + repositoryPrivate: false, + repositoryId: null + }); wizard.start(CreateTemplate); } diff --git a/src/lib/wizards/functions/createTemplate.svelte b/src/lib/wizards/functions/createTemplate.svelte index b33791ae2..d1bb6c352 100644 --- a/src/lib/wizards/functions/createTemplate.svelte +++ b/src/lib/wizards/functions/createTemplate.svelte @@ -5,49 +5,48 @@ import { sdk } from '$lib/stores/sdk'; import { wizard } from '$lib/stores/wizard'; import { goto } from '$app/navigation'; - import { - choices, - createFunction, - installation, - repository, - template, - templateConfig - } from './store'; + import { choices, installation, repository, template, templateConfig } from './store'; import { addNotification } from '$lib/stores/notifications'; import { Submit, trackEvent } from '$lib/actions/analytics'; import { base } from '$app/paths'; import { page } from '$app/stores'; - import SelectRepository from './steps/selectRepository.svelte'; import GitConfiguration from './steps/gitConfiguration.svelte'; import TemplateConfiguration from './steps/templateConfiguration.svelte'; - import TempalteFunctionDetails from './steps/tempalteFunctionDetails.svelte'; + import RepositoryBehaviour from './steps/repositoryBehaviour.svelte'; + import CreateRepository from './steps/createRepository.svelte'; async function create() { + const runtimeDetail = $template.runtimes.find((r) => r.name === $templateConfig.runtime); + const response = await sdk.forProject.functions.create( - $createFunction.$id || ID.unique(), - $createFunction.name, - $createFunction.runtime, - $createFunction.execute || undefined, - $createFunction.entrypoint, + $templateConfig.$id || ID.unique(), + $templateConfig.name, + $templateConfig.runtime, + $template.permissions || undefined, + runtimeDetail.entrypoint, + $template.events || undefined, + $template.cron || undefined, + $template.timeout || undefined, undefined, undefined, - undefined, - undefined, - undefined, - $createFunction.commands, + runtimeDetail.commands, $installation.$id, $repository.id, $choices.branch, $choices.silentMode, - $choices.rootDir + $choices.rootDir, + $template.providerRepositoryId, + $template.providerOwner, + runtimeDetail.providerRootDirectory, + $template.providerBranch ); goto(`${base}/console/project-${$page.params.project}/functions/function-${response.$id}`); addNotification({ - message: `${$createFunction.name} has been created`, + message: `${response.name} has been created`, type: 'success' }); trackEvent(Submit.FunctionCreate, { - customId: !!$createFunction.$id + customId: !!response.$id }); resetState(); wizard.hide(); @@ -61,16 +60,16 @@ const stepsComponents: WizardStepsType = new Map(); stepsComponents.set(1, { - label: 'Template Configuration', + label: 'Function configuration', component: TemplateConfiguration }); stepsComponents.set(2, { - label: 'Function Details', - component: TempalteFunctionDetails + label: 'Repository behaviour', + component: RepositoryBehaviour }); stepsComponents.set(3, { - label: 'Select Repository', - component: SelectRepository + label: 'Select repository', + component: CreateRepository }); stepsComponents.set(4, { label: 'Git configuration', diff --git a/src/lib/wizards/functions/steps/createRepository.svelte b/src/lib/wizards/functions/steps/createRepository.svelte new file mode 100644 index 000000000..f6be47ede --- /dev/null +++ b/src/lib/wizards/functions/steps/createRepository.svelte @@ -0,0 +1,151 @@ + + + + Select repository + + Select a Git repository that will trigger your function deployments when updated. + + + {#if $templateConfig.repositoryBehaviour === 'existing'} + + {:else} + {#await loadInstallations()} +
+
+
+ {:then installations} + {#if hasInstallations} +
+
+ { + return { + label: entry.organization, + value: entry.$id + }; + })} + on:change={() => { + $installation = installations.find( + (entry) => entry.$id === selectedInstallationId + ); + }} + bind:value={selectedInstallationId} /> +
+
+ {:else} +
+ + + + +
+ {/if} + {/await} + + {#if $installation} +
+
+
+ +
+
+
+ {$installation.organization}/{$templateConfig.repositoryName} +
+
+
+
+ + + + +
+
+ {/if} + {/if} + diff --git a/src/lib/wizards/functions/steps/gitConfiguration.svelte b/src/lib/wizards/functions/steps/gitConfiguration.svelte index 78e9a3252..e4efeac9d 100644 --- a/src/lib/wizards/functions/steps/gitConfiguration.svelte +++ b/src/lib/wizards/functions/steps/gitConfiguration.svelte @@ -1,5 +1,6 @@ + + + Repository Behaviour + + Connect function to a new repository or to an existing one within a selected Git + organization. + + +
    +
  • + +
  • +
  • + +
  • +
+
diff --git a/src/lib/wizards/functions/steps/tempalteFunctionDetails.svelte b/src/lib/wizards/functions/steps/tempalteFunctionDetails.svelte deleted file mode 100644 index fcd870600..000000000 --- a/src/lib/wizards/functions/steps/tempalteFunctionDetails.svelte +++ /dev/null @@ -1,33 +0,0 @@ - - - - Function details - Configure Appwrite Function you are about to create. - - - {#if !showCustomId} -
- (showCustomId = !showCustomId)}> - -
- {:else} - - {/if} -
-
diff --git a/src/lib/wizards/functions/steps/templateConfiguration.svelte b/src/lib/wizards/functions/steps/templateConfiguration.svelte index 4bfdffb4d..daacc44fa 100644 --- a/src/lib/wizards/functions/steps/templateConfiguration.svelte +++ b/src/lib/wizards/functions/steps/templateConfiguration.svelte @@ -1,21 +1,24 @@