commitmessagegenerator 1.5.0__tar.gz → 2.2.0__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.
Files changed (18) hide show
  1. {commitmessagegenerator-1.5.0 → commitmessagegenerator-2.2.0}/PKG-INFO +40 -2
  2. commitmessagegenerator-2.2.0/README.md +103 -0
  3. commitmessagegenerator-2.2.0/commitmessagegenerator/cli.py +168 -0
  4. commitmessagegenerator-2.2.0/commitmessagegenerator/configure.py +103 -0
  5. {commitmessagegenerator-1.5.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator/generator.py +11 -6
  6. {commitmessagegenerator-1.5.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator.egg-info/PKG-INFO +40 -2
  7. {commitmessagegenerator-1.5.0 → commitmessagegenerator-2.2.0}/pyproject.toml +1 -1
  8. commitmessagegenerator-1.5.0/README.md +0 -65
  9. commitmessagegenerator-1.5.0/commitmessagegenerator/cli.py +0 -40
  10. commitmessagegenerator-1.5.0/commitmessagegenerator/configure.py +0 -22
  11. {commitmessagegenerator-1.5.0 → commitmessagegenerator-2.2.0}/LICENSE +0 -0
  12. {commitmessagegenerator-1.5.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator/__init__.py +0 -0
  13. {commitmessagegenerator-1.5.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator.egg-info/SOURCES.txt +0 -0
  14. {commitmessagegenerator-1.5.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator.egg-info/dependency_links.txt +0 -0
  15. {commitmessagegenerator-1.5.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator.egg-info/entry_points.txt +0 -0
  16. {commitmessagegenerator-1.5.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator.egg-info/requires.txt +0 -0
  17. {commitmessagegenerator-1.5.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator.egg-info/top_level.txt +0 -0
  18. {commitmessagegenerator-1.5.0 → commitmessagegenerator-2.2.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commitmessagegenerator
3
- Version: 1.5.0
3
+ Version: 2.2.0
4
4
  Summary: Generate commit messages with AI (Google Gemini) automatically using `git diff`.
5
5
  Author-email: Gabriel Terceiro <gcarolinoterceiro@gmail.com>
6
6
  License: MIT
@@ -35,6 +35,14 @@ pip install commitmessagegenerator
35
35
  commitgen -cf
36
36
  ```
37
37
 
38
+ This opens an interactive configuration menu where you can:
39
+
40
+ 1. Set or update your Gemini API key
41
+ 2. Change the AI model
42
+ 3. Configure file staging behavior
43
+
44
+ Each option can be configured independently, and you can exit at any time without saving changes.
45
+
38
46
  ## Run this and type you API key to the terminal so the package creates the .env file and automatically adds it to the .gitignore
39
47
 
40
48
  Or do it manually:
@@ -45,6 +53,8 @@ Create a `.env` file in the directory where you will run commitgen (usually the
45
53
 
46
54
  ```
47
55
  GEMINI_API_KEY=your-gemini-api-key
56
+ AI_MODEL=gemini-2.0-flash
57
+ AUTO_ADD_ALL=true
48
58
  ```
49
59
 
50
60
  ## 🚀 Usage
@@ -58,9 +68,37 @@ commitgen (-c/-cp)
58
68
  The command will:
59
69
 
60
70
  - Read the git diff;
61
- - Send it to the Google Gemini API;
71
+ - Send it to the Google Gemini API using your configured model;
62
72
  - Return a commit message suggestion directly in your terminal.
63
73
 
74
+ ### Available Commands
75
+
76
+ - `commitgen` - Generate commit message only
77
+ - `commitgen -c` - Generate and commit with the message
78
+ - `commitgen -cp` - Generate, commit, and push
79
+ - `commitgen -cf` - Configure API key, model, and file staging behavior
80
+ - `commitgen -s` - Show current configuration status
81
+
82
+ ### Available Models
83
+
84
+ When configuring with `-cf`, you can choose from:
85
+
86
+ 1. **gemini-2.0-flash** (default) - Fast and efficient
87
+ 2. **gemini-1.5-flash** - Good balance of speed and quality
88
+ 3. **gemini-1.5-pro** - Highest quality, slower
89
+ 4. **gemini-2.0-flash-exp** - Experimental version
90
+ 5. **gemini-2.5-flash** - Latest version, fast and efficient
91
+ 6. **gemini-2.5-pro** - Latest version, highest quality
92
+
93
+ ### File Staging Behavior
94
+
95
+ When configuring with `-cf`, you can choose how files are staged:
96
+
97
+ 1. **Auto-add all files** (default) - Automatically runs `git add --all` before generating the commit message
98
+ 2. **Staged only** - Only reads the diff from files you've already staged with `git add`
99
+
100
+ The "staged only" option gives you more control over which changes are included in the commit message.
101
+
64
102
  ## 🧩 Requisites
65
103
 
66
104
  - Python 3.8 or higher
@@ -0,0 +1,103 @@
1
+ # commitmessagegenerator
2
+
3
+ Generate objective and technical commit messages with AI (Google Gemini) automatically using your `git diff`.
4
+
5
+ ## 📦 Install
6
+
7
+ ```bash
8
+ pip install commitmessagegenerator
9
+ ```
10
+
11
+ Or, if you're using a `venv`:
12
+
13
+ ```bash
14
+ python -m venv venv
15
+ source venv/bin/activate # or .\venv\Scripts\activate in Windows
16
+ pip install commitmessagegenerator
17
+ ```
18
+
19
+ ## ⚙️ Configuring
20
+
21
+ ```bash
22
+ commitgen -cf
23
+ ```
24
+
25
+ This opens an interactive configuration menu where you can:
26
+
27
+ 1. Set or update your Gemini API key
28
+ 2. Change the AI model
29
+ 3. Configure file staging behavior
30
+
31
+ Each option can be configured independently, and you can exit at any time without saving changes.
32
+
33
+ ## Run this and type you API key to the terminal so the package creates the .env file and automatically adds it to the .gitignore
34
+
35
+ Or do it manually:
36
+
37
+ ## IMPORTANT - BEFORE CREATING THIS FILE ADD '.venv' TO YOUR .gitignore SO YOUR API KEY ISN'T EXPOSED
38
+
39
+ Create a `.env` file in the directory where you will run commitgen (usually the root of your Git project):
40
+
41
+ ```
42
+ GEMINI_API_KEY=your-gemini-api-key
43
+ AI_MODEL=gemini-2.0-flash
44
+ AUTO_ADD_ALL=true
45
+ ```
46
+
47
+ ## 🚀 Usage
48
+
49
+ With the terminal, inside any Git repository with pending changes, run:
50
+
51
+ ```bash
52
+ commitgen (-c/-cp)
53
+ ```
54
+
55
+ The command will:
56
+
57
+ - Read the git diff;
58
+ - Send it to the Google Gemini API using your configured model;
59
+ - Return a commit message suggestion directly in your terminal.
60
+
61
+ ### Available Commands
62
+
63
+ - `commitgen` - Generate commit message only
64
+ - `commitgen -c` - Generate and commit with the message
65
+ - `commitgen -cp` - Generate, commit, and push
66
+ - `commitgen -cf` - Configure API key, model, and file staging behavior
67
+ - `commitgen -s` - Show current configuration status
68
+
69
+ ### Available Models
70
+
71
+ When configuring with `-cf`, you can choose from:
72
+
73
+ 1. **gemini-2.0-flash** (default) - Fast and efficient
74
+ 2. **gemini-1.5-flash** - Good balance of speed and quality
75
+ 3. **gemini-1.5-pro** - Highest quality, slower
76
+ 4. **gemini-2.0-flash-exp** - Experimental version
77
+ 5. **gemini-2.5-flash** - Latest version, fast and efficient
78
+ 6. **gemini-2.5-pro** - Latest version, highest quality
79
+
80
+ ### File Staging Behavior
81
+
82
+ When configuring with `-cf`, you can choose how files are staged:
83
+
84
+ 1. **Auto-add all files** (default) - Automatically runs `git add --all` before generating the commit message
85
+ 2. **Staged only** - Only reads the diff from files you've already staged with `git add`
86
+
87
+ The "staged only" option gives you more control over which changes are included in the commit message.
88
+
89
+ ## 🧩 Requisites
90
+
91
+ - Python 3.8 or higher
92
+ - Gemini API Key (Google Generative AI, free at: https://aistudio.google.com/app/apikey)
93
+ - Initialized Git repository
94
+ - Python dependencies (Automatically installed with the package):
95
+ - `GitPython`
96
+ - `google-generativeai`
97
+ - `python-dotenv`
98
+
99
+ ## 📄 License
100
+
101
+ ```
102
+ MIT License
103
+ ```
@@ -0,0 +1,168 @@
1
+ import argparse
2
+ import subprocess
3
+ from .generator import gerar_mensagem_commit
4
+ from .configure import api_key, get_configured_model, get_auto_add_setting, update_setting, get_api_key_status
5
+ import sys
6
+ import getpass
7
+
8
+ MODEL_MAP = {
9
+ "1": "gemini-2.0-flash",
10
+ "2": "gemini-1.5-flash",
11
+ "3": "gemini-1.5-pro",
12
+ "4": "gemini-2.0-flash-exp",
13
+ "5": "gemini-2.5-flash",
14
+ "6": "gemini-2.5-pro"
15
+ }
16
+
17
+ def configure_menu():
18
+ """Interactive configuration menu"""
19
+ while True:
20
+ # Get current settings
21
+ api_set = get_api_key_status()
22
+ current_model = get_configured_model()
23
+ auto_add = get_auto_add_setting()
24
+
25
+ print("\n" + "="*40)
26
+ print(" CONFIGURATION MENU")
27
+ print("="*40)
28
+ print(f"\n1. API Key [{('✓ Set' if api_set else '✗ Not set')}]")
29
+ print(f"2. Model [{current_model}]")
30
+ print(f"3. File staging [{('Auto-add all' if auto_add else 'Staged only')}]")
31
+ print("\n0. Exit")
32
+ print("="*40)
33
+
34
+ choice = input("\nSelect option (0-3): ").strip()
35
+
36
+ if choice == "0" or choice == "":
37
+ print("\nExiting configuration.\n")
38
+ break
39
+ elif choice == "1":
40
+ configure_api_key()
41
+ elif choice == "2":
42
+ configure_model()
43
+ elif choice == "3":
44
+ configure_staging()
45
+ else:
46
+ print("\nInvalid option. Please try again.")
47
+
48
+ def configure_api_key():
49
+ """Configure the API key"""
50
+ print("\n" + "-"*40)
51
+ print("API KEY CONFIGURATION")
52
+ print("-"*40)
53
+ print("Enter your Gemini API key below.")
54
+ print("Press Enter without typing to cancel.\n")
55
+
56
+ key = getpass.getpass("API Key: ")
57
+
58
+ if not key.strip():
59
+ print("\nNo changes made.")
60
+ return
61
+
62
+ update_setting("GEMINI_API_KEY", key)
63
+ print("\n✓ API Key saved successfully!")
64
+
65
+ def configure_model():
66
+ """Configure the AI model"""
67
+ current_model = get_configured_model()
68
+
69
+ print("\n" + "-"*40)
70
+ print("MODEL CONFIGURATION")
71
+ print("-"*40)
72
+ print(f"Current model: {current_model}\n")
73
+ print("Available models:")
74
+ print("1. gemini-2.0-flash (fast and efficient)")
75
+ print("2. gemini-1.5-flash (good balance)")
76
+ print("3. gemini-1.5-pro (highest quality, slower)")
77
+ print("4. gemini-2.0-flash-exp (experimental)")
78
+ print("5. gemini-2.5-flash (latest, fast)")
79
+ print("6. gemini-2.5-pro (latest, highest quality)")
80
+ print("\n0. Cancel")
81
+
82
+ choice = input("\nSelect model (0-6): ").strip()
83
+
84
+ if choice == "0" or choice == "":
85
+ print("\nNo changes made.")
86
+ return
87
+
88
+ if choice in MODEL_MAP:
89
+ selected_model = MODEL_MAP[choice]
90
+ update_setting("AI_MODEL", selected_model)
91
+ print(f"\n✓ Model changed to: {selected_model}")
92
+ else:
93
+ print("\nInvalid option. No changes made.")
94
+
95
+ def configure_staging():
96
+ """Configure file staging behavior"""
97
+ auto_add = get_auto_add_setting()
98
+
99
+ print("\n" + "-"*40)
100
+ print("FILE STAGING CONFIGURATION")
101
+ print("-"*40)
102
+ print(f"Current setting: {'Auto-add all files' if auto_add else 'Staged only'}\n")
103
+ print("1. Auto-add all files - Automatically stages all changes")
104
+ print("2. Staged only - Only use already staged files")
105
+ print("\n0. Cancel")
106
+
107
+ choice = input("\nSelect behavior (0-2): ").strip()
108
+
109
+ if choice == "0" or choice == "":
110
+ print("\nNo changes made.")
111
+ return
112
+
113
+ if choice == "1":
114
+ update_setting("AUTO_ADD_ALL", "true")
115
+ print("\n✓ Set to: Auto-add all files")
116
+ elif choice == "2":
117
+ update_setting("AUTO_ADD_ALL", "false")
118
+ print("\n✓ Set to: Staged only")
119
+ else:
120
+ print("\nInvalid option. No changes made.")
121
+
122
+ def main():
123
+ parser = argparse.ArgumentParser(description="Gerador de mensagens de commit com IA")
124
+ parser.add_argument("-c", "--commit", action="store_true", help="Commits with the generated message")
125
+ parser.add_argument("-cp", "--commitpush", action="store_true", help="Commits and pushes with the generated message")
126
+ parser.add_argument("-cf", "--configure", action="store_true", help="Configures the GEMINI_API_KEY environment variable")
127
+ parser.add_argument("-s", "--status", action="store_true", help="Shows current configuration status")
128
+ args = parser.parse_args()
129
+
130
+ if args.status:
131
+ from .configure import get_configured_model, get_auto_add_setting
132
+ import os
133
+ from dotenv import load_dotenv
134
+
135
+ load_dotenv()
136
+ key = os.getenv("GEMINI_API_KEY")
137
+ model = get_configured_model()
138
+ auto_add = get_auto_add_setting()
139
+
140
+ print("\nCurrent Configuration:")
141
+ print(f"API Key: {'✓ Set' if key else '✗ Not set'}")
142
+ print(f"Model: {model}")
143
+ print(f"Auto-add all files: {'✓ Yes' if auto_add else '✗ No (staged only)'}")
144
+ return
145
+
146
+ if not args.configure:
147
+ mensagem = gerar_mensagem_commit()
148
+
149
+ if "No changes detected" in mensagem:
150
+ print(mensagem)
151
+ return
152
+
153
+ print("\nGenerated commit message:\n" + mensagem)
154
+
155
+ if args.commit or args.commitpush:
156
+ print("\nCommitting changes...")
157
+ subprocess.run(["git", "commit", "-m", mensagem])
158
+
159
+ if args.commitpush:
160
+ print("\nPushing changes...")
161
+ subprocess.run(["git", "push"])
162
+
163
+ if args.configure:
164
+ configure_menu()
165
+
166
+ if len(sys.argv) == 1:
167
+ print("\nRemoving staged changes (git reset)...")
168
+ subprocess.run(["git", "reset"])
@@ -0,0 +1,103 @@
1
+ import os
2
+
3
+ def update_setting(setting_name, value):
4
+ """Update a single setting in the .env file"""
5
+ if os.path.exists(".env"):
6
+ with open(".env", "r") as f:
7
+ lines = f.readlines()
8
+
9
+ found = False
10
+ new_lines = []
11
+ for line in lines:
12
+ key_name = line.split("=")[0] if "=" in line else None
13
+ if key_name == setting_name:
14
+ new_lines.append(f"{setting_name}={value}\n")
15
+ found = True
16
+ else:
17
+ new_lines.append(line)
18
+
19
+ if not found:
20
+ new_lines.append(f"{setting_name}={value}\n")
21
+
22
+ with open(".env", "w") as f:
23
+ f.writelines(new_lines)
24
+ else:
25
+ with open(".env", "w") as f:
26
+ f.write(f"{setting_name}={value}\n")
27
+
28
+ _ensure_gitignore()
29
+
30
+ def _ensure_gitignore():
31
+ """Ensure .env is in .gitignore"""
32
+ if os.path.exists(".gitignore"):
33
+ with open(".gitignore", "r+") as outfile:
34
+ lines = outfile.readlines()
35
+ env_in_gitignore = next((line for line in lines if line.strip() == ".env"), None)
36
+ if not env_in_gitignore:
37
+ outfile.write("\n.env")
38
+
39
+ def api_key(key, model="gemini-2.0-flash", auto_add_all=True):
40
+ """Set all configuration at once (legacy function)"""
41
+ config = {
42
+ "GEMINI_API_KEY": key,
43
+ "AI_MODEL": model,
44
+ "AUTO_ADD_ALL": str(auto_add_all).lower()
45
+ }
46
+
47
+ if os.path.exists(".env"):
48
+ with open(".env", "r") as f:
49
+ lines = f.readlines()
50
+
51
+ existing_keys = set()
52
+ new_lines = []
53
+ for line in lines:
54
+ key_name = line.split("=")[0] if "=" in line else None
55
+ if key_name in config:
56
+ new_lines.append(f"{key_name}={config[key_name]}\n")
57
+ existing_keys.add(key_name)
58
+ else:
59
+ new_lines.append(line)
60
+
61
+ for key_name, value in config.items():
62
+ if key_name not in existing_keys:
63
+ new_lines.append(f"{key_name}={value}\n")
64
+
65
+ with open(".env", "w") as f:
66
+ f.writelines(new_lines)
67
+ else:
68
+ with open(".env", "w") as f:
69
+ for key_name, value in config.items():
70
+ f.write(f"{key_name}={value}\n")
71
+
72
+ _ensure_gitignore()
73
+
74
+ def get_api_key_status():
75
+ """Check if API key is set"""
76
+ if os.path.exists(".env"):
77
+ with open(".env", "r") as f:
78
+ lines = f.readlines()
79
+ api_line = next((line for line in lines if line.startswith("GEMINI_API_KEY=")), None)
80
+ if api_line:
81
+ value = api_line.split("=", 1)[1].strip()
82
+ return bool(value)
83
+ return False
84
+
85
+ def get_configured_model():
86
+ """Get the currently configured AI model from .env file"""
87
+ if os.path.exists(".env"):
88
+ with open(".env", "r") as outfile:
89
+ lines = outfile.readlines()
90
+ model_line = next((line for line in lines if line.startswith("AI_MODEL=")), None)
91
+ if model_line:
92
+ return model_line.split("=", 1)[1].strip()
93
+ return "gemini-2.0-flash" # Default fallback
94
+
95
+ def get_auto_add_setting():
96
+ """Get the auto-add all files setting from .env file"""
97
+ if os.path.exists(".env"):
98
+ with open(".env", "r") as outfile:
99
+ lines = outfile.readlines()
100
+ auto_add_line = next((line for line in lines if line.startswith("AUTO_ADD_ALL=")), None)
101
+ if auto_add_line:
102
+ return auto_add_line.split("=", 1)[1].strip().lower() == "true"
103
+ return True # Default: auto-add all files (current behavior)
@@ -2,6 +2,7 @@ import os
2
2
  from dotenv import load_dotenv
3
3
  from google import genai
4
4
  from git import Repo
5
+ from .configure import get_configured_model, get_auto_add_setting
5
6
 
6
7
  def gerar_mensagem_commit():
7
8
  load_dotenv()
@@ -9,16 +10,20 @@ def gerar_mensagem_commit():
9
10
  if not key:
10
11
  raise RuntimeError("The GEMINI_API_KEY environment variable is not set.")
11
12
 
12
- #genai.configure(api_key=key)
13
- #model = genai.GenerativeModel("gemini-2.0-flash")
13
+ # Get the configured model
14
+ model = get_configured_model()
14
15
 
15
16
  client = genai.Client(api_key=key)
16
17
 
17
18
 
18
19
  repo = Repo(os.getcwd())
19
20
 
20
- # Inclui arquivos staged (adicionados ou modificados)
21
- repo.git.add(all=True)
21
+ # Check if auto-add is enabled
22
+ auto_add = get_auto_add_setting()
23
+ if auto_add:
24
+ # Automatically stage all changes
25
+ repo.git.add(all=True)
26
+
22
27
  diff = repo.git.diff("--cached")
23
28
 
24
29
  if not diff.strip():
@@ -39,7 +44,7 @@ def gerar_mensagem_commit():
39
44
  )
40
45
 
41
46
  response = client.models.generate_content(
42
- model="gemini-2.0-flash",
47
+ model=model,
43
48
  contents=prompt
44
49
  )
45
- return response.text.strip()
50
+ return response.text.strip() if response.text else "Failed to generate commit message"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commitmessagegenerator
3
- Version: 1.5.0
3
+ Version: 2.2.0
4
4
  Summary: Generate commit messages with AI (Google Gemini) automatically using `git diff`.
5
5
  Author-email: Gabriel Terceiro <gcarolinoterceiro@gmail.com>
6
6
  License: MIT
@@ -35,6 +35,14 @@ pip install commitmessagegenerator
35
35
  commitgen -cf
36
36
  ```
37
37
 
38
+ This opens an interactive configuration menu where you can:
39
+
40
+ 1. Set or update your Gemini API key
41
+ 2. Change the AI model
42
+ 3. Configure file staging behavior
43
+
44
+ Each option can be configured independently, and you can exit at any time without saving changes.
45
+
38
46
  ## Run this and type you API key to the terminal so the package creates the .env file and automatically adds it to the .gitignore
39
47
 
40
48
  Or do it manually:
@@ -45,6 +53,8 @@ Create a `.env` file in the directory where you will run commitgen (usually the
45
53
 
46
54
  ```
47
55
  GEMINI_API_KEY=your-gemini-api-key
56
+ AI_MODEL=gemini-2.0-flash
57
+ AUTO_ADD_ALL=true
48
58
  ```
49
59
 
50
60
  ## 🚀 Usage
@@ -58,9 +68,37 @@ commitgen (-c/-cp)
58
68
  The command will:
59
69
 
60
70
  - Read the git diff;
61
- - Send it to the Google Gemini API;
71
+ - Send it to the Google Gemini API using your configured model;
62
72
  - Return a commit message suggestion directly in your terminal.
63
73
 
74
+ ### Available Commands
75
+
76
+ - `commitgen` - Generate commit message only
77
+ - `commitgen -c` - Generate and commit with the message
78
+ - `commitgen -cp` - Generate, commit, and push
79
+ - `commitgen -cf` - Configure API key, model, and file staging behavior
80
+ - `commitgen -s` - Show current configuration status
81
+
82
+ ### Available Models
83
+
84
+ When configuring with `-cf`, you can choose from:
85
+
86
+ 1. **gemini-2.0-flash** (default) - Fast and efficient
87
+ 2. **gemini-1.5-flash** - Good balance of speed and quality
88
+ 3. **gemini-1.5-pro** - Highest quality, slower
89
+ 4. **gemini-2.0-flash-exp** - Experimental version
90
+ 5. **gemini-2.5-flash** - Latest version, fast and efficient
91
+ 6. **gemini-2.5-pro** - Latest version, highest quality
92
+
93
+ ### File Staging Behavior
94
+
95
+ When configuring with `-cf`, you can choose how files are staged:
96
+
97
+ 1. **Auto-add all files** (default) - Automatically runs `git add --all` before generating the commit message
98
+ 2. **Staged only** - Only reads the diff from files you've already staged with `git add`
99
+
100
+ The "staged only" option gives you more control over which changes are included in the commit message.
101
+
64
102
  ## 🧩 Requisites
65
103
 
66
104
  - Python 3.8 or higher
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "commitmessagegenerator"
7
- version = "1.5.0"
7
+ version = "2.2.0"
8
8
  description = "Generate commit messages with AI (Google Gemini) automatically using `git diff`."
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -1,65 +0,0 @@
1
- # commitmessagegenerator
2
-
3
- Generate objective and technical commit messages with AI (Google Gemini) automatically using your `git diff`.
4
-
5
- ## 📦 Install
6
-
7
- ```bash
8
- pip install commitmessagegenerator
9
- ```
10
-
11
- Or, if you're using a `venv`:
12
-
13
- ```bash
14
- python -m venv venv
15
- source venv/bin/activate # or .\venv\Scripts\activate in Windows
16
- pip install commitmessagegenerator
17
- ```
18
-
19
- ## ⚙️ Configuring
20
-
21
- ```bash
22
- commitgen -cf
23
- ```
24
-
25
- ## Run this and type you API key to the terminal so the package creates the .env file and automatically adds it to the .gitignore
26
-
27
- Or do it manually:
28
-
29
- ## IMPORTANT - BEFORE CREATING THIS FILE ADD '.venv' TO YOUR .gitignore SO YOUR API KEY ISN'T EXPOSED
30
-
31
- Create a `.env` file in the directory where you will run commitgen (usually the root of your Git project):
32
-
33
- ```
34
- GEMINI_API_KEY=your-gemini-api-key
35
- ```
36
-
37
- ## 🚀 Usage
38
-
39
- With the terminal, inside any Git repository with pending changes, run:
40
-
41
- ```bash
42
- commitgen (-c/-cp)
43
- ```
44
-
45
- The command will:
46
-
47
- - Read the git diff;
48
- - Send it to the Google Gemini API;
49
- - Return a commit message suggestion directly in your terminal.
50
-
51
- ## 🧩 Requisites
52
-
53
- - Python 3.8 or higher
54
- - Gemini API Key (Google Generative AI, free at: https://aistudio.google.com/app/apikey)
55
- - Initialized Git repository
56
- - Python dependencies (Automatically installed with the package):
57
- - `GitPython`
58
- - `google-generativeai`
59
- - `python-dotenv`
60
-
61
- ## 📄 License
62
-
63
- ```
64
- MIT License
65
- ```
@@ -1,40 +0,0 @@
1
- import argparse
2
- import subprocess
3
- from .generator import gerar_mensagem_commit
4
- from .configure import api_key
5
- import sys
6
- import getpass
7
-
8
- def main():
9
- parser = argparse.ArgumentParser(description="Gerador de mensagens de commit com IA")
10
- parser.add_argument("-c", "--commit", action="store_true", help="Commits with the generated message")
11
- parser.add_argument("-cp", "--commitpush", action="store_true", help="Commits and pushes with the generated message")
12
- parser.add_argument("-cf", "--configure", action="store_true", help="Configures the GEMINI_API_KEY environment variable")
13
- args = parser.parse_args()
14
-
15
- if not args.configure:
16
- mensagem = gerar_mensagem_commit()
17
-
18
- if "No changes detected" in mensagem:
19
- print(mensagem)
20
- return
21
-
22
- print("\nGenerated commit message:\n" + mensagem)
23
-
24
- if args.commit or args.commitpush:
25
- print("\nCommitting changes...")
26
- subprocess.run(["git", "commit", "-m", mensagem])
27
-
28
- if args.commitpush:
29
- print("\nPushing changes...")
30
- subprocess.run(["git", "push"])
31
-
32
- if args.configure:
33
- print("\nPlease input your API KEY\nThis is directly set in the .env file")
34
- key = getpass.getpass()
35
- api_key(key)
36
- print("\nAPI KEY saved in .env file\n")
37
-
38
- if len(sys.argv) == 1:
39
- print("\nRemoving staged changes (git reset)...")
40
- subprocess.run(["git", "reset"])
@@ -1,22 +0,0 @@
1
- import os
2
- def api_key(key):
3
- if os.path.exists(".env"):
4
- with open(".env", "r+") as outfile:
5
- lines = outfile.readlines()
6
- gemini_api_key = next((line for line in lines if line.startswith("GEMINI_API_KEY=")), None)
7
- if gemini_api_key:
8
- outfile.seek(0)
9
- outfile.truncate()
10
- outfile.writelines([line if not line.startswith("GEMINI_API_KEY=") else f"GEMINI_API_KEY={key}\n" for line in lines])
11
- else:
12
- outfile.write(f"GEMINI_API_KEY={key}\n")
13
- else:
14
- with open(".env", "w") as outfile:
15
- outfile.write(f"GEMINI_API_KEY={key}\n")
16
-
17
- if os.path.exists(".gitignore"):
18
- with open(".gitignore", "r+") as outfile:
19
- lines = outfile.readlines()
20
- env_in_gitignore = next((line for line in lines if line.strip() == ".env"), None)
21
- if not env_in_gitignore:
22
- outfile.write("\n.env")