commitmessagegenerator 1.6.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,10 +1,124 @@
1
1
  import argparse
2
2
  import subprocess
3
3
  from .generator import gerar_mensagem_commit
4
- from .configure import api_key, get_configured_model
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")
@@ -14,17 +128,19 @@ def main():
14
128
  args = parser.parse_args()
15
129
 
16
130
  if args.status:
17
- from .configure import get_configured_model
131
+ from .configure import get_configured_model, get_auto_add_setting
18
132
  import os
19
133
  from dotenv import load_dotenv
20
134
 
21
135
  load_dotenv()
22
136
  key = os.getenv("GEMINI_API_KEY")
23
137
  model = get_configured_model()
138
+ auto_add = get_auto_add_setting()
24
139
 
25
140
  print("\nCurrent Configuration:")
26
141
  print(f"API Key: {'✓ Set' if key else '✗ Not set'}")
27
142
  print(f"Model: {model}")
143
+ print(f"Auto-add all files: {'✓ Yes' if auto_add else '✗ No (staged only)'}")
28
144
  return
29
145
 
30
146
  if not args.configure:
@@ -45,33 +161,7 @@ def main():
45
161
  subprocess.run(["git", "push"])
46
162
 
47
163
  if args.configure:
48
- print("\nPlease input your API KEY\nThis is directly set in the .env file")
49
- key = getpass.getpass()
50
-
51
- # Model selection
52
- print("\nAvailable models:")
53
- print("1. gemini-2.0-flash (default, fast and efficient)")
54
- print("2. gemini-1.5-flash (good balance of speed and quality)")
55
- print("3. gemini-1.5-pro (highest quality, slower)")
56
- print("4. gemini-2.0-flash-exp (experimental)")
57
- print("5. gemini-2.5-flash (latest, fast and efficient)")
58
- print("6. gemini-2.5-pro (latest, highest quality)")
59
-
60
- model_choice = input("\nSelect model (1-6) or press Enter for default (1): ").strip()
61
-
62
- model_map = {
63
- "1": "gemini-2.0-flash",
64
- "2": "gemini-1.5-flash",
65
- "3": "gemini-1.5-pro",
66
- "4": "gemini-2.0-flash-exp",
67
- "5": "gemini-2.5-flash",
68
- "6": "gemini-2.5-pro"
69
- }
70
-
71
- selected_model = model_map.get(model_choice, "gemini-2.0-flash")
72
-
73
- api_key(key, selected_model)
74
- print(f"\nAPI KEY and model ({selected_model}) saved in .env file\n")
164
+ configure_menu()
75
165
 
76
166
  if len(sys.argv) == 1:
77
167
  print("\nRemoving staged changes (git reset)...")
@@ -1,34 +1,34 @@
1
1
  import os
2
2
 
3
- def api_key(key, model="gemini-2.0-flash"):
3
+ def update_setting(setting_name, value):
4
+ """Update a single setting in the .env file"""
4
5
  if os.path.exists(".env"):
5
- with open(".env", "r+") as outfile:
6
- lines = outfile.readlines()
7
- gemini_api_key = next((line for line in lines if line.startswith("GEMINI_API_KEY=")), None)
8
- model_line = next((line for line in lines if line.startswith("AI_MODEL=")), None)
9
-
10
- outfile.seek(0)
11
- outfile.truncate()
12
-
13
- # Update or add GEMINI_API_KEY
14
- if gemini_api_key:
15
- outfile.writelines([line if not line.startswith("GEMINI_API_KEY=") else f"GEMINI_API_KEY={key}\n" for line in lines])
16
- else:
17
- outfile.writelines(lines)
18
- outfile.write(f"GEMINI_API_KEY={key}\n")
19
-
20
- # Update or add AI_MODEL
21
- if model_line:
22
- outfile.seek(0)
23
- outfile.truncate()
24
- outfile.writelines([line if not line.startswith("AI_MODEL=") else f"AI_MODEL={model}\n" for line in outfile.readlines()])
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
25
16
  else:
26
- outfile.write(f"AI_MODEL={model}\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)
27
24
  else:
28
- with open(".env", "w") as outfile:
29
- outfile.write(f"GEMINI_API_KEY={key}\n")
30
- outfile.write(f"AI_MODEL={model}\n")
25
+ with open(".env", "w") as f:
26
+ f.write(f"{setting_name}={value}\n")
27
+
28
+ _ensure_gitignore()
31
29
 
30
+ def _ensure_gitignore():
31
+ """Ensure .env is in .gitignore"""
32
32
  if os.path.exists(".gitignore"):
33
33
  with open(".gitignore", "r+") as outfile:
34
34
  lines = outfile.readlines()
@@ -36,6 +36,52 @@ def api_key(key, model="gemini-2.0-flash"):
36
36
  if not env_in_gitignore:
37
37
  outfile.write("\n.env")
38
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
+
39
85
  def get_configured_model():
40
86
  """Get the currently configured AI model from .env file"""
41
87
  if os.path.exists(".env"):
@@ -45,3 +91,13 @@ def get_configured_model():
45
91
  if model_line:
46
92
  return model_line.split("=", 1)[1].strip()
47
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,7 +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
5
+ from .configure import get_configured_model, get_auto_add_setting
6
6
 
7
7
  def gerar_mensagem_commit():
8
8
  load_dotenv()
@@ -18,8 +18,12 @@ def gerar_mensagem_commit():
18
18
 
19
19
  repo = Repo(os.getcwd())
20
20
 
21
- # Inclui arquivos staged (adicionados ou modificados)
22
- 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
+
23
27
  diff = repo.git.diff("--cached")
24
28
 
25
29
  if not diff.strip():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commitmessagegenerator
3
- Version: 1.6.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,10 +35,13 @@ pip install commitmessagegenerator
35
35
  commitgen -cf
36
36
  ```
37
37
 
38
- This will prompt you for:
38
+ This opens an interactive configuration menu where you can:
39
39
 
40
- 1. Your Gemini API key
41
- 2. Your preferred AI model (with options to choose from)
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.
42
45
 
43
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
44
47
 
@@ -51,6 +54,7 @@ Create a `.env` file in the directory where you will run commitgen (usually the
51
54
  ```
52
55
  GEMINI_API_KEY=your-gemini-api-key
53
56
  AI_MODEL=gemini-2.0-flash
57
+ AUTO_ADD_ALL=true
54
58
  ```
55
59
 
56
60
  ## 🚀 Usage
@@ -72,7 +76,7 @@ The command will:
72
76
  - `commitgen` - Generate commit message only
73
77
  - `commitgen -c` - Generate and commit with the message
74
78
  - `commitgen -cp` - Generate, commit, and push
75
- - `commitgen -cf` - Configure API key and model
79
+ - `commitgen -cf` - Configure API key, model, and file staging behavior
76
80
  - `commitgen -s` - Show current configuration status
77
81
 
78
82
  ### Available Models
@@ -86,6 +90,15 @@ When configuring with `-cf`, you can choose from:
86
90
  5. **gemini-2.5-flash** - Latest version, fast and efficient
87
91
  6. **gemini-2.5-pro** - Latest version, highest quality
88
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
+
89
102
  ## 🧩 Requisites
90
103
 
91
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=7QjfbOv2DWzlQP7eCkFzsX0EI1hc9rKWuGIMjdPv6jM,3006
3
- commitmessagegenerator/configure.py,sha256=chWBYqPtf4pIdRM9X5VPfjhdhRXVPqrHthdKVFaEBcQ,2068
4
- commitmessagegenerator/generator.py,sha256=Lrw78EC_s6lfwrrSxJaeK8BJKi2gUgjob7Ms9X70V9g,1519
5
- commitmessagegenerator-1.6.0.dist-info/licenses/LICENSE,sha256=q7KJbcPCqUAvkBuI1QNc8Kg9XPfBfnNkLN9WKwudO8U,11
6
- commitmessagegenerator-1.6.0.dist-info/METADATA,sha256=99_RVdKcu_8ewRYSmFgmNBZ3dho2NQTCKbHmTX4mdso,2775
7
- commitmessagegenerator-1.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- commitmessagegenerator-1.6.0.dist-info/entry_points.txt,sha256=VmVQY00e0SuHsTFZmOCcyN0VYCQlVnZrdZNJdUGLCVo,62
9
- commitmessagegenerator-1.6.0.dist-info/top_level.txt,sha256=G8wUZw8MTtvYs1WgehFVTPKqw5Td7gGedZZIQbZH1Co,23
10
- commitmessagegenerator-1.6.0.dist-info/RECORD,,