-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_folder_repos.py
68 lines (47 loc) · 2.26 KB
/
add_folder_repos.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# import os
# from github import Github
# import subprocess
# def update_remote_urls(root_directory, username):
# # Iterate over each folder in the root directory
# for folder in os.listdir(root_directory):
# # Check if the path is a directory
# repo_path = os.path.join(root_directory, folder)
# if os.path.isdir(repo_path):
# try:
# # Change directory to the repository
# os.chdir(repo_path)
# # Update remote URL to point to your GitHub repository
# subprocess.run(["git", "remote", "set-url", "origin", f"https://github.com/{username}/{folder}.git"])
# print(f"Remote URL updated successfully for '{folder}' repository.")
# except Exception as e:
# print(f"Failed to update remote URL for '{folder}' repository: {e}")
# # Root directory containing subfolders (repositories)
# root_directory = os.path.dirname(__file__)
# # Your GitHub username
# # Update remote URLs for all subfolders
# update_remote_urls(root_directory, username)
# # GitHub credentials
# # Root directory containing folders to convert to repositories
# # Initialize GitHub instance
# g = Github(token)
# # Get the authenticated user (you)
# user = g.get_user()
# # Iterate over each folder in the root directory
# for folder in os.listdir(root_directory):
# # Check if the path is a directory
# if os.path.isdir(os.path.join(root_directory, folder)):
# try:
# # Create repository
# repo = user.create_repo(folder)
# print(f"Repository '{folder}' created successfully.")
# # Change directory to the folder
# os.chdir(os.path.join(root_directory, folder))
# # Initialize Git repository locally
# subprocess.run(["git", "init"])
# # Add GitHub repository as remote origin
# subprocess.run(["git", "remote", "add", "origin", f"https://github.com/{username}/{folder}.git"])
# # Push to GitHub
# subprocess.run(["git", "push", "-u", "origin", "master"])
# print(f"Repository '{folder}' pushed successfully.")
# except Exception as e:
# print(f"Failed to create or push repository '{folder}': {e}")