commitmessagegenerator 1.5.0__py3-none-any.whl → 2.2.0__py3-none-any.whl

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,17 +1,148 @@
1
1
  import argparse
2
2
  import subprocess
3
3
  from .generator import gerar_mensagem_commit
4
- from .configure import api_key
4
+ from .configure import api_key, get_configured_model, get_auto_add_setting, update_setting, get_api_key_status
5
5
  import sys
6
6
  import getpass
7
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
+
8
122
  def main():
9
123
  parser = argparse.ArgumentParser(description="Gerador de mensagens de commit com IA")
10
124
  parser.add_argument("-c", "--commit", action="store_true", help="Commits with the generated message")
11
125
  parser.add_argument("-cp", "--commitpush", action="store_true", help="Commits and pushes with the generated message")
12
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")
13
128
  args = parser.parse_args()
14
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
+
15
146
  if not args.configure:
16
147
  mensagem = gerar_mensagem_commit()
17
148
 
@@ -30,10 +161,7 @@ def main():
30
161
  subprocess.run(["git", "push"])
31
162
 
32
163
  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")
164
+ configure_menu()
37
165
 
38
166
  if len(sys.argv) == 1:
39
167
  print("\nRemoving staged changes (git reset)...")
@@ -1,22 +1,103 @@
1
1
  import os
2
- def api_key(key):
2
+
3
+ def update_setting(setting_name, value):
4
+ """Update a single setting in the .env file"""
3
5
  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])
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
11
16
  else:
12
- outfile.write(f"GEMINI_API_KEY={key}\n")
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)
13
24
  else:
14
- with open(".env", "w") as outfile:
15
- outfile.write(f"GEMINI_API_KEY={key}\n")
25
+ with open(".env", "w") as f:
26
+ f.write(f"{setting_name}={value}\n")
27
+
28
+ _ensure_gitignore()
16
29
 
30
+ def _ensure_gitignore():
31
+ """Ensure .env is in .gitignore"""
17
32
  if os.path.exists(".gitignore"):
18
33
  with open(".gitignore", "r+") as outfile:
19
34
  lines = outfile.readlines()
20
35
  env_in_gitignore = next((line for line in lines if line.strip() == ".env"), None)
21
36
  if not env_in_gitignore:
22
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
@@ -0,0 +1,10 @@
1
+ commitmessagegenerator/__init__.py,sha256=Wsl1vaSI5fWuK3B9MfZnPp1PxnRfTmnvW_20vgswgT0,45
2
+ commitmessagegenerator/cli.py,sha256=IoSYuH8-Zc5YNdS6pmSg0nwo-UNufNPZb78Z76llSTk,5775
3
+ commitmessagegenerator/configure.py,sha256=5OtQ9Y2udsIGeSztnsiFqSrcKWcm4pGKS6uyZS9-YvU,3749
4
+ commitmessagegenerator/generator.py,sha256=c0IUPxP8A10OMokWwKYoes5gDi_-BJ0COl0Vm2ZM6ew,1624
5
+ commitmessagegenerator-2.2.0.dist-info/licenses/LICENSE,sha256=q7KJbcPCqUAvkBuI1QNc8Kg9XPfBfnNkLN9WKwudO8U,11
6
+ commitmessagegenerator-2.2.0.dist-info/METADATA,sha256=MBfGnghBea_1vjbxqyRD2cPISPZb7pzJ2heW2AYJv9w,3376
7
+ commitmessagegenerator-2.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ commitmessagegenerator-2.2.0.dist-info/entry_points.txt,sha256=VmVQY00e0SuHsTFZmOCcyN0VYCQlVnZrdZNJdUGLCVo,62
9
+ commitmessagegenerator-2.2.0.dist-info/top_level.txt,sha256=G8wUZw8MTtvYs1WgehFVTPKqw5Td7gGedZZIQbZH1Co,23
10
+ commitmessagegenerator-2.2.0.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- commitmessagegenerator/__init__.py,sha256=Wsl1vaSI5fWuK3B9MfZnPp1PxnRfTmnvW_20vgswgT0,45
2
- commitmessagegenerator/cli.py,sha256=lpYpRpjcKY6dQ2uhm6Rwpos_lEy9RELhuvE6aSI2jxI,1475
3
- commitmessagegenerator/configure.py,sha256=gzG9cp4B4qIXsoGVTSq-D80N6cmf_A77W73s0k-JkyQ,981
4
- commitmessagegenerator/generator.py,sha256=4BJHi7Perllkxnqf00KWPTQTPh1oZZABX3DXHrApF1Y,1453
5
- commitmessagegenerator-1.5.0.dist-info/licenses/LICENSE,sha256=q7KJbcPCqUAvkBuI1QNc8Kg9XPfBfnNkLN9WKwudO8U,11
6
- commitmessagegenerator-1.5.0.dist-info/METADATA,sha256=TTMjszdGCBBNgRtdGYH5zYT2MEje1PgkieiEAiX5yaE,1909
7
- commitmessagegenerator-1.5.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- commitmessagegenerator-1.5.0.dist-info/entry_points.txt,sha256=VmVQY00e0SuHsTFZmOCcyN0VYCQlVnZrdZNJdUGLCVo,62
9
- commitmessagegenerator-1.5.0.dist-info/top_level.txt,sha256=G8wUZw8MTtvYs1WgehFVTPKqw5Td7gGedZZIQbZH1Co,23
10
- commitmessagegenerator-1.5.0.dist-info/RECORD,,