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