Skip to content

Instantly share code, notes, and snippets.

@emmadesilva
Created July 12, 2024 17:21
Show Gist options
  • Select an option

  • Save emmadesilva/2c594879ec6bfea64c8c60bb2f236564 to your computer and use it in GitHub Desktop.

Select an option

Save emmadesilva/2c594879ec6bfea64c8c60bb2f236564 to your computer and use it in GitHub Desktop.
Personal AI commit message model generation
<?php
// SIMPLIFIED MODEL GENERATOR
$raw = trim(shell_exec('git log --pretty=format:"%s" --first-parent master'));
$lines = explode("\n", $raw);
$lines = filter_duplicates_keeping_first_matches($lines);
$lines = filter_lines_starting_with($lines, ['Merge', 'Revert', 'Reapply', 'Bump']);
file_put_contents(__DIR__.'/commit-message-model.txt', implode("\n", $lines));
// Next step: Pass the file to a capable LLM with a high context window, using this prompt:
// > Here is a list of commit messages, please compress these into a model that can be
// > used to replicate the commit message style when using an LLM/GPT model like
// > yourself to create similar looking commit messages from Git diffs.
@emmadesilva
Copy link
Author

Result:

### Follow these instructions to create a good commit message:

1. **Start with an imperative verb**:
    - Examples: Add, Update, Remove, Fix, Create, Adjust, Improve, Normalize, Simplify, Document, Change, Format, Refactor, Clean up, Rename, etc.

2. **Specify the target**:
    - Examples: workflow, documentation, configuration, test, method, helper, file, commit message, etc.

3. **Optionally provide context or additional details**:
    - Examples: to fix bug, for new feature, due to error, to improve readability, etc.

4. **Maintain concise and clear language**:
    - Ensure each message is specific and to the point.

Given this structure, here are some examples of how this model might look:

- `Add missing download path`
- `Update internal documentation`
- `Fix release notes spelling`
- `Remove mkdir call`
- `Create .phpstorm.meta.php`
- `Simplify test`
- `Normalize capitalization`
- `Format Markdown`
- `Refactor unit test to extend unit test case (12.5x faster)`

Using the above patterns, here is a generalized template:

```plaintext
[Verb] [Target] [Optional Context/Detail]
```

### Sample Generated Commit Messages

Using the template, here are a few sample commit messages:

1. `Add new API endpoint for user authentication`
2. `Update README to include setup instructions`
3. `Fix typo in configuration file`
4. `Remove deprecated methods from utility class`
5. `Create initial migration scripts`
6. `Adjust test cases to handle new validation rules`
7. `Document code with additional comments and examples`
8. `Format JSON response for better readability`
9. `Refactor database connection logic to use environment variables`
10. `Normalize header tags across all HTML files`

@emmadesilva
Copy link
Author

emmadesilva commented Jul 12, 2024

Usage:

Create a Git commit message for this patch. Provide 5 options matching the style guide added below the patch.

Paste patch here

Paste model here

Example response:

Claude Sonnet

Thank you for providing the patch and the commit message style guide. I'll create 5 options for Git commit messages that match the given style guide. Here are the options:

  1. Add commit message model generator script
  2. Create PHP script for generating commit message models
  3. Implement AI-assisted commit message generation tool
  4. Add script to extract and filter Git commit messages
  5. Create tool for building commit message style models

These options follow the style guide by starting with an imperative verb, specifying the target, and providing context where appropriate. They are concise and clear, focusing on the main purpose of the added script.

ChatGPT 4o

Here are five commit message options following the provided style guide:

  1. Create commit-message-model-generator script
  2. Add script to generate commit message model
  3. Simplify commit message model creation process
  4. Document commit message model generation script
  5. Format output of commit message model generator script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment