GuaccO commited on
Commit
40b4024
·
verified ·
1 Parent(s): 9de8b68

It doesnt connects me still to them, maybe can I upload files to make it easier?

Browse files
Files changed (5) hide show
  1. README.md +8 -5
  2. api/github-auth.js +51 -0
  3. index.html +113 -19
  4. script.js +115 -0
  5. style.css +23 -19
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Githubsupabasesync Wizard
3
- emoji: 🔥
4
- colorFrom: blue
5
- colorTo: gray
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: GitHubSupabaseSync Wizard 🧙
3
+ colorFrom: red
4
+ colorTo: pink
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://huggingface.co/deepsite).
api/github-auth.js ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { createClient } from '@supabase/supabase-js';
2
+
3
+ export default async function handler(req, res) {
4
+ if (req.method !== 'POST') {
5
+ return res.status(405).json({ message: 'Method not allowed' });
6
+ }
7
+
8
+ const { code } = req.body;
9
+
10
+ try {
11
+ // Exchange GitHub code for access token
12
+ const response = await fetch('https://github.com/login/oauth/access_token', {
13
+ method: 'POST',
14
+ headers: {
15
+ 'Content-Type': 'application/json',
16
+ 'Accept': 'application/json'
17
+ },
18
+ body: JSON.stringify({
19
+ client_id: process.env.GITHUB_CLIENT_ID,
20
+ client_secret: process.env.GITHUB_CLIENT_SECRET,
21
+ code,
22
+ redirect_uri: process.env.GITHUB_REDIRECT_URI
23
+ })
24
+ });
25
+
26
+ const data = await response.json();
27
+
28
+ if (data.error) {
29
+ throw new Error(data.error_description || 'GitHub authentication failed');
30
+ }
31
+
32
+ // Store the token in Supabase (optional)
33
+ const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY);
34
+ await supabase
35
+ .from('user_tokens')
36
+ .upsert({
37
+ user_id: req.session.user.id, // You'd need session management
38
+ github_token: data.access_token,
39
+ updated_at: new Date().toISOString()
40
+ });
41
+
42
+ res.status(200).json({
43
+ access_token: data.access_token,
44
+ token_type: data.token_type,
45
+ scope: data.scope
46
+ });
47
+ } catch (error) {
48
+ console.error('GitHub auth error:', error);
49
+ res.status(500).json({ message: error.message });
50
+ }
51
+ }
index.html CHANGED
@@ -1,19 +1,113 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>GitHub ↔️ Supabase Connector</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <script src="https://unpkg.com/feather-icons"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
11
+ <script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
12
+ </head>
13
+ <body class="bg-gray-50 min-h-screen">
14
+ <custom-navbar></custom-navbar>
15
+
16
+ <main class="container mx-auto px-4 py-12">
17
+ <div class="max-w-3xl mx-auto bg-white rounded-xl shadow-md overflow-hidden p-8">
18
+ <div class="text-center mb-10">
19
+ <h1 class="text-3xl font-bold text-gray-800 mb-2">Connect GitHub ↔️ Supabase</h1>
20
+ <p class="text-gray-600">Seamlessly integrate your GitHub repositories with Supabase for automated deployments</p>
21
+ </div>
22
+
23
+ <div class="grid md:grid-cols-2 gap-8">
24
+ <!-- GitHub Connection -->
25
+ <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
26
+ <div class="flex items-center mb-4">
27
+ <i data-feather="github" class="w-6 h-6 mr-2 text-gray-800"></i>
28
+ <h2 class="text-xl font-semibold text-gray-800">GitHub Setup</h2>
29
+ </div>
30
+ <p class="text-gray-600 mb-4">Connect your GitHub account to enable repository access.</p>
31
+ <button id="githubAuth" class="w-full bg-gray-800 hover:bg-gray-700 text-white py-2 px-4 rounded-lg flex items-center justify-center">
32
+ <i data-feather="github" class="w-5 h-5 mr-2"></i>
33
+ Connect GitHub
34
+ </button>
35
+ <div id="githubStatus" class="mt-4 text-sm text-gray-500 hidden">
36
+ <i data-feather="check-circle" class="w-4 h-4 inline mr-1 text-green-500"></i>
37
+ <span>Connected</span>
38
+ </div>
39
+ </div>
40
+
41
+ <!-- Supabase Connection -->
42
+ <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
43
+ <div class="flex items-center mb-4">
44
+ <i data-feather="database" class="w-6 h-6 mr-2 text-gray-800"></i>
45
+ <h2 class="text-xl font-semibold text-gray-800">Supabase Setup</h2>
46
+ </div>
47
+ <div class="space-y-4">
48
+ <div>
49
+ <label class="block text-sm font-medium text-gray-700 mb-1">Project URL</label>
50
+ <input type="text" id="supabaseUrl" placeholder="https://your-project-ref.supabase.co" class="w-full px-3 py-2 border border-gray-300 rounded-md">
51
+ </div>
52
+ <div>
53
+ <label class="block text-sm font-medium text-gray-700 mb-1">API Key</label>
54
+ <input type="password" id="supabaseKey" placeholder="your-anon-key" class="w-full px-3 py-2 border border-gray-300 rounded-md">
55
+ </div>
56
+ <button id="supabaseConnect" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white py-2 px-4 rounded-lg">
57
+ Connect Supabase
58
+ </button>
59
+ <div id="supabaseStatus" class="text-sm text-gray-500 hidden">
60
+ <i data-feather="check-circle" class="w-4 h-4 inline mr-1 text-green-500"></i>
61
+ <span>Connected</span>
62
+ </div>
63
+ </div>
64
+ </div>
65
+ </div>
66
+
67
+ <!-- Configuration Panel (shown after both connected) -->
68
+ <div id="configPanel" class="mt-10 hidden">
69
+ <h2 class="text-xl font-semibold text-gray-800 mb-4">Configuration</h2>
70
+ <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
71
+ <div class="grid md:grid-cols-2 gap-6">
72
+ <div>
73
+ <label class="block text-sm font-medium text-gray-700 mb-1">Select Repository</label>
74
+ <select id="repoSelect" class="w-full px-3 py-2 border border-gray-300 rounded-md">
75
+ <option value="">Loading repositories...</option>
76
+ </select>
77
+ </div>
78
+ <div>
79
+ <label class="block text-sm font-medium text-gray-700 mb-1">Select Branch</label>
80
+ <select id="branchSelect" class="w-full px-3 py-2 border border-gray-300 rounded-md" disabled>
81
+ <option value="">Select repository first</option>
82
+ </select>
83
+ </div>
84
+ </div>
85
+ <div class="mt-4">
86
+ <label class="block text-sm font-medium text-gray-700 mb-1">Deployment Hook URL</label>
87
+ <input type="text" id="hookUrl" placeholder="https://api.supabase.com/v1/hooks/..." class="w-full px-3 py-2 border border-gray-300 rounded-md">
88
+ </div>
89
+ <button id="saveConfig" class="mt-6 bg-green-600 hover:bg-green-700 text-white py-2 px-6 rounded-lg">
90
+ Save Configuration
91
+ </button>
92
+ </div>
93
+ </div>
94
+ </div>
95
+ </main>
96
+
97
+ <custom-footer></custom-footer>
98
+
99
+ <script src="components/navbar.js"></script>
100
+ <script src="components/footer.js"></script>
101
+ <script src="script.js"></script>
102
+ <script>
103
+ feather.replace();
104
+
105
+ // Check for GitHub auth status
106
+ if (localStorage.getItem('githubToken')) {
107
+ document.getElementById('githubAuth').classList.add('hidden');
108
+ document.getElementById('githubStatus').classList.remove('hidden');
109
+ }
110
+ </script>
111
+ <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
112
+ </body>
113
+ </html>
script.js ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ // Shared JavaScript across all pages
3
+ document.addEventListener('DOMContentLoaded', () => {
4
+ // Initialize Supabase client when page loads
5
+ let supabase = null;
6
+
7
+ // GitHub OAuth flow
8
+ document.getElementById('githubAuth').addEventListener('click', () => {
9
+ // Redirect to GitHub OAuth
10
+ window.location.href = `https://github.com/login/oauth/authorize?client_id=${encodeURIComponent('YOUR_GITHUB_CLIENT_ID')}&scope=${encodeURIComponent('repo,admin:repo_hook')}&redirect_uri=${encodeURIComponent(window.location.origin + '/auth/github/callback')}`;
11
+ });
12
+ // Supabase connection
13
+ document.getElementById('supabaseConnect').addEventListener('click', async () => {
14
+ const url = document.getElementById('supabaseUrl').value;
15
+ const key = document.getElementById('supabaseKey').value;
16
+
17
+ if (!url || !key) {
18
+ alert('Please enter both Supabase URL and API Key');
19
+ return;
20
+ }
21
+
22
+ try {
23
+ supabase = createClient(url, key);
24
+
25
+ // Test connection by making a simple request
26
+ const { data, error } = await supabase.from('profiles').select('*').limit(1);
27
+
28
+ if (error) throw error;
29
+
30
+ // Connection successful
31
+ document.getElementById('supabaseConnect').classList.add('hidden');
32
+ document.getElementById('supabaseStatus').classList.remove('hidden');
33
+
34
+ // If GitHub is also connected, show config panel
35
+ if (localStorage.getItem('githubToken')) {
36
+ document.getElementById('configPanel').classList.remove('hidden');
37
+ loadRepositories();
38
+ }
39
+ } catch (error) {
40
+ alert('Supabase connection failed: ' + error.message);
41
+ }
42
+ });
43
+ // Repository selection
44
+ document.getElementById('repoSelect').addEventListener('change', (e) => {
45
+ if (e.target.value) {
46
+ simulateLoadBranches(e.target.value);
47
+ }
48
+ });
49
+
50
+ // Save configuration
51
+ document.getElementById('saveConfig').addEventListener('click', () => {
52
+ const repo = document.getElementById('repoSelect').value;
53
+ const branch = document.getElementById('branchSelect').value;
54
+ const hookUrl = document.getElementById('hookUrl').value;
55
+
56
+ if (repo && branch && hookUrl) {
57
+ alert('Configuration saved successfully!');
58
+ // In a real app, this would save to your backend or Supabase
59
+ } else {
60
+ alert('Please complete all configuration fields');
61
+ }
62
+ });
63
+ });
64
+ async function loadRepositories() {
65
+ try {
66
+ const response = await fetch('https://api.github.com/user/repos', {
67
+ headers: {
68
+ 'Authorization': `token ${localStorage.getItem('githubToken')}`
69
+ }
70
+ });
71
+
72
+ if (!response.ok) throw new Error('Failed to fetch repositories');
73
+
74
+ const repos = await response.json();
75
+ const select = document.getElementById('repoSelect');
76
+
77
+ select.innerHTML = '<option value="">Select a repository</option>';
78
+ repos.forEach(repo => {
79
+ const option = document.createElement('option');
80
+ option.value = repo.full_name;
81
+ option.textContent = repo.name;
82
+ select.appendChild(option);
83
+ });
84
+
85
+ select.disabled = false;
86
+ } catch (error) {
87
+ alert('Error loading repositories: ' + error.message);
88
+ }
89
+ }
90
+ // Handle GitHub OAuth callback
91
+ if (window.location.pathname === '/auth/github/callback') {
92
+ const code = new URLSearchParams(window.location.search).get('code');
93
+
94
+ if (code) {
95
+ // Exchange code for access token
96
+ fetch('/api/github-auth', {
97
+ method: 'POST',
98
+ headers: {
99
+ 'Content-Type': 'application/json'
100
+ },
101
+ body: JSON.stringify({ code })
102
+ })
103
+ .then(response => response.json())
104
+ .then(data => {
105
+ localStorage.setItem('githubToken', data.access_token);
106
+ window.location.href = '/'; // Redirect back to main page
107
+ })
108
+ .catch(error => {
109
+ console.error('GitHub auth failed:', error);
110
+ alert('GitHub authentication failed');
111
+ });
112
+ }
113
+ }
114
+ function checkConnectionStatus() {
115
+ const githubConnected = !document.getElementById('github
style.css CHANGED
@@ -1,28 +1,32 @@
 
 
 
1
  body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
 
 
4
  }
5
 
6
- h1 {
7
- font-size: 16px;
8
- margin-top: 0;
9
  }
10
 
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
 
16
  }
17
 
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
24
  }
25
 
26
- .card p:last-child {
27
- margin-bottom: 0;
28
- }
 
1
+ /* Shared styles across all pages */
2
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
3
+
4
  body {
5
+ font-family: 'Inter', sans-serif;
6
+ display: flex;
7
+ flex-direction: column;
8
+ min-height: 100vh;
9
  }
10
 
11
+ /* Button transitions */
12
+ button {
13
+ transition: all 0.2s ease-in-out;
14
  }
15
 
16
+ /* Input focus styles */
17
+ input:focus, select:focus {
18
+ outline: none;
19
+ ring: 2px;
20
+ ring-color: rgba(99, 102, 241, 0.5);
21
+ border-color: rgba(99, 102, 241, 0.8);
22
  }
23
 
24
+ /* Animation for status messages */
25
+ @keyframes fadeIn {
26
+ from { opacity: 0; transform: translateY(5px); }
27
+ to { opacity: 1; transform: translateY(0); }
 
 
28
  }
29
 
30
+ .status-message {
31
+ animation: fadeIn 0.3s ease-out;
32
+ }