File size: 861 Bytes
b2a5882
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c18bb0
 
 
 
 
 
 
 
 
b2a5882
 
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
import os
from github import Github
from dotenv import load_dotenv

from utils import log



def upload_to_github(file_path, content):
    load_dotenv(override=True)
    g = Github(os.getenv("GITHUB_TOKEN"))
    repo = g.get_repo("ljm565/adminsim-human-eval")
    try:
        contents = None
        try:
            contents = repo.get_contents(file_path, ref="main")
        except Exception:
            pass

        if contents is None:
            repo.create_file(file_path, "feat: Add new results", content, branch="main")
            log(f"File created successfully at {file_path}!")
        else:
            repo.update_file(file_path, "feat: Update the results", content, contents.sha, branch="main")
            log(f"File updated successfully at {file_path}!")
    
    except Exception as e:
        log(f"An error occurred: {e}", level="error")