Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: kaizen generate pr commit msg and description #550

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/code_review/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@
user="kaizen/example",
)
print(desc_data)

comit_message = pr_desc.generate_pr_commit_message(desc_data.desc)
12 changes: 12 additions & 0 deletions kaizen/generator/pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
PR_DESCRIPTION_PROMPT,
MERGE_PR_DESCRIPTION_PROMPT,
PR_DESCRIPTION_SYSTEM_PROMPT,
PR_COMMIT_MESSAGE_PROMPT,
)


Expand Down Expand Up @@ -170,3 +171,14 @@ def _process_file_chunk(
self.total_usage = self.provider.update_usage(self.total_usage, usage)

return desc

def generate_pr_commit_message(
self,
desc: str,
user: Optional[str] = None,
) -> str:
prompt = PR_COMMIT_MESSAGE_PROMPT.format(
DESC=desc,
)
resp, usage = self.provider.chat_completion_with_json(prompt, user=user)
return resp, usage
55 changes: 55 additions & 0 deletions kaizen/llms/prompts/pr_desc_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,58 @@
Here is list of PR descriptions in json format:
{DESCS}
"""


PR_COMMIT_MESSAGE_PROMPT = """
Generate a concise and informative Git commit message based on the following description of code changes.
Follow the Conventional Commits format and these best practices:

1. Start with a type prefix, followed by a colon and space (e.g., feat:, fix:, docs:)
2. Use lowercase for the entire subject line
3. Keep the subject line (first line) under 50 characters
4. Summarize the main change in the subject line
5. Leave a blank line between the subject and the body (if a body is needed)
6. Use the body to explain the what and why of the change, not the how
7. Wrap the body at 72 characters
8. Use bullet points in the body for multiple changes if necessary
9. Include relevant issue numbers (e.g., "fixes #123" or "relates to #456")

Common type prefixes:
- feat: A new feature
- fix: A bug fix
- docs: Documentation only changes
- style: Changes that do not affect the meaning of the code (white-space, formatting, etc)
- refactor: A code change that neither fixes a bug nor adds a feature
- perf: A code change that improves performance
- test: Adding missing tests or correcting existing tests
- chore: Changes to the build process or auxiliary tools and libraries

Examples:

1. Simple change:
{{
"subject": "fix: typo in README.md",
"body": null
}}

2. Complex change:
{{
"subject": "feat: user authentication feature",
"body": "Implement login and logout functionality for users.\\n\\n- Create login form and handle submission\\n- Set up session management\\n- Add logout button and route\\n- Update navbar to show login status\\n\\nRelates to #42"
}}


Based on this description, generate a commit message following the above guidelines and examples.
If the changes are simple, a subject line alone may suffice. For more complex changes, include a body with additional details.

Provide the output in JSON format with the following structure:
```
{{
"subject": "prefix:the commit message subject line",
"body": "The commit message body (if necessary, otherwise null)"
}}
```

Code change description:
{DESC}
"""
Loading