Skip to content

Commit 0c763d7

Browse files
authored
Merge pull request #2899 from appwrite/fix-reconnect-repo
fix(sites): reconnect repo flow and branch selection
2 parents ec5b6ad + 90912c3 commit 0c763d7

6 files changed

Lines changed: 114 additions & 46 deletions

File tree

bun.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@
8989
},
9090
"overrides": {
9191
"vite": "npm:rolldown-vite@latest",
92-
"minimatch": "10.2.1"
92+
"minimatch": "10.2.3"
9393
}
9494
}

src/lib/components/git/connectRepoModal.svelte

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
}
5353
});
5454
55+
$effect(() => {
56+
if ($installation?.$id) {
57+
selectedInstallationId = $installation.$id;
58+
}
59+
});
60+
5561
async function connectRepo() {
5662
try {
5763
if (repositoryBehaviour === 'new') {
@@ -105,13 +111,29 @@
105111
{product}
106112
action="button"
107113
{callbackState}
108-
connect={(e) => {
114+
connect={async (e) => {
109115
trackEvent(Click.ConnectRepositoryClick, {
110116
from: product
111117
});
112118
repository.set(e);
113119
repositoryName = e.name;
114120
selectedRepository = e.id;
121+
if (!selectedInstallationId && $installation?.$id) {
122+
selectedInstallationId = $installation.$id;
123+
}
124+
try {
125+
await connect(selectedInstallationId, e.id);
126+
show = false;
127+
addNotification({
128+
type: 'success',
129+
message: 'Repository connected successfully'
130+
});
131+
} catch (error) {
132+
addNotification({
133+
type: 'error',
134+
message: error?.message ?? 'Failed to connect repository'
135+
});
136+
}
115137
}} />
116138
{/if}
117139
</Layout.Stack>

src/lib/components/git/repositories.svelte

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import { Query, VCSDetectionType, type Models } from '@appwrite.io/console';
2121
import { getFrameworkIcon } from '$lib/stores/sites';
2222
import { connectGitHub } from '$lib/stores/git';
23+
import { addNotification } from '$lib/stores/notifications';
2324
import { page } from '$app/state';
2425
import Card from '../card.svelte';
2526
import SkeletonRepoList from './skeletonRepoList.svelte';
@@ -274,9 +275,20 @@
274275
variant="secondary"
275276
style="flex-shrink: 0;"
276277
disabled={!!connectingRepositoryId}
277-
on:click={() => {
278+
on:click={async () => {
278279
connectingRepositoryId = repo.id;
279-
connect(repo);
280+
try {
281+
await Promise.resolve(connect(repo));
282+
} catch (error) {
283+
addNotification({
284+
type: 'error',
285+
message:
286+
error?.message ??
287+
'Failed to connect repository'
288+
});
289+
} finally {
290+
connectingRepositoryId = null;
291+
}
280292
}}>
281293
Connect
282294
</PinkButton.Button>

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

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import { IconPlus } from '@appwrite.io/pink-icons-svelte';
1515
import { onMount } from 'svelte';
1616
import { realtime, sdk } from '$lib/stores/sdk';
17+
import { sortBranches } from '$lib/stores/vcs';
1718
import { invalidate } from '$app/navigation';
1819
import { Dependencies } from '$lib/constants';
1920
import CreateCliModal from './createCliModal.svelte';
@@ -40,28 +41,45 @@
4041
});
4142
4243
async function connect(selectedInstallationId: string, selectedRepository: string) {
44+
let nextBranch = data.site?.providerBranch ?? 'main';
4345
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;
6258
} catch {
63-
return;
59+
// Ignore branch lookup failures; fallback to default.
6460
}
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);
6583
}
6684
</script>
6785

src/routes/(console)/project-[region]-[project]/sites/site-[site]/settings/updateRepository.svelte

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,46 @@
116116
}
117117
118118
async function connect(selectedInstallationId: string, selectedRepository: string) {
119+
let nextBranch = site?.providerBranch ?? 'main';
119120
try {
120-
await sdk.forProject(page.params.region, page.params.project).sites.update({
121-
siteId: site.$id,
122-
name: site.name,
123-
framework: site.framework as Framework,
124-
enabled: site?.enabled,
125-
logging: site?.logging || undefined,
126-
timeout: site?.timeout,
127-
installCommand: site?.installCommand,
128-
buildCommand: site?.buildCommand,
129-
outputDirectory: site?.outputDirectory,
130-
buildRuntime: site?.buildRuntime as BuildRuntime,
131-
adapter: site.adapter as Adapter,
132-
fallbackFile: site?.fallbackFile,
133-
installationId: selectedInstallationId,
134-
providerRepositoryId: selectedRepository,
135-
providerBranch: 'main',
136-
specification: site?.specification || undefined
137-
});
138-
139-
invalidate(Dependencies.SITE);
121+
const branchList = await sdk
122+
.forProject(page.params.region, page.params.project)
123+
.vcs.listRepositoryBranches({
124+
installationId: selectedInstallationId,
125+
providerRepositoryId: selectedRepository
126+
});
127+
const sorted = sortBranches(branchList.branches);
128+
nextBranch =
129+
sorted.find((branch) => branch.name === site?.providerBranch)?.name ??
130+
sorted.find((branch) => branch.name === 'main' || branch.name === 'master')?.name ??
131+
sorted[0]?.name ??
132+
nextBranch;
140133
} catch {
141-
return;
134+
// Ignore branch lookup failures; fallback to default.
142135
}
136+
137+
await sdk.forProject(page.params.region, page.params.project).sites.update({
138+
siteId: site.$id,
139+
name: site.name,
140+
framework: site.framework as Framework,
141+
enabled: site?.enabled,
142+
logging: site?.logging || undefined,
143+
timeout: site?.timeout,
144+
installCommand: site?.installCommand,
145+
buildCommand: site?.buildCommand,
146+
outputDirectory: site?.outputDirectory,
147+
buildRuntime: site?.buildRuntime as BuildRuntime,
148+
adapter: site.adapter as Adapter,
149+
fallbackFile: site?.fallbackFile,
150+
installationId: selectedInstallationId,
151+
providerRepositoryId: selectedRepository,
152+
providerBranch: nextBranch,
153+
providerSilentMode: site?.providerSilentMode ?? undefined,
154+
providerRootDirectory: site?.providerRootDirectory ?? undefined,
155+
specification: site?.specification || undefined
156+
});
157+
158+
invalidate(Dependencies.SITE);
143159
}
144160
145161
$: if (site?.installationId && site?.providerRepositoryId) {

0 commit comments

Comments
 (0)