-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_utils.py
More file actions
47 lines (44 loc) · 1.42 KB
/
Copy pathgithub_utils.py
File metadata and controls
47 lines (44 loc) · 1.42 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
import streamlit as st
from github import Github
import base64
import os
def push_to_github(file_path, content, commit_message):
"""
Pousse un fichier modifié vers le dépôt GitHub.
Args:
file_path (str): Chemin du fichier (ex. 'data/clients.csv').
content (str): Contenu du fichier (CSV sous forme de string).
commit_message (str): Message du commit.
Returns:
bool: True si succès, False sinon.
"""
try:
# Récupérer les secrets
github_token = st.secrets["github"]["token"]
repo_name = st.secrets["github"]["repo"]
# Initialiser le client GitHub
g = Github(github_token)
repo = g.get_repo(repo_name)
# Vérifier si le fichier existe dans le dépôt
try:
file = repo.get_contents(file_path)
# Mettre à jour le fichier
repo.update_file(
path=file_path,
message=commit_message,
content=content,
sha=file.sha,
branch="master"
)
except:
# Créer le fichier s'il n'existe pas
repo.create_file(
path=file_path,
message=commit_message,
content=content,
branch="master"
)
return True
except Exception as e:
st.error(f"Erreur lors du push vers GitHub : {e}")
return False