Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import shutil
|
|
5 |
import zipfile
|
6 |
from github import Github
|
7 |
from git import Repo
|
8 |
-
import
|
9 |
|
10 |
def download_github_repo(url, local_path):
|
11 |
if os.path.exists(local_path):
|
@@ -26,14 +26,14 @@ def create_repo(g, repo_name):
|
|
26 |
user = g.get_user()
|
27 |
return user.create_repo(repo_name)
|
28 |
|
29 |
-
def delete_repo(g, repo_name):
|
30 |
-
repo = g.get_repo(repo_name)
|
31 |
-
repo.delete()
|
32 |
-
|
33 |
def push_to_github(local_path, repo, github_token):
|
34 |
repo_url = f"https://{github_token}@github.com/{repo.full_name}.git"
|
35 |
repo = Repo(local_path)
|
36 |
-
origin
|
|
|
|
|
|
|
|
|
37 |
origin.push(refspec='{}:{}'.format('master', 'master'))
|
38 |
|
39 |
def main():
|
@@ -73,19 +73,18 @@ def main():
|
|
73 |
|
74 |
with st.spinner("Processing..."):
|
75 |
try:
|
76 |
-
# Generate a
|
77 |
-
|
|
|
|
|
78 |
|
79 |
# Download the source repository
|
80 |
download_github_repo(source_repo, local_path)
|
81 |
|
82 |
# Create a zip file
|
83 |
-
zip_filename = f"repo_contents_{
|
84 |
create_zip_file(local_path, zip_filename)
|
85 |
|
86 |
-
# Generate a unique repository name
|
87 |
-
new_repo_name = f"AIExample-Clone-{uuid.uuid4().hex[:8]}"
|
88 |
-
|
89 |
# Create the new repository
|
90 |
g = Github(github_token)
|
91 |
user = g.get_user()
|
|
|
5 |
import zipfile
|
6 |
from github import Github
|
7 |
from git import Repo
|
8 |
+
from datetime import datetime
|
9 |
|
10 |
def download_github_repo(url, local_path):
|
11 |
if os.path.exists(local_path):
|
|
|
26 |
user = g.get_user()
|
27 |
return user.create_repo(repo_name)
|
28 |
|
|
|
|
|
|
|
|
|
29 |
def push_to_github(local_path, repo, github_token):
|
30 |
repo_url = f"https://{github_token}@github.com/{repo.full_name}.git"
|
31 |
repo = Repo(local_path)
|
32 |
+
if 'origin' in [remote.name for remote in repo.remotes]:
|
33 |
+
origin = repo.remote('origin')
|
34 |
+
origin.set_url(repo_url)
|
35 |
+
else:
|
36 |
+
origin = repo.create_remote('origin', repo_url)
|
37 |
origin.push(refspec='{}:{}'.format('master', 'master'))
|
38 |
|
39 |
def main():
|
|
|
73 |
|
74 |
with st.spinner("Processing..."):
|
75 |
try:
|
76 |
+
# Generate a date-stamped name
|
77 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
78 |
+
new_repo_name = f"AIExample-Clone-{timestamp}"
|
79 |
+
local_path = f"./temp_repo_{timestamp}"
|
80 |
|
81 |
# Download the source repository
|
82 |
download_github_repo(source_repo, local_path)
|
83 |
|
84 |
# Create a zip file
|
85 |
+
zip_filename = f"repo_contents_{timestamp}"
|
86 |
create_zip_file(local_path, zip_filename)
|
87 |
|
|
|
|
|
|
|
88 |
# Create the new repository
|
89 |
g = Github(github_token)
|
90 |
user = g.get_user()
|