Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
|
| 3 |
from git import Repo
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
# Retrieve the environment variables
|
| 7 |
GITHUB_PAT = os.getenv('GITHUB_PAT')
|
|
@@ -11,11 +12,24 @@ GIT_repo = os.getenv('GIT_repo')
|
|
| 11 |
if GITHUB_PAT:
|
| 12 |
print("GITHUB_PAT set")
|
| 13 |
|
| 14 |
-
# Ensure the cloned_repo directory does not already exist
|
| 15 |
if not os.path.exists('cloned_repo'):
|
| 16 |
# Clone the repository using the Personal Access Token for authentication
|
| 17 |
Repo.clone_from(f'https://{GIT_id}:{GITHUB_PAT}@github.com/{GIT_id}/{GIT_repo}.git', './cloned_repo')
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
from git import Repo
|
| 4 |
import os
|
| 5 |
+
import shutil
|
| 6 |
|
| 7 |
# Retrieve the environment variables
|
| 8 |
GITHUB_PAT = os.getenv('GITHUB_PAT')
|
|
|
|
| 12 |
if GITHUB_PAT:
|
| 13 |
print("GITHUB_PAT set")
|
| 14 |
|
|
|
|
| 15 |
if not os.path.exists('cloned_repo'):
|
| 16 |
# Clone the repository using the Personal Access Token for authentication
|
| 17 |
Repo.clone_from(f'https://{GIT_id}:{GITHUB_PAT}@github.com/{GIT_id}/{GIT_repo}.git', './cloned_repo')
|
| 18 |
|
| 19 |
+
# Move all files from the cloned_repo directory to the current directory
|
| 20 |
+
for item in os.listdir('cloned_repo'):
|
| 21 |
+
source_path = os.path.join('cloned_repo', item)
|
| 22 |
+
destination_path = os.path.join('.', item)
|
| 23 |
+
|
| 24 |
+
# If it's a file, move it directly
|
| 25 |
+
if os.path.isfile(source_path):
|
| 26 |
+
shutil.move(source_path, destination_path)
|
| 27 |
+
# If it's a directory, move the entire directory
|
| 28 |
+
elif os.path.isdir(source_path):
|
| 29 |
+
if os.path.exists(destination_path):
|
| 30 |
+
shutil.rmtree(destination_path) # Remove if the directory already exists
|
| 31 |
+
shutil.move(source_path, destination_path)
|
| 32 |
+
|
| 33 |
+
# Now you can import the main module from the current directory
|
| 34 |
+
import main
|
| 35 |
+
from main import *
|