commitmessagegenerator 1.6.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 (17) hide show
  1. {commitmessagegenerator-1.6.0 → commitmessagegenerator-2.2.0}/PKG-INFO +18 -5
  2. {commitmessagegenerator-1.6.0 → commitmessagegenerator-2.2.0}/README.md +17 -4
  3. commitmessagegenerator-2.2.0/commitmessagegenerator/cli.py +168 -0
  4. commitmessagegenerator-2.2.0/commitmessagegenerator/configure.py +103 -0
  5. {commitmessagegenerator-1.6.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator/generator.py +7 -3
  6. {commitmessagegenerator-1.6.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator.egg-info/PKG-INFO +18 -5
  7. {commitmessagegenerator-1.6.0 → commitmessagegenerator-2.2.0}/pyproject.toml +1 -1
  8. commitmessagegenerator-1.6.0/commitmessagegenerator/cli.py +0 -78
  9. commitmessagegenerator-1.6.0/commitmessagegenerator/configure.py +0 -47
  10. {commitmessagegenerator-1.6.0 → commitmessagegenerator-2.2.0}/LICENSE +0 -0
  11. {commitmessagegenerator-1.6.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator/__init__.py +0 -0
  12. {commitmessagegenerator-1.6.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator.egg-info/SOURCES.txt +0 -0
  13. {commitmessagegenerator-1.6.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator.egg-info/dependency_links.txt +0 -0
  14. {commitmessagegenerator-1.6.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator.egg-info/entry_points.txt +0 -0
  15. {commitmessagegenerator-1.6.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator.egg-info/requires.txt +0 -0
  16. {commitmessagegenerator-1.6.0 → commitmessagegenerator-2.2.0}/commitmessagegenerator.egg-info/top_level.txt +0 -0
  17. {commitmessagegenerator-1.6.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.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
@@ -22,10 +22,13 @@ pip install commitmessagegenerator
22
22
  commitgen -cf
23
23
  ```
24
24
 
25
- This will prompt you for:
25
+ This opens an interactive configuration menu where you can:
26
26
 
27
- 1. Your Gemini API key
28
- 2. Your preferred AI model (with options to choose from)
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.
29
32
 
30
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
31
34
 
@@ -38,6 +41,7 @@ Create a `.env` file in the directory where you will run commitgen (usually the
38
41
  ```
39
42
  GEMINI_API_KEY=your-gemini-api-key
40
43
  AI_MODEL=gemini-2.0-flash
44
+ AUTO_ADD_ALL=true
41
45
  ```
42
46
 
43
47
  ## 🚀 Usage
@@ -59,7 +63,7 @@ The command will:
59
63
  - `commitgen` - Generate commit message only
60
64
  - `commitgen -c` - Generate and commit with the message
61
65
  - `commitgen -cp` - Generate, commit, and push
62
- - `commitgen -cf` - Configure API key and model
66
+ - `commitgen -cf` - Configure API key, model, and file staging behavior
63
67
  - `commitgen -s` - Show current configuration status
64
68
 
65
69
  ### Available Models
@@ -73,6 +77,15 @@ When configuring with `-cf`, you can choose from:
73
77
  5. **gemini-2.5-flash** - Latest version, fast and efficient
74
78
  6. **gemini-2.5-pro** - Latest version, highest quality
75
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
+
76
89
  ## 🧩 Requisites
77
90
 
78
91
  - Python 3.8 or higher
@@ -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,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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "commitmessagegenerator"
7
- version = "1.6.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,78 +0,0 @@
1
- import argparse
2
- import subprocess
3
- from .generator import gerar_mensagem_commit
4
- from .configure import api_key, get_configured_model
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
- parser.add_argument("-s", "--status", action="store_true", help="Shows current configuration status")
14
- args = parser.parse_args()
15
-
16
- if args.status:
17
- from .configure import get_configured_model
18
- import os
19
- from dotenv import load_dotenv
20
-
21
- load_dotenv()
22
- key = os.getenv("GEMINI_API_KEY")
23
- model = get_configured_model()
24
-
25
- print("\nCurrent Configuration:")
26
- print(f"API Key: {'✓ Set' if key else '✗ Not set'}")
27
- print(f"Model: {model}")
28
- return
29
-
30
- if not args.configure:
31
- mensagem = gerar_mensagem_commit()
32
-
33
- if "No changes detected" in mensagem:
34
- print(mensagem)
35
- return
36
-
37
- print("\nGenerated commit message:\n" + mensagem)
38
-
39
- if args.commit or args.commitpush:
40
- print("\nCommitting changes...")
41
- subprocess.run(["git", "commit", "-m", mensagem])
42
-
43
- if args.commitpush:
44
- print("\nPushing changes...")
45
- subprocess.run(["git", "push"])
46
-
47
- 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")
75
-
76
- if len(sys.argv) == 1:
77
- print("\nRemoving staged changes (git reset)...")
78
- subprocess.run(["git", "reset"])
@@ -1,47 +0,0 @@
1
- import os
2
-
3
- def api_key(key, model="gemini-2.0-flash"):
4
- 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()])
25
- else:
26
- outfile.write(f"AI_MODEL={model}\n")
27
- 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")
31
-
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 get_configured_model():
40
- """Get the currently configured AI model from .env file"""
41
- if os.path.exists(".env"):
42
- with open(".env", "r") as outfile:
43
- lines = outfile.readlines()
44
- model_line = next((line for line in lines if line.startswith("AI_MODEL=")), None)
45
- if model_line:
46
- return model_line.split("=", 1)[1].strip()
47
- return "gemini-2.0-flash" # Default fallback