git-copilot-commit 0.1.19__tar.gz → 0.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. git_copilot_commit-0.2.0/.justfile +56 -0
  2. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/PKG-INFO +1 -1
  3. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/src/git_copilot_commit/cli.py +107 -35
  4. git_copilot_commit-0.2.0/src/git_copilot_commit/prompts/commit-message-generator-prompt.md +62 -0
  5. git_copilot_commit-0.1.19/src/git_copilot_commit/prompts/commit-message-generator-prompt.md +0 -70
  6. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/.github/workflows/ci.yml +0 -0
  7. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/.gitignore +0 -0
  8. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/.python-version +0 -0
  9. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/LICENSE +0 -0
  10. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/README.md +0 -0
  11. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/pyproject.toml +0 -0
  12. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/src/git_copilot_commit/__init__.py +0 -0
  13. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/src/git_copilot_commit/git.py +0 -0
  14. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/src/git_copilot_commit/py.typed +0 -0
  15. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/src/git_copilot_commit/settings.py +0 -0
  16. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/src/git_copilot_commit/version.py +0 -0
  17. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/uv.lock +0 -0
  18. {git_copilot_commit-0.1.19 → git_copilot_commit-0.2.0}/vhs/demo.vhs +0 -0
@@ -0,0 +1,56 @@
1
+ # List available commands
2
+ [private]
3
+ default:
4
+ @just --list
5
+
6
+ # Pass all arguments directly to git-copilot-commit
7
+ commit *args:
8
+ uv run git-copilot-commit commit {{args}}
9
+
10
+
11
+ # Bump version based on GitHub tags and create empty commit
12
+ bump type="patch":
13
+ #!/usr/bin/env bash
14
+ set -euo pipefail
15
+
16
+ # Get the latest tag from GitHub
17
+ echo "Fetching latest tag from GitHub..."
18
+ latest_tag=$(gh release list --limit 1 --json tagName --jq '.[0].tagName // "v0.0.0"')
19
+
20
+ # Remove 'v' prefix if present
21
+ version=${latest_tag#v}
22
+
23
+ # Parse version components
24
+ IFS='.' read -r major minor patch <<< "$version"
25
+
26
+ # Bump based on type
27
+ case "{{type}}" in
28
+ major)
29
+ major=$((major + 1))
30
+ minor=0
31
+ patch=0
32
+ ;;
33
+ minor)
34
+ minor=$((minor + 1))
35
+ patch=0
36
+ ;;
37
+ patch)
38
+ patch=$((patch + 1))
39
+ ;;
40
+ *)
41
+ echo "Error: Invalid bump type '{{type}}'. Use: major, minor, or patch"
42
+ exit 1
43
+ ;;
44
+ esac
45
+
46
+ # Create new version
47
+ new_version="v${major}.${minor}.${patch}"
48
+
49
+ echo "Current version: $latest_tag"
50
+ echo "New version: $new_version"
51
+
52
+ # Create empty commit
53
+ git commit --allow-empty -m "Bump version to $new_version"
54
+
55
+ echo "✓ Created empty commit for $new_version"
56
+ echo " Next: Create and push tag with: git tag $new_version && git push && git push --tags"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: git-copilot-commit
3
- Version: 0.1.19
3
+ Version: 0.2.0
4
4
  Summary: Automatically generate and commit changes using copilot
5
5
  Author-email: Dheepak Krishnamurthy <1813121+kdheepak@users.noreply.github.com>
6
6
  License-File: LICENSE
@@ -3,6 +3,7 @@ git-copilot-commit - AI-powered Git commit assistant
3
3
  """
4
4
 
5
5
  import rich.terminal_theme
6
+ import sys
6
7
  import typer
7
8
  from rich.console import Console
8
9
  from rich.prompt import Confirm
@@ -13,7 +14,7 @@ from pathlib import Path
13
14
 
14
15
  from pycopilot.copilot import Copilot, CopilotAPIError # type: ignore
15
16
  from pycopilot.auth import Authentication
16
- from .git import GitRepository, GitError, NotAGitRepositoryError, GitStatus
17
+ from .git import GitRepository, GitError, NotAGitRepositoryError
17
18
  from .settings import Settings
18
19
  from .version import __version__
19
20
 
@@ -23,7 +24,7 @@ app = typer.Typer(help=__doc__, add_completion=False)
23
24
 
24
25
  def version_callback(value: bool):
25
26
  if value:
26
- rich.print(f"git-copilot-commit [bold green]{__version__}[/]")
27
+ rich.print(f"git-copilot-commit [bold yellow]{__version__}[/]")
27
28
  raise typer.Exit()
28
29
 
29
30
 
@@ -39,12 +40,14 @@ def main(
39
40
  """
40
41
  if ctx.invoked_subcommand is None:
41
42
  # Show help when no command is provided
42
- print(ctx.get_help())
43
+ console.print(ctx.get_help())
43
44
  raise typer.Exit()
44
45
  else:
45
- console.print(
46
- f"[bold]{(__package__ or 'git_copilot_commit').replace('_', '-')}[/] - [bold blue]v{__version__}[/]\n"
47
- )
46
+ # Don't show version for print command to avoid interfering with pipes
47
+ if ctx.invoked_subcommand != "echo":
48
+ console.print(
49
+ f"[bold]{(__package__ or 'git_copilot_commit').replace('_', '-')}[/] - [bold green]v{__version__}[/]\n"
50
+ )
48
51
 
49
52
 
50
53
  def get_prompt_locations():
@@ -85,40 +88,53 @@ def load_system_prompt() -> str:
85
88
 
86
89
 
87
90
  def generate_commit_message(
88
- repo: GitRepository, status: GitStatus, model: str | None = None
91
+ repo: GitRepository, model: str | None = None, context: str = ""
89
92
  ) -> str:
90
93
  """Generate a conventional commit message using Copilot API."""
91
94
 
95
+ # Refresh status after staging
96
+ status = repo.get_status()
97
+
98
+ if not status.has_staged_changes:
99
+ console.print("[red]No staged changes to commit.[/red]")
100
+ raise typer.Exit()
101
+
92
102
  system_prompt = load_system_prompt()
93
103
  client = Copilot(system_prompt=system_prompt)
94
104
 
95
- prompt = f"""
96
- `git status`:
97
-
98
- ```
99
- {status.get_porcelain_output()}
100
- ```
105
+ prompt_parts = [
106
+ "`git status`:\n",
107
+ f"```\n{status.get_porcelain_output()}\n```",
108
+ "\n\n`git diff --staged`:\n",
109
+ f"```\n{status.staged_diff}\n```",
110
+ ]
101
111
 
102
- `git diff --staged`:
112
+ if context.strip():
113
+ prompt_parts.insert(0, f"User-provided context:\n\n{context.strip()}\n\n")
103
114
 
104
- ```
105
- {status.staged_diff}
106
- ```
115
+ prompt_parts.append("\nGenerate a conventional commit message:")
107
116
 
108
- Generate a conventional commit message:"""
117
+ prompt = "\n".join(prompt_parts)
109
118
 
110
119
  try:
111
120
  response = client.ask(prompt, model=model) if model else client.ask(prompt)
112
121
  return response.content
113
122
  except CopilotAPIError:
114
- # Fallback to git status only when diff is too large
115
- fallback_prompt = f"""`git status`:
116
-
117
- ```
118
- {status.get_porcelain_output()}
119
- ```
123
+ fallback_prompt_parts = [
124
+ "`git status`:\n",
125
+ f"```\n{status.get_porcelain_output()}\n```",
126
+ ]
127
+
128
+ if context.strip():
129
+ fallback_prompt_parts.insert(
130
+ 0, f"User-provided context:\n\n{context.strip()}\n\n"
131
+ )
132
+
133
+ fallback_prompt_parts.append(
134
+ "\nGenerate a conventional commit message based on the git status above:"
135
+ )
120
136
 
121
- Generate a conventional commit message based on the git status above:"""
137
+ fallback_prompt = "\n".join(fallback_prompt_parts)
122
138
 
123
139
  response = (
124
140
  client.ask(fallback_prompt, model=model)
@@ -139,6 +155,12 @@ def commit(
139
155
  yes: bool = typer.Option(
140
156
  False, "--yes", "-y", help="Automatically accept the generated commit message"
141
157
  ),
158
+ context: str = typer.Option(
159
+ "",
160
+ "--context",
161
+ "-c",
162
+ help="Optional user-provided context to guide commit message",
163
+ ),
142
164
  ):
143
165
  """
144
166
  Generate commit message based on changes in the current git repository and commit them.
@@ -186,25 +208,29 @@ def commit(
186
208
  repo.stage_files()
187
209
  console.print("[green]Staged untracked files.[/green]")
188
210
 
189
- # Refresh status after staging
190
- status = repo.get_status()
191
-
192
- if not status.has_staged_changes:
193
- console.print("[yellow]No staged changes to commit.[/yellow]")
194
- raise typer.Exit()
211
+ if context:
212
+ console.print(
213
+ Panel(context.strip(), title="User Context", border_style="magenta")
214
+ )
195
215
 
196
216
  # Generate or use provided commit message
197
217
  with console.status(
198
- "[cyan]Generating commit message based on [bold]`git diff --staged`[/bold] ...[/cyan]"
218
+ "[yellow]Generating commit message based on [bold]`git diff --staged`[/] ...[/yellow]"
199
219
  ):
200
- commit_message = generate_commit_message(repo, status, model)
220
+ commit_message = generate_commit_message(repo, model, context=context)
201
221
 
202
222
  console.print(
203
- "[cyan]Generated commit message based on [bold]`git diff --staged`[/bold] ...[/cyan]"
223
+ "[yellow]Generated commit message based on [bold]`git diff --staged`[/] ...[/yellow]"
204
224
  )
205
225
 
206
226
  # Display commit message
207
- console.print(Panel(commit_message, title="Commit Message", border_style="green"))
227
+ console.print(
228
+ Panel(
229
+ f"[bold]{commit_message}[/]",
230
+ title="Commit Message",
231
+ border_style="cyan",
232
+ )
233
+ )
208
234
 
209
235
  # Confirm commit or edit message (skip if --yes flag is used)
210
236
  if yes:
@@ -319,5 +345,51 @@ def config(
319
345
  console.print(f"Config file: [dim]{settings.config_file}[/dim]")
320
346
 
321
347
 
348
+ @app.command()
349
+ def echo(
350
+ model: str | None = typer.Option(
351
+ None, "--model", "-m", help="Model to use for generating commit message"
352
+ ),
353
+ ):
354
+ """
355
+ Generate commit message from stdin input (useful for pipes).
356
+ """
357
+ # Read from stdin
358
+ input_text = sys.stdin.read()
359
+
360
+ if not input_text.strip():
361
+ console.print("[red]Error: No input provided via stdin[/red]")
362
+ raise typer.Exit(1)
363
+
364
+ # Load settings and use default model if none provided
365
+ settings = Settings()
366
+ if model is None:
367
+ model = settings.default_model
368
+
369
+ # Load system prompt and create client
370
+ system_prompt = load_system_prompt()
371
+ client = Copilot(system_prompt=system_prompt)
372
+
373
+ # Generate commit message from the input
374
+ prompt = f"""
375
+ `git diff --staged`:
376
+
377
+ ```
378
+ {input_text.strip()}
379
+ ```
380
+
381
+ Generate a conventional commit message based on the input above:"""
382
+
383
+ try:
384
+ response = client.ask(prompt, model=model) if model else client.ask(prompt)
385
+ # Print the commit message directly to stdout (no rich formatting for pipes)
386
+ import builtins
387
+
388
+ builtins.print(response.content)
389
+ except CopilotAPIError as e:
390
+ console.print(f"[red]Error generating commit message: {e}[/red]")
391
+ raise typer.Exit(1)
392
+
393
+
322
394
  if __name__ == "__main__":
323
395
  app()
@@ -0,0 +1,62 @@
1
+ # Commit Message Generator System Prompt
2
+
3
+ You are a Git commit message assistant trained to write a single clear, structured, and informative commit message following the Conventional Commits specification. You will receive:
4
+
5
+ 1. A `git diff --staged` output (or a summary of changed files)
6
+ 2. Optionally, additional **user-provided context**
7
+
8
+ Your task is to generate a **single-line commit message** in the [Conventional Commits](https://www.conventionalcommits.org/) format based on both inputs. If no context is provided, rely **only** on the diff.
9
+
10
+ ## ✅ Output Format
11
+
12
+ ```
13
+ <type>(<optional scope>): <description>
14
+ ```
15
+
16
+ - Do not include a body or footer.
17
+ - Do not wrap the message in backticks or code blocks.
18
+ - Keep the title line ≤72 characters.
19
+
20
+ ## ✅ Valid Types
21
+
22
+ - `feat`: New feature
23
+ - `fix`: Bug fix
24
+ - `docs`: Documentation changes
25
+ - `style`: Code formatting (no logic changes)
26
+ - `refactor`: Code restructuring (no behavior changes)
27
+ - `perf`: Performance improvements
28
+ - `test`: Adding or updating tests
29
+ - `chore`: Maintenance tasks (e.g., CI/CD, dependencies)
30
+ - `revert`: Revert of a previous commit
31
+
32
+ ## ✅ Scope (Optional)
33
+
34
+ - Lowercase, single word or hyphenated phrase
35
+ - Represents the affected area, module, or file
36
+ - Use broad area if multiple related files are affected
37
+
38
+ ## ✅ Subject Line
39
+
40
+ - Use imperative mood ("remove" not "removed")
41
+ - Focus on **what** changed, not why or how
42
+ - Be concise and specific
43
+ - Use abbreviations (e.g., "config" not "configuration")
44
+
45
+ ## ✅ Using User-Provided Context
46
+
47
+ - If additional context is provided by the user, you may **incorporate it** to clarify purpose (e.g., "remove duplicate entry").
48
+ - If no such context is provided, **do not speculate or infer**.
49
+ - Only use terms like "unused", "duplicate", or "deprecated" when explicitly stated by the user or clearly shown in the diff.
50
+
51
+ ## ❌ Do Not
52
+
53
+ - Do not use vague phrases ("made changes", "updated code")
54
+ - Do not use past tense ("added", "removed")
55
+ - Do not explain implementation or reasoning ("to fix bug", "because of issue")
56
+ - Do not guess purpose based on intuition or incomplete file context
57
+
58
+ ---
59
+
60
+ Given a Git diff, a list of modified files, or a short description of changes, generate a single, short, clear and structured Conventional Commit message following the above rules. If multiple changes are detected, prioritize the most important changes in a single commit message. Do not add any body or footer. You can only give one reply for each conversation.
61
+
62
+ Do not wrap the response in triple backticks or single backticks. Return the commit message as the output without any additional text, explanations, or formatting markers.
@@ -1,70 +0,0 @@
1
- # Commit Message Generator System Prompt
2
-
3
- You are a Git commit message assistant trained to write a single clear, structured, and informative commit message following the Conventional Commits specification based on the provided `git diff --staged` output.
4
-
5
- Output format: Provide only the commit message without any additional text, explanations, or formatting markers.
6
-
7
- The guidelines for the commit messages are as follows:
8
-
9
- ## 1. Format
10
-
11
- ```
12
- <type>[optional scope]: <description>
13
- ```
14
-
15
- - The first line (title) should be at most 72 characters long.
16
- - If the natural description exceeds 72 characters, prioritize the most important aspect.
17
- - Use abbreviations when appropriate: `config` not `configuration`.
18
- - The body (if present) should be wrapped at 100 characters per line.
19
-
20
- ## 2. Valid Commit Types:
21
-
22
- - `feat`: A new feature
23
- - `fix`: A bug fix
24
- - `docs`: Documentation changes
25
- - `style`: Code formatting (no logic changes)
26
- - `refactor`: Code restructuring (no behavior changes)
27
- - `perf`: Performance improvements
28
- - `test`: Adding or updating tests
29
- - `chore`: Maintenance tasks (e.g., tooling, CI/CD, dependencies)
30
- - `revert`: Reverting previous changes
31
-
32
- ## 3. Scope (Optional but encouraged):
33
-
34
- - Enclose in parentheses
35
- - Use the affected module, component, or area
36
- - For multiple files in same area, use the broader scope
37
- - For single files, you may use filename
38
- - Scope should be a single word or hyphenated phrase describing the affected module
39
-
40
- ## 4. Description:
41
-
42
- - Use imperative mood (e.g., "add feature" instead of "added" or "adds").
43
- - Be concise yet informative.
44
- - Focus on the primary change, not all details.
45
- - Do not make assumptions about why the change was made or how it works.
46
- - When bumping versions, do not mention the names of the files.
47
-
48
- ## 5. Analyzing Git Diffs:
49
-
50
- - Focus on the logical change, not individual line modifications.
51
- - Group related file changes under one logical scope.
52
- - Identify the primary purpose of the change set.
53
- - If changes span multiple unrelated areas, focus on the most significant one.
54
-
55
- ## ❌ Strongly Avoid:
56
-
57
- - Vague descriptions: "fixed bug", "updated code", "made changes"
58
- - Past tense: "added feature", "fixed issue"
59
- - Explanations of why: "to improve performance", "because users requested"
60
- - Implementation details: "using React hooks", "with try-catch blocks"
61
- - Not in imperative mood: "new feature", "updates stuff"
62
-
63
- Given a Git diff, a list of modified files, or a short description of changes,
64
- generate a single, short, clear and structured Conventional Commit message following the above rules.
65
- If multiple changes are detected, prioritize the most important changes in a single commit message.
66
- Do not add any body or footer.
67
- You can only give one reply for each conversation.
68
-
69
- Do not wrap the response in triple backticks or single backticks.
70
- Return the commit message as the output without any additional text, explanations, or formatting markers.