File size: 1,441 Bytes
fc1afe5
 
 
 
 
 
 
 
 
 
 
 
 
3c703c5
 
 
 
 
fc1afe5
 
 
 
 
 
3c703c5
 
 
fc1afe5
 
b790d50
fc1afe5
 
 
 
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
def commit_and_push_changes():
    import os
    import subprocess
    from pathlib import Path

    # Define the paths
    REPO_DIR = Path(".")  # Root directory of your Hugging Face Space repo
    DATA_DIR = REPO_DIR / "data/questions"  # Persistent storage in the repo
    JSONL_FILE = REPO_DIR / "output.jsonl"

    DATA_DIR.mkdir(parents=True, exist_ok=True)  # Ensure directory exists

    GIT_USER = os.getenv("GIT_USER")
    GIT_EMAIL = os.getenv("GIT_EMAIL")
    HF_OWNER = os.getenv("HF_OWNER")
    HF_TOKEN = os.getenv("HF_TOKEN")
    REPO_NAME = os.getenv("REPO_NAME")
    REPO_URL = f"https://{HF_OWNER}:{HF_TOKEN}@huggingface.co/spaces/{REPO_NAME}"

    # Set remote URL before pushing

    """Automates Git add, commit, and push for updated data."""
    try:
        # Run Git commands
        subprocess.run(["git", "config", "--global", "user.name", GIT_USER], check=True)
        subprocess.run(["git", "config", "--global", "user.email", GIT_EMAIL], check=True)
        subprocess.run(["git", "remote", "set-url", "origin", REPO_URL], check=True)
        subprocess.run(["git", "add", "--all"], check=True)
        subprocess.run(["git", "commit", "-m", "Update questions data"], check=True)
        subprocess.run(["git", "push", "origin", "main"], check=True)
        print("βœ… Data committed and pushed successfully!")
    
    except subprocess.CalledProcessError as e:
        print(f"❌ Git operation failed: {e}")