Skip to content

Commit

Permalink
Implement new git abilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldiron committed May 25, 2023
1 parent dd6555a commit 5bfc75e
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 25 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"node": ">=16"
},
"scripts": {
"dev": "vite dev",
"dev": "vite dev --host 0.0.0.0",
"build": "vite build",
"preview": "vite preview",
"sync": "svelte-kit sync",
Expand All @@ -21,7 +21,7 @@
"dependencies": {
"@analytics/google-analytics": "^1.0.5",
"analytics": "^0.8.1",
"@aw-labs/appwrite-console": "npm:matej-appwrite-console@7.1.52",
"@aw-labs/appwrite-console": "npm:matej-appwrite-console@7.1.63",
"@aw-labs/icons": "0.0.0-77",
"@aw-labs/ui": "0.0.0-77",
"@popperjs/core": "^2.11.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import InputSwitch from '$lib/elements/forms/inputSwitch.svelte';
import Variables from '$lib/components/environmentVariables/variables.svelte';
import GitConnection from './gitConnection.svelte';
import InputSelect from '$lib/elements/forms/inputSelect.svelte';
export let data: PageData;
Expand All @@ -39,6 +40,7 @@
let entrypoint: string = null;
let buildCommand: string = null;
let installCommand: string = null;
let branch: string = null;
let showGitConnection = false;
Expand All @@ -55,6 +57,7 @@
entrypoint ??= $func.entrypoint;
buildCommand ??= $func.buildCommand;
installCommand ??= $func.installCommand;
branch ??= $func.branch;
$eventSet = new Set($func.events);
});
Expand All @@ -73,7 +76,8 @@
$func.buildCommand,
$func.installCommand,
$func.vcsInstallationId,
$func.repositoryId
$func.repositoryId,
$func.branch
);
invalidate(Dependencies.FUNCTION);
addNotification({
Expand Down Expand Up @@ -104,7 +108,8 @@
$func.buildCommand,
$func.installCommand,
$func.vcsInstallationId,
$func.repositoryId
$func.repositoryId,
$func.branch
);
invalidate(Dependencies.FUNCTION);
addNotification({
Expand Down Expand Up @@ -135,7 +140,8 @@
$func.buildCommand,
$func.installCommand,
$func.vcsInstallationId,
$func.repositoryId
$func.repositoryId,
$func.branch
);
invalidate(Dependencies.FUNCTION);
addNotification({
Expand Down Expand Up @@ -166,7 +172,8 @@
$func.buildCommand,
$func.installCommand,
$func.vcsInstallationId,
$func.repositoryId
$func.repositoryId,
$func.branch
);
invalidate(Dependencies.FUNCTION);
addNotification({
Expand Down Expand Up @@ -197,7 +204,8 @@
$func.buildCommand,
$func.installCommand,
$func.vcsInstallationId,
$func.repositoryId
$func.repositoryId,
$func.branch
);
invalidate(Dependencies.FUNCTION);
Expand Down Expand Up @@ -229,7 +237,8 @@
$func.buildCommand,
$func.installCommand,
$func.vcsInstallationId,
$func.repositoryId
$func.repositoryId,
$func.branch
);
invalidate(Dependencies.FUNCTION);
Expand Down Expand Up @@ -261,7 +270,41 @@
buildCommand,
installCommand,
$func.vcsInstallationId,
$func.repositoryId
$func.repositoryId,
$func.branch
);
invalidate(Dependencies.FUNCTION);
addNotification({
type: 'success',
message: 'Deployment settings has been updated'
});
trackEvent('submit_function_update_deployment_settings');
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
}
}
async function updateBranch() {
try {
await sdkForProject.functions.update(
functionId,
$func.name,
$func.execute,
$func.events,
$func.schedule,
$func.timeout,
$func.enabled,
$func.logging,
$func.entrypoint,
$func.buildCommand,
$func.installCommand,
$func.vcsInstallationId,
$func.repositoryId,
branch
);
invalidate(Dependencies.FUNCTION);
Expand Down Expand Up @@ -293,6 +336,7 @@
$func.buildCommand,
$func.installCommand,
'',
'',
''
);
await invalidate(Dependencies.FUNCTION);
Expand Down Expand Up @@ -399,7 +443,18 @@
<p>SOME TEXT</p>
<svelte:fragment slot="aside">
<ul>
<p>(Repo name, owner name, link to GitHub, ...)</p>
<InputSelect
options={(data?.branches?.branches ?? []).map((branch) => {
return {
label: branch.name,
value: branch.name
};
})}
bind:value={branch}
id="branch"
label="Branch" />

<Button on:click={() => updateBranch()}>Update</Button>
</ul>
</svelte:fragment>
<svelte:fragment slot="actions">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ import { Dependencies } from '$lib/constants';
import type { PageLoad } from './$types';

export const load: PageLoad = async ({ params, parent, depends }) => {
await parent();
const parentData = await parent();
depends(Dependencies.VARIABLES);

return {
variables: await sdkForProject.functions.listVariables(params.function),
installations: await sdkForProject.vcs.listInstallations()
installations: await sdkForProject.vcs.listInstallations(),
branches: parentData.function.vcsInstallationId
? await sdkForProject.vcs.listRepositoryBranches(
parentData.function.vcsInstallationId,
parentData.function.repositoryId
)
: null
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
import { Empty, Modal } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { Button } from '$lib/elements/forms';
import InputSelect from '$lib/elements/forms/inputSelect.svelte';
import { sdkForProject } from '$lib/stores/sdk';
import type { Models } from '@aw-labs/appwrite-console';
export let installations: Models.InstallationList;
export let show = false;
const functionId = $page.params.function;
let selectedInstallation: Models.Installation = null;
let selectedRepository: Models.Repository = null;
let selectedBranchName: string = null;
let repositories: Models.RepositoryList = null;
let branches: Models.BranchList = null;
let error: string;
async function selectInstallation(installation: Models.Installation) {
try {
Expand All @@ -26,10 +30,22 @@
searchQuery || undefined
);
}
$: if (selectedInstallation) {
searchRepositories(inputValue);
}
async function connectRepository(repository: Models.Repository) {
async function selectRepository(repository: Models.Repository) {
selectedRepository = repository;
console.log(selectedRepository);
branches = await sdkForProject.vcs.listRepositoryBranches(
selectedInstallation.$id,
repository.id
);
}
async function connectRepository() {
try {
await sdkForProject.functions.update(
functionId,
Expand All @@ -44,7 +60,8 @@
$page.data.function.buildCommand,
$page.data.function.installCommand,
selectedInstallation.$id,
`${repository.id}`
selectedRepository.id,
selectedBranchName
);
show = false;
await invalidate(Dependencies.FUNCTION);
Expand All @@ -55,6 +72,7 @@
error = e.message;
}
}
let inputValue = '';
</script>

Expand Down Expand Up @@ -107,7 +125,7 @@
</div>
</Empty>
{/if}
{:else}
{:else if !selectedRepository}
<p>
2. Select repository:

Expand Down Expand Up @@ -139,8 +157,8 @@
class="table-col"
data-title="Enabled"
style="--p-col-width:40">
<Button on:click={() => connectRepository(repository)}
>Connect</Button>
<Button on:click={() => selectRepository(repository)}
>Select</Button>
</td>
</tr>
{/each}
Expand All @@ -160,6 +178,27 @@
</Empty>
{/if}
</p>
{:else}
<p>
3. Select branch:

{#if branches === null}
<p>Loading...</p>
{:else}
<InputSelect
options={branches.branches.map((branch) => {
return {
label: branch.name,
value: branch.name
};
})}
bind:value={selectedBranchName}
id="branch"
label="Branch" />

<Button on:click={() => connectRepository()}>Deploy Now</Button>
{/if}
</p>
{/if}

<svelte:fragment slot="footer" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
name: 'GitHub',
icon: 'github',
redirect: () => {
sdkForProject.vcs.createGitHubInstallation();
sdkForProject.vcs.createGitHubInstallation(window.location.href);
}
}
];
Expand Down

0 comments on commit 5bfc75e

Please sign in to comment.