gitpush-tool 0.1.3__tar.gz → 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gitpush_tool-0.1.3/gitpush_tool.egg-info → gitpush_tool-0.1.4}/PKG-INFO +1 -1
- gitpush_tool-0.1.4/gitpush_tool/__init__.py +1 -0
- {gitpush_tool-0.1.3 → gitpush_tool-0.1.4}/gitpush_tool/cli.py +70 -44
- {gitpush_tool-0.1.3 → gitpush_tool-0.1.4/gitpush_tool.egg-info}/PKG-INFO +1 -1
- {gitpush_tool-0.1.3 → gitpush_tool-0.1.4}/setup.py +1 -1
- gitpush_tool-0.1.3/gitpush_tool/__init__.py +0 -1
- {gitpush_tool-0.1.3 → gitpush_tool-0.1.4}/LICENSE +0 -0
- {gitpush_tool-0.1.3 → gitpush_tool-0.1.4}/MANIFEST.in +0 -0
- {gitpush_tool-0.1.3 → gitpush_tool-0.1.4}/README.md +0 -0
- {gitpush_tool-0.1.3 → gitpush_tool-0.1.4}/gitpush_tool.egg-info/SOURCES.txt +0 -0
- {gitpush_tool-0.1.3 → gitpush_tool-0.1.4}/gitpush_tool.egg-info/dependency_links.txt +0 -0
- {gitpush_tool-0.1.3 → gitpush_tool-0.1.4}/gitpush_tool.egg-info/entry_points.txt +0 -0
- {gitpush_tool-0.1.3 → gitpush_tool-0.1.4}/gitpush_tool.egg-info/top_level.txt +0 -0
- {gitpush_tool-0.1.3 → gitpush_tool-0.1.4}/pyproject.toml +0 -0
- {gitpush_tool-0.1.3 → gitpush_tool-0.1.4}/setup.cfg +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.4"
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import argparse
|
|
3
|
-
import sys
|
|
4
|
-
import requests
|
|
5
|
-
from getpass import getpass
|
|
6
|
-
|
|
7
1
|
import os
|
|
8
2
|
import argparse
|
|
9
3
|
import sys
|
|
@@ -11,17 +5,29 @@ import requests
|
|
|
11
5
|
from getpass import getpass
|
|
12
6
|
import json
|
|
13
7
|
|
|
14
|
-
def
|
|
15
|
-
"""
|
|
16
|
-
#
|
|
8
|
+
def get_github_token():
|
|
9
|
+
"""Get GitHub token from various sources with priority order"""
|
|
10
|
+
# 1. Check environment variable
|
|
17
11
|
token = os.getenv("GITHUB_TOKEN")
|
|
12
|
+
|
|
13
|
+
# 2. Check token file
|
|
18
14
|
if not token:
|
|
19
15
|
token_path = os.path.join(os.path.dirname(__file__), '..', 'token')
|
|
20
16
|
if os.path.exists(token_path):
|
|
21
17
|
with open(token_path, 'r') as f:
|
|
22
18
|
token = f.read().strip()
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
|
|
20
|
+
# 3. Prompt user if still not found
|
|
21
|
+
if not token:
|
|
22
|
+
print("\n🔑 GitHub personal access token is required to create repositories.")
|
|
23
|
+
print("Create one at: https://github.com/settings/tokens (with 'repo' scope)")
|
|
24
|
+
token = getpass("Enter your GitHub token: ")
|
|
25
|
+
|
|
26
|
+
return token
|
|
27
|
+
|
|
28
|
+
def create_github_repo(repo_name, private=False, description=""):
|
|
29
|
+
"""Create a new GitHub repository using the GitHub API"""
|
|
30
|
+
token = get_github_token()
|
|
25
31
|
|
|
26
32
|
if not token:
|
|
27
33
|
print("❌ GitHub token is required to create a repository")
|
|
@@ -29,7 +35,8 @@ def create_github_repo(repo_name, private=False, description=""):
|
|
|
29
35
|
|
|
30
36
|
headers = {
|
|
31
37
|
"Authorization": f"token {token}",
|
|
32
|
-
"Accept": "application/vnd.github
|
|
38
|
+
"Accept": "application/vnd.github+json",
|
|
39
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
data = {
|
|
@@ -46,21 +53,44 @@ def create_github_repo(repo_name, private=False, description=""):
|
|
|
46
53
|
json=data
|
|
47
54
|
)
|
|
48
55
|
|
|
49
|
-
#
|
|
56
|
+
# Detailed error handling
|
|
50
57
|
if response.status_code == 401:
|
|
51
|
-
print("❌ Authentication failed.
|
|
52
|
-
print("
|
|
53
|
-
print("
|
|
58
|
+
print("❌ Authentication failed. Invalid or expired token.")
|
|
59
|
+
print("Please create a new token with 'repo' scope at:")
|
|
60
|
+
print("https://github.com/settings/tokens")
|
|
54
61
|
return None
|
|
62
|
+
|
|
63
|
+
elif response.status_code == 403:
|
|
64
|
+
print("❌ Permission denied (403 Forbidden). Possible reasons:")
|
|
65
|
+
print("- Token doesn't have 'repo' scope")
|
|
66
|
+
print("- Token is restricted to specific repositories")
|
|
67
|
+
print("- GitHub API rate limit exceeded")
|
|
68
|
+
|
|
69
|
+
# Try to get rate limit info
|
|
70
|
+
try:
|
|
71
|
+
limits = requests.get(
|
|
72
|
+
"https://api.github.com/rate_limit",
|
|
73
|
+
headers=headers
|
|
74
|
+
).json()
|
|
75
|
+
remaining = limits['resources']['core']['remaining']
|
|
76
|
+
reset_time = limits['resources']['core']['reset']
|
|
77
|
+
print(f"⏳ API calls remaining: {remaining}")
|
|
78
|
+
print(f"🔄 Rate limit resets at: {reset_time}")
|
|
79
|
+
except:
|
|
80
|
+
pass
|
|
81
|
+
|
|
82
|
+
return None
|
|
83
|
+
|
|
55
84
|
elif response.status_code == 422:
|
|
56
85
|
error_data = response.json()
|
|
57
86
|
if 'errors' in error_data:
|
|
58
87
|
for error in error_data['errors']:
|
|
59
88
|
if error.get('field') == 'name' and 'already exists' in error.get('message', ''):
|
|
60
|
-
print(f"❌ Repository '{repo_name}' already exists
|
|
89
|
+
print(f"❌ Repository '{repo_name}' already exists")
|
|
61
90
|
return None
|
|
62
91
|
print(f"❌ Validation error: {error_data.get('message', 'Unknown error')}")
|
|
63
92
|
return None
|
|
93
|
+
|
|
64
94
|
elif response.status_code != 201:
|
|
65
95
|
print(f"❌ Failed to create repository (HTTP {response.status_code}): {response.text}")
|
|
66
96
|
return None
|
|
@@ -77,64 +107,60 @@ def create_github_repo(repo_name, private=False, description=""):
|
|
|
77
107
|
|
|
78
108
|
def run():
|
|
79
109
|
parser = argparse.ArgumentParser(
|
|
80
|
-
description="📦
|
|
110
|
+
description="📦 CLI tool to automate git operations and GitHub repository creation"
|
|
81
111
|
)
|
|
82
|
-
parser.add_argument("commit", nargs="?", help="Commit message
|
|
83
|
-
parser.add_argument("branch", nargs="?", default="main", help="Branch
|
|
84
|
-
parser.add_argument("remote", nargs="?", default="origin", help="Remote name (default: origin)
|
|
85
|
-
parser.add_argument("--force", action="store_true", help="Force push
|
|
86
|
-
parser.add_argument("--tags", action="store_true", help="Push
|
|
87
|
-
parser.add_argument("--init", action="store_true", help="
|
|
88
|
-
parser.add_argument("--new-repo", metavar="
|
|
89
|
-
parser.add_argument("--private", action="store_true", help="Make
|
|
90
|
-
parser.add_argument("--description", help="
|
|
112
|
+
parser.add_argument("commit", nargs="?", help="Commit message")
|
|
113
|
+
parser.add_argument("branch", nargs="?", default="main", help="Branch name (default: main)")
|
|
114
|
+
parser.add_argument("remote", nargs="?", default="origin", help="Remote name (default: origin)")
|
|
115
|
+
parser.add_argument("--force", action="store_true", help="Force push with --force-with-lease")
|
|
116
|
+
parser.add_argument("--tags", action="store_true", help="Push tags")
|
|
117
|
+
parser.add_argument("--init", action="store_true", help="Initialize git repo")
|
|
118
|
+
parser.add_argument("--new-repo", metavar="NAME", help="Create new GitHub repository")
|
|
119
|
+
parser.add_argument("--private", action="store_true", help="Make repository private")
|
|
120
|
+
parser.add_argument("--description", help="Repository description")
|
|
91
121
|
|
|
92
122
|
args = parser.parse_args()
|
|
93
123
|
|
|
94
|
-
# Create new GitHub repository if requested
|
|
95
124
|
if args.new_repo:
|
|
96
|
-
print(f"🆕 Creating
|
|
125
|
+
print(f"🆕 Creating repository: {args.new_repo}")
|
|
97
126
|
repo_url = create_github_repo(
|
|
98
127
|
args.new_repo,
|
|
99
128
|
private=args.private,
|
|
100
129
|
description=args.description or ""
|
|
101
130
|
)
|
|
131
|
+
|
|
102
132
|
if not repo_url:
|
|
103
133
|
sys.exit(1)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
# Initialize git if not already a repo
|
|
134
|
+
|
|
135
|
+
# Initialize git if needed
|
|
108
136
|
if not os.path.exists(".git"):
|
|
109
137
|
args.init = True
|
|
110
|
-
|
|
111
|
-
# Set
|
|
138
|
+
|
|
139
|
+
# Set remote
|
|
112
140
|
os.system(f"git remote add {args.remote} {repo_url}")
|
|
113
141
|
|
|
114
142
|
if args.init:
|
|
115
|
-
print("🛠 Initializing git repository
|
|
143
|
+
print("🛠 Initializing git repository")
|
|
116
144
|
os.system("git init")
|
|
117
145
|
|
|
118
146
|
os.system("git add .")
|
|
119
147
|
|
|
120
148
|
if args.commit:
|
|
121
|
-
print(f"📦 Committing
|
|
149
|
+
print(f"📦 Committing: '{args.commit}'")
|
|
122
150
|
os.system(f'git commit -m "{args.commit}"')
|
|
123
151
|
else:
|
|
124
|
-
print("⚠️
|
|
152
|
+
print("⚠️ Skipping commit (no message provided)")
|
|
125
153
|
|
|
126
154
|
push_cmd = "git push"
|
|
127
|
-
|
|
128
155
|
if args.force:
|
|
129
156
|
push_cmd += " --force-with-lease"
|
|
130
|
-
|
|
131
157
|
if args.tags:
|
|
132
158
|
push_cmd += " --tags"
|
|
133
|
-
|
|
134
159
|
if args.remote and args.branch:
|
|
135
160
|
push_cmd += f" {args.remote} {args.branch}"
|
|
136
|
-
elif args.branch:
|
|
137
|
-
push_cmd += f" origin {args.branch}"
|
|
138
161
|
|
|
139
|
-
print(f"🚀
|
|
162
|
+
print(f"🚀 Executing: {push_cmd}")
|
|
140
163
|
os.system(push_cmd)
|
|
164
|
+
|
|
165
|
+
if __name__ == "__main__":
|
|
166
|
+
run()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.1.3"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|