|
14 | 14 | import { IconPlus } from '@appwrite.io/pink-icons-svelte'; |
15 | 15 | import { onMount } from 'svelte'; |
16 | 16 | import { realtime, sdk } from '$lib/stores/sdk'; |
| 17 | + import { sortBranches } from '$lib/stores/vcs'; |
17 | 18 | import { invalidate } from '$app/navigation'; |
18 | 19 | import { Dependencies } from '$lib/constants'; |
19 | 20 | import CreateCliModal from './createCliModal.svelte'; |
|
40 | 41 | }); |
41 | 42 |
|
42 | 43 | async function connect(selectedInstallationId: string, selectedRepository: string) { |
| 44 | + let nextBranch = data.site?.providerBranch ?? 'main'; |
43 | 45 | try { |
44 | | - await sdk.forProject(page.params.region, page.params.project).sites.update({ |
45 | | - siteId: data.site.$id, |
46 | | - name: data.site.name, |
47 | | - framework: data.site.framework as Framework, |
48 | | - enabled: data.site.enabled, |
49 | | - logging: data.site.logging || undefined, |
50 | | - timeout: data.site.timeout, |
51 | | - installCommand: data.site.installCommand, |
52 | | - buildCommand: data.site.buildCommand, |
53 | | - outputDirectory: data.site.outputDirectory, |
54 | | - buildRuntime: data.site.buildRuntime as BuildRuntime, |
55 | | - adapter: data.site.adapter as Adapter, |
56 | | - fallbackFile: data.site.fallbackFile, |
57 | | - installationId: selectedInstallationId, |
58 | | - providerRepositoryId: selectedRepository, |
59 | | - providerBranch: 'main' |
60 | | - }); |
61 | | - invalidate(Dependencies.SITE); |
| 46 | + const branchList = await sdk |
| 47 | + .forProject(page.params.region, page.params.project) |
| 48 | + .vcs.listRepositoryBranches({ |
| 49 | + installationId: selectedInstallationId, |
| 50 | + providerRepositoryId: selectedRepository |
| 51 | + }); |
| 52 | + const sorted = sortBranches(branchList.branches); |
| 53 | + nextBranch = |
| 54 | + sorted.find((branch) => branch.name === data.site?.providerBranch)?.name ?? |
| 55 | + sorted.find((branch) => branch.name === 'main' || branch.name === 'master')?.name ?? |
| 56 | + sorted[0]?.name ?? |
| 57 | + nextBranch; |
62 | 58 | } catch { |
63 | | - return; |
| 59 | + // Ignore branch lookup failures; fallback to default. |
64 | 60 | } |
| 61 | +
|
| 62 | + await sdk.forProject(page.params.region, page.params.project).sites.update({ |
| 63 | + siteId: data.site.$id, |
| 64 | + name: data.site.name, |
| 65 | + framework: data.site.framework as Framework, |
| 66 | + enabled: data.site.enabled, |
| 67 | + logging: data.site.logging || undefined, |
| 68 | + timeout: data.site.timeout, |
| 69 | + installCommand: data.site.installCommand, |
| 70 | + buildCommand: data.site.buildCommand, |
| 71 | + outputDirectory: data.site.outputDirectory, |
| 72 | + buildRuntime: data.site.buildRuntime as BuildRuntime, |
| 73 | + adapter: data.site.adapter as Adapter, |
| 74 | + fallbackFile: data.site.fallbackFile, |
| 75 | + installationId: selectedInstallationId, |
| 76 | + providerRepositoryId: selectedRepository, |
| 77 | + providerBranch: nextBranch, |
| 78 | + providerSilentMode: data.site?.providerSilentMode ?? undefined, |
| 79 | + providerRootDirectory: data.site?.providerRootDirectory ?? undefined, |
| 80 | + specification: data.site?.specification || undefined |
| 81 | + }); |
| 82 | + invalidate(Dependencies.SITE); |
65 | 83 | } |
66 | 84 | </script> |
67 | 85 |
|
|
0 commit comments