gitpush-tool 0.1.1__tar.gz → 0.1.2__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.2
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,13 @@ To push all local tags:
117
117
  gitpush_tool --tags
118
118
  ```
119
119
 
120
+ ### Creating and Pushing to a New GitHub Repository
121
+
122
+ To create a new GitHub repository and push your code in one command:
123
+
124
+ ```bash
125
+ gitpush_tool "Initial commit" --new-repo my-new-repo --description "My awesome project"
126
+
120
127
  ### Help
121
128
 
122
129
  To view all available commands and options:
@@ -92,6 +92,13 @@ To push all local tags:
92
92
  gitpush_tool --tags
93
93
  ```
94
94
 
95
+ ### Creating and Pushing to a New GitHub Repository
96
+
97
+ To create a new GitHub repository and push your code in one command:
98
+
99
+ ```bash
100
+ gitpush_tool "Initial commit" --new-repo my-new-repo --description "My awesome project"
101
+
95
102
  ### Help
96
103
 
97
104
  To view all available commands and options:
@@ -0,0 +1 @@
1
+ __version__ = "0.1.2"
@@ -0,0 +1,104 @@
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitpush-tool
3
- Version: 0.1.1
3
+ Version: 0.1.2
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,13 @@ To push all local tags:
117
117
  gitpush_tool --tags
118
118
  ```
119
119
 
120
+ ### Creating and Pushing to a New GitHub Repository
121
+
122
+ To create a new GitHub repository and push your code in one command:
123
+
124
+ ```bash
125
+ gitpush_tool "Initial commit" --new-repo my-new-repo --description "My awesome project"
126
+
120
127
  ### Help
121
128
 
122
129
  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.2",
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