From b37ee64e59d13baa95a4c309f63250e9a558beac Mon Sep 17 00:00:00 2001
From: Arman
Date: Mon, 12 Jun 2023 17:47:13 +0200
Subject: [PATCH] feat: git configuration
---
src/lib/actions/analytics.ts | 1 +
.../settings/disconnectRepo.svelte | 62 +++++++++
.../settings/gitConfigurationModal.svelte | 46 +++++--
.../settings/updateConfiguration.svelte | 125 +++++++++++++++---
4 files changed, 205 insertions(+), 29 deletions(-)
create mode 100644 src/routes/console/project-[project]/functions/function-[function]/settings/disconnectRepo.svelte
diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts
index 8a3737d77..734b3753c 100644
--- a/src/lib/actions/analytics.ts
+++ b/src/lib/actions/analytics.ts
@@ -175,6 +175,7 @@ export enum Submit {
FunctionUpdateLogging = 'submit_function_update_logging',
FunctionUpdateTimeout = 'submit_function_update_timeout',
FunctionUpdateEvents = 'submit_function_update_events',
+ FunctionDisconnectRepo = 'submit_function_disconnect_repo',
DeploymentCreate = 'submit_deployment_create',
DeploymentDelete = 'submit_deployment_delete',
DeploymentUpdate = 'submit_deployment_update',
diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/disconnectRepo.svelte b/src/routes/console/project-[project]/functions/function-[function]/settings/disconnectRepo.svelte
new file mode 100644
index 000000000..8327a8106
--- /dev/null
+++ b/src/routes/console/project-[project]/functions/function-[function]/settings/disconnectRepo.svelte
@@ -0,0 +1,62 @@
+
+
+
+ Disconnect Git repository
+
+ Are you sure you want to disconnect {$func.name}? This will affect future deployments to
+ this function.
+
+
+
+
+
+
diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/gitConfigurationModal.svelte b/src/routes/console/project-[project]/functions/function-[function]/settings/gitConfigurationModal.svelte
index ce977d4a6..c4be8aa52 100644
--- a/src/routes/console/project-[project]/functions/function-[function]/settings/gitConfigurationModal.svelte
+++ b/src/routes/console/project-[project]/functions/function-[function]/settings/gitConfigurationModal.svelte
@@ -112,21 +112,34 @@
>.
{#if repositoriesList?.total}
- {#each repositoriesList.repositories as repo}
-
Total results: {repositoriesList?.total}
+
+
+
![{$func.name}]()
+
+
{selectedRepo}
@@ -192,7 +210,7 @@
{/await}
{/if}
diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/updateConfiguration.svelte b/src/routes/console/project-[project]/functions/function-[function]/settings/updateConfiguration.svelte
index f156e214a..36ee28062 100644
--- a/src/routes/console/project-[project]/functions/function-[function]/settings/updateConfiguration.svelte
+++ b/src/routes/console/project-[project]/functions/function-[function]/settings/updateConfiguration.svelte
@@ -4,13 +4,23 @@
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { AvatarGroup, CardGrid, Collapsible, CollapsibleItem, Heading } from '$lib/components';
import { Dependencies } from '$lib/constants';
- import { Button, Form, FormList, InputText } from '$lib/elements/forms';
+ import {
+ Button,
+ Form,
+ FormList,
+ InputChoice,
+ InputSelect,
+ InputText
+ } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { func } from '../store';
import GitInstallationModal from '$routes/console/project-[project]/settings/GitInstallationModal.svelte';
import GitConfigurationModal from './gitConfigurationModal.svelte';
+ import { toLocaleDateTime } from '$lib/helpers/date';
+ import { onMount } from 'svelte';
+ import DisconnectRepo from './disconnectRepo.svelte';
export let installations: Models.InstallationList;
const functionId = $page.params.function;
@@ -19,6 +29,20 @@
let installCmd: string;
let buildCmd: string;
let showGit = false;
+ let branchesList: Models.BranchList;
+ let selectedBranch: string;
+ let silentMode = false;
+ let selectedDir: string;
+ let showDisconnect = false;
+
+ onMount(() => {
+ entrypoint = $func?.entrypoint;
+ installCmd = $func?.installCommand;
+ buildCmd = $func?.buildCommand;
+ selectedBranch = $func?.vcsBranch;
+ silentMode = $func?.vcsSilentMode ?? false;
+ selectedDir = $func?.vcsRootDirectory;
+ });
async function updateConfiguration() {
try {
@@ -29,7 +53,16 @@
$func.events || undefined,
$func.schedule || undefined,
$func.timeout || undefined,
- $func.enabled
+ $func.enabled,
+ $func.logging,
+ $func.entrypoint,
+ $func.buildCommand,
+ $func.installCommand,
+ $func.vcsInstallationId,
+ $func.vcsRepositoryId,
+ selectedBranch,
+ silentMode,
+ selectedDir
);
await invalidate(Dependencies.FUNCTION);
addNotification({
@@ -45,6 +78,23 @@
trackError(error, Submit.FunctionUpdateConfiguration);
}
}
+
+ async function getBranches(installation: string, repo: string) {
+ branchesList = await sdk.forProject.vcs.listRepositoryBranches(installation, repo);
+ selectedBranch = $func?.vcsBranch ?? branchesList.branches[0].name;
+ }
+
+ $: if ($func?.vcsInstallationId && $func?.vcsRepositoryId) {
+ getBranches($func.vcsInstallationId, $func.vcsRepositoryId);
+ }
+
+ $: isUpdateButtonEnabled =
+ entrypoint !== $func?.entrypoint ||
+ installCmd !== $func?.installCommand ||
+ buildCmd !== $func?.buildCommand ||
+ selectedBranch !== $func?.vcsBranch ||
+ silentMode !== $func?.vcsSilentMode ||
+ selectedDir !== $func?.vcsRootDirectory;