Skip to content

Commit

Permalink
feat: kaizen generate pr commit msg and description
Browse files Browse the repository at this point in the history
  • Loading branch information
sauravpanda committed Sep 16, 2024
1 parent 6dc40d6 commit 3410fb8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
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}
"""

0 comments on commit 3410fb8

Please sign in to comment.