File size: 1,375 Bytes
d903cfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
# Load load_dotenv to load the .env file
from dotenv import load_dotenv
from supabase import create_client, Client

load_dotenv()

url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)

def get_supabase() -> Client:
    return supabase

def post_github_access_token(token: str, user_emaill: str) -> None:
    supabase.table("users_github_access_tokens").insert({"github_access_token": token, "user_email": user_emaill}).execute()
    
def get_github_access_token(user_email: str):
    # Get the last access token
    table_results =  supabase.table("users_github_access_tokens").select("github_access_token").eq("user_email", user_email).execute()
    # Access the data attribute of the response object
    data = table_results.data

    # Check if there are results and return the last token
    if data:
        return data[-1]['github_access_token']
    else:
        return None  # or handle the case where there is no matching token

def post_github_repo(repo_name: str, user_email: str) -> None:
    supabase.table("users_github_repos_name").insert({"repo_name": repo_name, "user_email": user_email}).execute()
    
def get_github_repos(user_email: str) -> list:
    return supabase.table("users_github_repos_name").select("repo_name").eq("user_email", user_email).execute().get("data")