Skip to content

Commit 41e672a

Browse files
authored
Merge pull request #3121 from appwrite/feat/gitea-connect-button
Add Connect to Gitea button
2 parents c34e081 + 8436692 commit 41e672a

3 files changed

Lines changed: 52 additions & 10 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!--
2+
Gitea has no icon in @appwrite.io/pink-icons-svelte yet, so this is a
3+
hand-drawn stand-in (simplified teapot silhouette, matching Gitea's
4+
mascot) kept local to the git-connect UI until a proper brand icon
5+
lands in the shared icon package. Mirrors the monochrome,
6+
currentcolor-fill convention of the other Icon* components (e.g.
7+
IconGithub) so it drops into <Icon icon={IconGitea} /> unchanged.
8+
-->
9+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 20 20">
10+
<path
11+
fill="currentcolor"
12+
fill-rule="evenodd"
13+
d="M6 3.75A1.25 1.25 0 0 1 7.25 2.5h5.5A1.25 1.25 0 0 1 14 3.75V5h1.25A2.75 2.75 0 0 1 18 7.75v1.5A2.75 2.75 0 0 1 15.25 12H14v.114a3.886 3.886 0 0 1-3.886 3.886H9.886A3.886 3.886 0 0 1 6 12.114V3.75Zm7 5.75V3.75a.25.25 0 0 0-.25-.25h-5.5a.25.25 0 0 0-.25.25v8.364A2.886 2.886 0 0 0 9.886 15h.228A2.886 2.886 0 0 0 13 12.114V9.5ZM14 6v5h1.25c.966 0 1.75-.784 1.75-1.75v-1.5c0-.966-.784-1.75-1.75-1.75H14Z"
14+
clip-rule="evenodd" />
15+
<path
16+
fill="currentcolor"
17+
d="M4 16.5a.75.75 0 0 1 .75-.75h10.5a.75.75 0 0 1 0 1.5H4.75a.75.75 0 0 1-.75-.75Z" />
18+
</svg>

src/lib/components/git/connectGit.svelte

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<script lang="ts">
22
import { isSelfHosted } from '$lib/system';
3-
import { connectGitHub } from '$lib/stores/git';
3+
import { connectGitHub, connectGitea } from '$lib/stores/git';
44
import Button from '$lib/elements/forms/button.svelte';
55
import { IconGithub } from '@appwrite.io/pink-icons-svelte';
66
import { Alert, Card, Empty, Icon, Layout } from '@appwrite.io/pink-svelte';
77
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
8+
import IconGitea from './IconGitea.svelte';
89
910
export let callbackState: Record<string, string> = null;
1011
1112
let isVcsEnabled = $regionalConsoleVariables?._APP_VCS_ENABLED === true;
13+
// Not in the SDK's generated types yet -- server already returns it.
14+
let vcsProviders = ($regionalConsoleVariables as { _APP_VCS_PROVIDERS?: string[] })
15+
?._APP_VCS_PROVIDERS;
16+
let isGiteaEnabled = vcsProviders?.includes('gitea') ?? false;
1217
</script>
1318

1419
<Layout.Stack>
@@ -35,13 +40,24 @@
3540
title="No installation was added to the project yet"
3641
description="Add an installation to connect repositories">
3742
<svelte:fragment slot="actions">
38-
<Button
39-
secondary
40-
href={connectGitHub(callbackState).toString()}
41-
disabled={!isVcsEnabled}>
42-
<Icon slot="start" icon={IconGithub} />
43-
Connect to GitHub
44-
</Button>
43+
<Layout.Stack direction="row">
44+
<Button
45+
secondary
46+
href={connectGitHub(callbackState).toString()}
47+
disabled={!isVcsEnabled}>
48+
<Icon slot="start" icon={IconGithub} />
49+
Connect to GitHub
50+
</Button>
51+
{#if isGiteaEnabled}
52+
<Button
53+
secondary
54+
href={connectGitea(callbackState).toString()}
55+
disabled={!isVcsEnabled}>
56+
<Icon slot="start" icon={IconGitea} />
57+
Connect to Gitea
58+
</Button>
59+
{/if}
60+
</Layout.Stack>
4561
</svelte:fragment>
4662
</Empty>
4763
</Card.Base>

src/lib/stores/git.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
import { page } from '$app/state';
22
import { getApiEndpoint } from './sdk';
33

4-
export function connectGitHub(callbackState: Record<string, string> = null) {
4+
function connectVcsProvider(provider: string, callbackState: Record<string, string> = null) {
55
const redirect = new URL(page.url);
66
if (callbackState) {
77
Object.keys(callbackState).forEach((key) => {
88
redirect.searchParams.append(key, callbackState[key]);
99
});
1010
}
11-
const target = new URL(`${getApiEndpoint(page.params.region)}/vcs/github/authorize`);
11+
const target = new URL(`${getApiEndpoint(page.params.region)}/vcs/${provider}/authorize`);
1212
target.searchParams.set('project', page.params.project);
1313
target.searchParams.set('success', redirect.toString());
1414
target.searchParams.set('failure', redirect.toString());
1515
target.searchParams.set('mode', 'admin');
1616
return target;
1717
}
1818

19+
export function connectGitHub(callbackState: Record<string, string> = null) {
20+
return connectVcsProvider('github', callbackState);
21+
}
22+
23+
export function connectGitea(callbackState: Record<string, string> = null) {
24+
return connectVcsProvider('gitea', callbackState);
25+
}
26+
1927
export function deploymentStatusConverter(status: string) {
2028
// Status component possible values - status: 'waiting' | 'ready' | 'processing' | 'pending' | 'failed' | 'complete';
2129
switch (status) {

0 commit comments

Comments
 (0)