-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_github.py
More file actions
224 lines (188 loc) · 6.81 KB
/
setup_github.py
File metadata and controls
224 lines (188 loc) · 6.81 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/usr/bin/env python3
"""
GitHub Integration Setup Script
This script helps set up GitHub integration for your repository.
"""
import os
import subprocess
import sys
from pathlib import Path
GITHUB_USERNAME = "surajdeval"
GITHUB_REPO_NAME = "PRO_SOW_GPT"
GITHUB_REPO_URL = f"https://github.com/{GITHUB_USERNAME}/{GITHUB_REPO_NAME}.git"
def check_git_installed():
"""Check if Git is installed."""
try:
subprocess.run(["git", "--version"], capture_output=True, check=True)
return True
except (subprocess.CalledProcessError, FileNotFoundError):
return False
def initialize_git_repo():
"""Initialize Git repository if not already initialized."""
if os.path.exists(".git"):
print("✓ Git repository already initialized")
return True
try:
subprocess.run(["git", "init"], check=True)
print("✓ Git repository initialized")
return True
except subprocess.CalledProcessError as e:
print(f"✗ Error initializing Git repository: {e}")
return False
def configure_git_user():
"""Configure Git user name and email."""
try:
# Check if already configured
result = subprocess.run(
["git", "config", "user.name"],
capture_output=True,
text=True
)
if result.returncode == 0 and result.stdout.strip():
print(f"✓ Git user.name already set: {result.stdout.strip()}")
else:
subprocess.run(["git", "config", "user.name", GITHUB_USERNAME], check=True)
print(f"✓ Git user.name set to: {GITHUB_USERNAME}")
result = subprocess.run(
["git", "config", "user.email"],
capture_output=True,
text=True
)
if result.returncode == 0 and result.stdout.strip():
print(f"✓ Git user.email already set: {result.stdout.strip()}")
else:
email = input("Enter your GitHub email (or press Enter to skip): ").strip()
if email:
subprocess.run(["git", "config", "user.email", email], check=True)
print(f"✓ Git user.email set to: {email}")
except subprocess.CalledProcessError as e:
print(f"✗ Error configuring Git user: {e}")
return False
return True
def set_remote_repo(token=None):
"""Set up GitHub remote repository."""
try:
# Check if remote already exists
result = subprocess.run(
["git", "remote", "get-url", "origin"],
capture_output=True,
text=True
)
if result.returncode == 0:
print(f"✓ Remote 'origin' already exists: {result.stdout.strip()}")
if token:
# Update remote URL with token
remote_url = f"https://{token}@github.com/{GITHUB_USERNAME}/{GITHUB_REPO_NAME}.git"
subprocess.run(["git", "remote", "set-url", "origin", remote_url], check=True)
print("✓ Remote URL updated with authentication token")
else:
# Add remote
if token:
remote_url = f"https://{token}@github.com/{GITHUB_USERNAME}/{GITHUB_REPO_NAME}.git"
else:
remote_url = GITHUB_REPO_URL
subprocess.run(["git", "remote", "add", "origin", remote_url], check=True)
print(f"✓ Remote 'origin' added: {GITHUB_REPO_URL}")
return True
except subprocess.CalledProcessError as e:
print(f"✗ Error setting remote repository: {e}")
return False
def create_initial_commit():
"""Create initial commit if repository is empty."""
try:
# Check if there are any commits
result = subprocess.run(
["git", "rev-parse", "--verify", "HEAD"],
capture_output=True
)
if result.returncode == 0:
print("✓ Repository already has commits")
return True
# Check if there are changes to commit
result = subprocess.run(
["git", "status", "--porcelain"],
capture_output=True,
text=True
)
if not result.stdout.strip():
print("ℹ No changes to commit")
return True
# Add all files
subprocess.run(["git", "add", "."], check=True)
# Create initial commit
subprocess.run(
["git", "commit", "-m", "Initial commit: PRO SOW GPT workflow"],
check=True
)
print("✓ Initial commit created")
return True
except subprocess.CalledProcessError as e:
print(f"✗ Error creating initial commit: {e}")
return False
def main():
"""Main setup function."""
print("=" * 60)
print("GitHub Integration Setup")
print("=" * 60)
print()
# Check if Git is installed
if not check_git_installed():
print("✗ Git is not installed on your system.")
print("\nPlease install Git first:")
print(" - Download from: https://git-scm.com/download/win")
print(" - Or use: winget install Git.Git")
print("\nAfter installing Git, run this script again.")
return False
print("✓ Git is installed")
print()
# Get GitHub token
token = None
token_input = input("Enter your GitHub Personal Access Token (or press Enter to skip): ").strip()
if token_input:
token = token_input
print("✓ Token received (will be used for authentication)")
else:
print("ℹ No token provided - you'll need to authenticate manually")
print()
# Initialize repository
if not initialize_git_repo():
return False
# Configure Git user
if not configure_git_user():
return False
# Set remote repository
if not set_remote_repo(token):
return False
# Create initial commit
create_initial_commit()
print()
print("=" * 60)
print("Setup Complete!")
print("=" * 60)
print()
print("Next steps:")
print("1. Create the repository on GitHub:")
print(f" https://github.com/new")
print(f" Repository name: {GITHUB_REPO_NAME}")
print()
print("2. Push your code to GitHub:")
if token:
print(" git push -u origin main")
else:
print(" git push -u origin main")
print(" (You may be prompted for credentials)")
print()
print("3. Verify the integration:")
print(f" Visit: https://github.com/{GITHUB_USERNAME}/{GITHUB_REPO_NAME}")
print()
return True
if __name__ == "__main__":
try:
success = main()
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\n\nSetup cancelled by user")
sys.exit(1)
except Exception as e:
print(f"\n✗ Unexpected error: {e}")
sys.exit(1)