Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

feat(git): one-click "Connect with GitHub" repo picker

Juan Denisfb96db72d426
diff --git a/frontend/src/components/git/GithubRepoPicker.jsx b/frontend/src/components/git/GithubRepoPicker.jsx
new file mode 100644
index 00000000..544d378c
--- /dev/null
+++ b/frontend/src/components/git/GithubRepoPicker.jsx
@@ -0,0 +1,178 @@
+import { useState, useEffect, useCallback } from 'react';
+import { SiGithub } from 'react-icons/si';
+import { Search, RefreshCw, Check } from 'lucide-react';
+import { Link } from 'react-router-dom';
+import api from '../../services/api';
+import { Button } from '@/components/ui/button';
+import { Input } from '@/components/ui/input';
+
+// One-click "Connect with GitHub" repo picker — the easy alternative to pasting a
+// clone URL. It reuses the SAME GitHub source-connection OAuth that the New
+// Service page already uses (no new backend), so any connect surface can offer
+// "authorize once, then pick a repo". It is purely a selection helper: it calls
+// onPick({ repoUrl, fullName, branch }) as the user chooses, and the host form
+// turns that into its own connect request.
+function cloneUrl(repo) {
+ return repo.clone_url || `https://github.com/${repo.full_name}.git`;
+}
+
+const GithubRepoPicker = ({ onPick }) => {
+ const [status, setStatus] = useState(null); // { configured, connection }
+ const [loading, setLoading] = useState(true);
+ const [repos, setRepos] = useState([]);
+ const [reposLoading, setReposLoading] = useState(false);
+ const [search, setSearch] = useState('');
+ const [selected, setSelected] = useState(null);
+ const [branches, setBranches] = useState([]);
+ const [branch, setBranch] = useState('');
+
+ const connection = status?.connection;
+ const configured = status?.configured;
+
+ const loadStatus = useCallback(async () => {
+ setLoading(true);
+ try {
+ setStatus(await api.getGithubSourceStatus());
+ } catch {
+ setStatus(null);
+ } finally {
+ setLoading(false);
+ }
+ }, []);
+
+ useEffect(() => { loadStatus(); }, [loadStatus]);
+
+ const loadRepos = useCallback(async (q = '') => {
+ setReposLoading(true);
+ try {
+ const data = await api.listGithubRepositories({ search: q, perPage: 80 });
+ setRepos(data.repos || []);
+ } catch {
+ setRepos([]);
+ } finally {
+ setReposLoading(false);
+ }
+ }, []);
+
+ useEffect(() => { if (connection) loadRepos(); }, [connection, loadRepos]);
+
+ // Picking a repo defaults the branch, loads its branch list, and emits.
+ useEffect(() => {
+ if (!selected) return undefined;
+ const b = selected.default_branch || 'main';
+ setBranch(b);
+ onPick?.({ repoUrl: cloneUrl(selected), fullName: selected.full_name, branch: b });
+ let cancelled = false;
+ api.listGithubBranches(selected.full_name)
+ .then((data) => { if (!cancelled) setBranches(data.branches || []); })
+ .catch(() => { if (!cancelled) setBranches([]); });
+ return () => { cancelled = true; };
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [selected]);
+
+ function pickBranch(b) {
+ setBranch(b);
+ if (selected) onPick?.({ repoUrl: cloneUrl(selected), fullName: selected.full_name, branch: b });
+ }
+
+ async function connectGithub() {
+ try {
+ const redirectUri = `${window.location.origin}/connections/callback/github`;
+ sessionStorage.setItem('sourceConnectionReturnTo', window.location.pathname + window.location.search);
+ const { auth_url } = await api.startSourceConnection('github', redirectUri);
+ window.location.href = auth_url;
+ } catch {
+ /* a retry surfaces the host's toast; nothing to do here */
+ }
+ }
+
+ if (loading) return null;
+
+ // No OAuth app configured — nudge to Settings, but never block the paste-URL
+ // path the host form still renders below this.
+ if (!configured) {
+ return (
+ <div className="git-connect__gh git-connect__gh--hint">
+ <SiGithub size={15} aria-hidden="true" />
+ <span>
+ Set up the GitHub connection in <Link to="/settings/connections">Settings</Link> to
+ pick a repo in one click instead of pasting a URL.
+ </span>
+ </div>
+ );
+ }
+
+ if (!connection) {
+ return (
+ <div className="git-connect__gh git-connect__gh--connect">
+ <SiGithub size={18} aria-hidden="true" />
+ <div className="git-connect__gh-text">
+ <strong>Connect with GitHub</strong>
+ <span>Authorize once, then choose a repository instead of pasting a URL.</span>
+ </div>
+ <Button type="button" onClick={connectGithub}>
+ <SiGithub size={15} /> Connect GitHub
+ </Button>
+ </div>
+ );
+ }
+
+ return (
+ <div className="git-connect__gh git-connect__gh--picker">
+ <div className="git-connect__gh-account">
+ {connection.avatar_url && <img src={connection.avatar_url} alt="" />}
+ <span className="git-connect__gh-account-name">
+ <strong>{connection.display_name || connection.provider_username}</strong>
+ <small>@{connection.provider_username}</small>
+ </span>
+ <Button type="button" variant="outline" size="sm" onClick={() => loadRepos(search)}>
+ <RefreshCw size={14} className={reposLoading ? 'spinning' : ''} /> Refresh
+ </Button>
+ </div>
+
+ <div className="git-connect__gh-search">
+ <Search size={15} aria-hidden="true" />
+ <Input
+ value={search}
+ onChange={(e) => setSearch(e.target.value)}
+ placeholder="Search your repositories"
+ onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); loadRepos(search); } }}
+ />
+ </div>
+
+ <div className="git-connect__gh-list">
+ {reposLoading && <div className="git-connect__gh-state">Loading repositories…</div>}
+ {!reposLoading && repos.length === 0 && <div className="git-connect__gh-state">No repositories found.</div>}
+ {!reposLoading && repos.map((repo) => (
+ <button
+ type="button"
+ key={repo.id}
+ className={`git-connect__gh-repo${selected?.id === repo.id ? ' is-active' : ''}`}
+ onClick={() => setSelected(repo)}
+ >
+ <span className="git-connect__gh-repo-main">
+ <strong>{repo.full_name}</strong>
+ <small>{repo.description || repo.language || 'No description'}</small>
+ </span>
+ <span className="git-connect__gh-repo-vis">{repo.private ? 'Private' : 'Public'}</span>
+ {selected?.id === repo.id && <Check size={15} />}
+ </button>
+ ))}
+ </div>
+
+ {selected && branches.length > 0 && (
+ <div className="git-connect__gh-branch">
+ <label htmlFor="gh-branch">Branch</label>
+ <select id="gh-branch" value={branch} onChange={(e) => pickBranch(e.target.value)}>
+ {branches.map((b) => {
+ const name = typeof b === 'string' ? b : b.name;
+ return <option key={name} value={name}>{name}</option>;
+ })}
+ </select>
+ </div>
+ )}
+ </div>
+ );
+};
+
+export default GithubRepoPicker;
diff --git a/frontend/src/components/git/RepoConnectForm.jsx b/frontend/src/components/git/RepoConnectForm.jsx
index 4b400094..74e5b4b1 100644
--- a/frontend/src/components/git/RepoConnectForm.jsx
+++ b/frontend/src/components/git/RepoConnectForm.jsx
@@ -6,6 +6,7 @@ import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import { Switch } from '@/components/ui/switch';
import { RepoProviderStrip, ProviderBadge, detectProvider } from './GitProviders';
+import GithubRepoPicker from './GithubRepoPicker';
// Canonical "connect a repository" form, shared across ServerKit's surfaces
// (WordPress Git settings, the New Service page, the service connect modal).
@@ -39,6 +40,7 @@ const RepoConnectForm = ({
urlPlaceholder = 'https://github.com/user/repo.git',
submitLabel = 'Connect Repository',
idPrefix = 'repo',
+ enableGithub = true,
}) => {
const [formData, setFormData] = useState({
repoUrl: '',
@@ -159,6 +161,17 @@ const RepoConnectForm = ({
<RepoProviderStrip detected={provider?.key} />
+ {enableGithub && (
+ <>
+ <GithubRepoPicker
+ onPick={({ repoUrl, branch }) =>
+ setFormData((p) => ({ ...p, repoUrl, branch: branch || p.branch }))
+ }
+ />
+ <div className="git-connect__or"><span>or connect by URL</span></div>
+ </>
+ )}
+
{error && <div className="error-message">{error}</div>}
<div className="git-connect__field">
diff --git a/frontend/src/styles/components/_git-connect.scss b/frontend/src/styles/components/_git-connect.scss
index 30115094..94a3c5f4 100644
--- a/frontend/src/styles/components/_git-connect.scss
+++ b/frontend/src/styles/components/_git-connect.scss
@@ -315,3 +315,157 @@
justify-content: flex-end;
}
}
+
+// ---- GitHub one-click picker (GithubRepoPicker) ----------------------------
+// The "connect with GitHub" fast path that sits above the paste-a-URL field in
+// RepoConnectForm. Reuses the same OAuth as /services/new.
+.git-connect__or {
+ display: flex;
+ align-items: center;
+ gap: $space-3;
+ color: var(--text-faint);
+ font-size: 11.5px;
+ text-transform: uppercase;
+ letter-spacing: 0.06em;
+
+ &::before,
+ &::after {
+ content: "";
+ flex: 1;
+ height: 1px;
+ background: var(--border-soft);
+ }
+}
+
+.git-connect__gh {
+ border: 1px solid var(--border-soft);
+ border-radius: var(--radius);
+ background: var(--surface-2);
+
+ &--hint {
+ display: flex;
+ align-items: center;
+ gap: 9px;
+ padding: 11px 13px;
+ font-size: 12.5px;
+ color: var(--text-dim);
+
+ a { color: var(--accent-bright); }
+ svg { color: var(--text-faint); flex-shrink: 0; }
+ }
+
+ &--connect {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ padding: 14px 15px;
+
+ > svg { color: var(--text); flex-shrink: 0; }
+ }
+
+ &-text {
+ display: flex;
+ flex-direction: column;
+ flex: 1;
+ min-width: 0;
+
+ strong { font-size: 13.5px; }
+ span { font-size: 12px; color: var(--text-faint); }
+ }
+
+ &--picker { padding: 12px; display: grid; gap: 10px; }
+
+ &-account {
+ display: flex;
+ align-items: center;
+ gap: 9px;
+
+ img { width: 26px; height: 26px; border-radius: 50%; }
+ .git-connect__gh-account-name {
+ display: flex;
+ flex-direction: column;
+ line-height: 1.25;
+ strong { font-size: 13px; }
+ small { font-size: 11px; color: var(--text-faint); }
+ }
+ > .ui-button { margin-left: auto; }
+ }
+
+ &-search {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ padding: 0 10px;
+ background: var(--surface);
+ border: 1px solid var(--border-soft);
+ border-radius: 8px;
+
+ svg { color: var(--text-faint); flex-shrink: 0; }
+ .ui-input { border: none; background: none; padding-left: 0; height: 34px; }
+ }
+
+ &-list {
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+ max-height: 240px;
+ overflow-y: auto;
+ }
+
+ &-state { padding: 12px; font-size: 12.5px; color: var(--text-faint); text-align: center; }
+
+ &-repo {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ padding: 9px 11px;
+ border: 1px solid var(--border-soft);
+ border-radius: 8px;
+ background: var(--surface);
+ text-align: left;
+ cursor: pointer;
+ transition: border-color 0.14s, background 0.14s;
+
+ &:hover { border-color: var(--border-strong); }
+ &.is-active {
+ border-color: var(--accent-bright);
+ background: var(--accent-bg);
+ svg { color: var(--accent-bright); margin-left: auto; flex-shrink: 0; }
+ }
+ }
+
+ &-repo-main {
+ display: flex;
+ flex-direction: column;
+ flex: 1;
+ min-width: 0;
+
+ strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+ small { font-size: 11.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+ }
+
+ &-repo-vis {
+ font-family: var(--mono);
+ font-size: 10.5px;
+ color: var(--text-faint);
+ flex-shrink: 0;
+ }
+
+ &-branch {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ font-size: 12.5px;
+
+ label { color: var(--text-dim); }
+ select {
+ flex: 1;
+ height: 34px;
+ padding: 0 10px;
+ background: var(--surface);
+ border: 1px solid var(--border-soft);
+ border-radius: 8px;
+ color: var(--text);
+ }
+ }
+}