gitpush-tool 0.1.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitpush-tool
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A CLI tool to simplify Git push operations with intelligent defaults and options.
5
5
  Home-page: https://github.com/yourusername/gitpush_tool
6
6
  Author: Ganesh Sonawane
@@ -117,6 +117,7 @@ To push all local tags:
117
117
  gitpush_tool --tags
118
118
  ```
119
119
 
120
+ <<<<<<< HEAD
120
121
  ### Creating and Pushing to a New GitHub Repository
121
122
 
122
123
  To create a new GitHub repository and push your code in one command:
@@ -124,6 +125,8 @@ To create a new GitHub repository and push your code in one command:
124
125
  ```bash
125
126
  gitpush_tool "Initial commit" --new-repo my-new-repo --description "My awesome project"
126
127
 
128
+ =======
129
+ >>>>>>> d1625633dae3f9eec5bfc0bc8727dd2f8bd2e98c
127
130
  ### Help
128
131
 
129
132
  To view all available commands and options:
@@ -92,6 +92,7 @@ To push all local tags:
92
92
  gitpush_tool --tags
93
93
  ```
94
94
 
95
+ <<<<<<< HEAD
95
96
  ### Creating and Pushing to a New GitHub Repository
96
97
 
97
98
  To create a new GitHub repository and push your code in one command:
@@ -99,6 +100,8 @@ To create a new GitHub repository and push your code in one command:
99
100
  ```bash
100
101
  gitpush_tool "Initial commit" --new-repo my-new-repo --description "My awesome project"
101
102
 
103
+ =======
104
+ >>>>>>> d1625633dae3f9eec5bfc0bc8727dd2f8bd2e98c
102
105
  ### Help
103
106
 
104
107
  To view all available commands and options:
@@ -0,0 +1 @@
1
+ __version__ = "0.1.4"
@@ -0,0 +1,166 @@
1
+ import os
2
+ import argparse
3
+ import sys
4
+ import requests
5
+ from getpass import getpass
6
+ import json
7
+
8
+ def get_github_token():
9
+ """Get GitHub token from various sources with priority order"""
10
+ # 1. Check environment variable
11
+ token = os.getenv("GITHUB_TOKEN")
12
+
13
+ # 2. Check token file
14
+ if not token:
15
+ token_path = os.path.join(os.path.dirname(__file__), '..', 'token')
16
+ if os.path.exists(token_path):
17
+ with open(token_path, 'r') as f:
18
+ token = f.read().strip()
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()
31
+
32
+ if not token:
33
+ print("❌ GitHub token is required to create a repository")
34
+ return None
35
+
36
+ headers = {
37
+ "Authorization": f"token {token}",
38
+ "Accept": "application/vnd.github+json",
39
+ "X-GitHub-Api-Version": "2022-11-28"
40
+ }
41
+
42
+ data = {
43
+ "name": repo_name,
44
+ "description": description,
45
+ "private": private,
46
+ "auto_init": False
47
+ }
48
+
49
+ try:
50
+ response = requests.post(
51
+ "https://api.github.com/user/repos",
52
+ headers=headers,
53
+ json=data
54
+ )
55
+
56
+ # Detailed error handling
57
+ if response.status_code == 401:
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")
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
+
84
+ elif response.status_code == 422:
85
+ error_data = response.json()
86
+ if 'errors' in error_data:
87
+ for error in error_data['errors']:
88
+ if error.get('field') == 'name' and 'already exists' in error.get('message', ''):
89
+ print(f"❌ Repository '{repo_name}' already exists")
90
+ return None
91
+ print(f"❌ Validation error: {error_data.get('message', 'Unknown error')}")
92
+ return None
93
+
94
+ elif response.status_code != 201:
95
+ print(f"❌ Failed to create repository (HTTP {response.status_code}): {response.text}")
96
+ return None
97
+
98
+ repo_url = response.json()["html_url"]
99
+ print(f"✅ Successfully created repository: {repo_url}")
100
+ return repo_url
101
+
102
+ except requests.exceptions.RequestException as e:
103
+ print(f"❌ Failed to create repository: {str(e)}")
104
+ if "Max retries exceeded" in str(e):
105
+ print("⚠️ Network connection problem detected")
106
+ return None
107
+
108
+ def run():
109
+ parser = argparse.ArgumentParser(
110
+ description="📦 CLI tool to automate git operations and GitHub repository creation"
111
+ )
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")
121
+
122
+ args = parser.parse_args()
123
+
124
+ if args.new_repo:
125
+ print(f"🆕 Creating repository: {args.new_repo}")
126
+ repo_url = create_github_repo(
127
+ args.new_repo,
128
+ private=args.private,
129
+ description=args.description or ""
130
+ )
131
+
132
+ if not repo_url:
133
+ sys.exit(1)
134
+
135
+ # Initialize git if needed
136
+ if not os.path.exists(".git"):
137
+ args.init = True
138
+
139
+ # Set remote
140
+ os.system(f"git remote add {args.remote} {repo_url}")
141
+
142
+ if args.init:
143
+ print("🛠 Initializing git repository")
144
+ os.system("git init")
145
+
146
+ os.system("git add .")
147
+
148
+ if args.commit:
149
+ print(f"📦 Committing: '{args.commit}'")
150
+ os.system(f'git commit -m "{args.commit}"')
151
+ else:
152
+ print("⚠️ Skipping commit (no message provided)")
153
+
154
+ push_cmd = "git push"
155
+ if args.force:
156
+ push_cmd += " --force-with-lease"
157
+ if args.tags:
158
+ push_cmd += " --tags"
159
+ if args.remote and args.branch:
160
+ push_cmd += f" {args.remote} {args.branch}"
161
+
162
+ print(f"🚀 Executing: {push_cmd}")
163
+ os.system(push_cmd)
164
+
165
+ if __name__ == "__main__":
166
+ run()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitpush-tool
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A CLI tool to simplify Git push operations with intelligent defaults and options.
5
5
  Home-page: https://github.com/yourusername/gitpush_tool
6
6
  Author: Ganesh Sonawane
@@ -117,6 +117,7 @@ To push all local tags:
117
117
  gitpush_tool --tags
118
118
  ```
119
119
 
120
+ <<<<<<< HEAD
120
121
  ### Creating and Pushing to a New GitHub Repository
121
122
 
122
123
  To create a new GitHub repository and push your code in one command:
@@ -124,6 +125,8 @@ To create a new GitHub repository and push your code in one command:
124
125
  ```bash
125
126
  gitpush_tool "Initial commit" --new-repo my-new-repo --description "My awesome project"
126
127
 
128
+ =======
129
+ >>>>>>> d1625633dae3f9eec5bfc0bc8727dd2f8bd2e98c
127
130
  ### Help
128
131
 
129
132
  To view all available commands and options:
@@ -3,7 +3,7 @@ from pathlib import Path
3
3
 
4
4
  setup(
5
5
  name="gitpush-tool",
6
- version="0.1.2",
6
+ version="0.1.4",
7
7
  packages=find_packages(),
8
8
  install_requires=[],
9
9
  entry_points={
@@ -1 +0,0 @@
1
- __version__ = "0.1.2"
@@ -1,104 +0,0 @@
1
- import os
2
- import argparse
3
- import sys
4
- import requests
5
- from getpass import getpass
6
-
7
- def create_github_repo(repo_name, private=False, description=""):
8
- """Create a new GitHub repository using the GitHub API"""
9
- # Get GitHub token from environment or prompt
10
- token = os.getenv("GITHUB_TOKEN")
11
- if not token:
12
- token_path = os.path.join(os.path.dirname(__file__), '..', 'token')
13
- if os.path.exists(token_path):
14
- with open(token_path, 'r') as f:
15
- token = f.read().strip()
16
- else:
17
- token = getpass("Enter your GitHub personal access token: ")
18
-
19
- headers = {
20
- "Authorization": f"token {token}",
21
- "Accept": "application/vnd.github.v3+json"
22
- }
23
- data = {
24
- "name": repo_name,
25
- "description": description,
26
- "private": private,
27
- "auto_init": False
28
- }
29
-
30
- try:
31
- response = requests.post(
32
- "https://api.github.com/user/repos",
33
- headers=headers,
34
- json=data
35
- )
36
- response.raise_for_status()
37
- return response.json()["html_url"]
38
- except requests.exceptions.RequestException as e:
39
- print(f"❌ Failed to create repository: {e}")
40
- return None
41
-
42
- def run():
43
- parser = argparse.ArgumentParser(
44
- description="📦 Simple CLI to automate git operations and GitHub repository creation."
45
- )
46
- parser.add_argument("commit", nargs="?", help="Commit message. If omitted, no commit will be made.")
47
- parser.add_argument("branch", nargs="?", default="main", help="Branch to push to (default: main).")
48
- parser.add_argument("remote", nargs="?", default="origin", help="Remote name (default: origin).")
49
- parser.add_argument("--force", action="store_true", help="Force push (use with caution).")
50
- parser.add_argument("--tags", action="store_true", help="Push all local tags.")
51
- parser.add_argument("--init", action="store_true", help="Run 'git init' before pushing.")
52
- parser.add_argument("--new-repo", metavar="REPO_NAME", help="Create a new GitHub repository with this name.")
53
- parser.add_argument("--private", action="store_true", help="Make the new repository private.")
54
- parser.add_argument("--description", help="Description for the new repository.")
55
-
56
- args = parser.parse_args()
57
-
58
- # Create new GitHub repository if requested
59
- if args.new_repo:
60
- print(f"🆕 Creating new GitHub repository: {args.new_repo}")
61
- repo_url = create_github_repo(
62
- args.new_repo,
63
- private=args.private,
64
- description=args.description or ""
65
- )
66
- if not repo_url:
67
- sys.exit(1)
68
-
69
- print(f"✅ Repository created: {repo_url}")
70
-
71
- # Initialize git if not already a repo
72
- if not os.path.exists(".git"):
73
- args.init = True
74
-
75
- # Set up git remote
76
- os.system(f"git remote add {args.remote} {repo_url}")
77
-
78
- if args.init:
79
- print("🛠 Initializing git repository...")
80
- os.system("git init")
81
-
82
- os.system("git add .")
83
-
84
- if args.commit:
85
- print(f"📦 Committing with message: '{args.commit}'")
86
- os.system(f'git commit -m "{args.commit}"')
87
- else:
88
- print("⚠️ No commit message provided. Skipping commit step.")
89
-
90
- push_cmd = "git push"
91
-
92
- if args.force:
93
- push_cmd += " --force-with-lease"
94
-
95
- if args.tags:
96
- push_cmd += " --tags"
97
-
98
- if args.remote and args.branch:
99
- push_cmd += f" {args.remote} {args.branch}"
100
- elif args.branch:
101
- push_cmd += f" origin {args.branch}"
102
-
103
- print(f"🚀 Running: {push_cmd}")
104
- os.system(push_cmd)
File without changes
File without changes
File without changes