Skip to content

chroe/prompt optimize - #22

Closed
mingcheng wants to merge 19 commits into
release/1.4.0from
chroe/prompt-optimize
Closed

mingcheng wants to merge 19 commits into
release/1.4.0from
chroe/prompt-optimize

Conversation

@mingcheng

@mingcheng mingcheng commented Sep 21, 2025 •

Copy link
Copy Markdown
Owner

Summary by Sourcery

Validate OpenAI model names on demand and centralize commit sign-off handling by refactoring the Git commit implementation and OpenAI client, bump version, update metadata and README with semantic commit guidelines

New Features:

  • Add '--check' CLI option to validate OpenAI API key and model availability

Enhancements:

  • Move commit sign-off logic into the Git layer and use Git signature API for author and committer
  • Replace deprecated OpenAI check with a 'check_model' method that verifies model availability
  • Refactor commit message handling to enforce immutability and pass sign-off flag to repository.commit
  • Bump package version to 1.4.0, update Cargo.toml metadata and disable unused dependencies

Documentation:

  • Add semantic commit message guidelines references and refine tool description in README

Chores:

  • Add .coderabbit.yaml configuration for code review automation

mingcheng and others added 19 commits July 11, 2025 19:33
* feat: implement signoff feature for commit messages ✍️

- Add signoff option to CLI arguments in `cli.rs`
- Implement author name and email retrieval in `git.rs`
- Append signoff to commit message in `main.rs` if enabled
- Add tests for author name and email functions in `git.rs`

Signed-off-by: mingcheng <mingcheng@apache.org>

* feat: add auto signoff detection from environment variable ✍️

- Implement detection of GIT_AUTO_SIGNOFF environment variable
- Enable signoff if environment variable is set to true or 1
- Update logic to combine CLI signoff option with environment variable check

Signed-off-by: mingcheng <mingcheng@apache.org>

* docs: update README with new environment variable for signoff 📚

- Add `AIGITCOMMIT_SIGNOFF` environment variable to README
- Mention auto sign-off feature when variable is set to true

Signed-off-by: mingcheng <mingcheng@apache.org>

* style: update log message formatting in git and openai modules 🖌️ (#13)

- Replace static string formatting with variable interpolation in log messages
- Apply consistent formatting for trace logs across `git.rs` and `openai.rs`

Signed-off-by: mingcheng <mingcheng@apache.org>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* docs: correct environment variable name in README 📚

- Update `AIGITCOMMIT_SIGNOFF` to `GIT_AUTO_SIGNOFF` in README for consistency
- Reflect the correct variable used in the code for auto signoff feature

Signed-off-by: mingcheng <mingcheng@apache.org>

* style: update log message formatting in git and openai modules 🖌️ (#13)

- Replace static string formatting with variable interpolation in log messages
- Apply consistent formatting for trace logs across `git.rs` and `openai.rs`

Signed-off-by: mingcheng <mingcheng@apache.org>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* docs: correct environment variable name in README 📚

- Update `AIGITCOMMIT_SIGNOFF` to `GIT_AUTO_SIGNOFF` in README for consistency
- Reflect the correct variable used in the code for auto signoff feature

Signed-off-by: mingcheng <mingcheng@apache.org>

* docs: update file modification timestamps 📅

- Adjust last modified timestamps in `main.rs` and `openai.rs` for accuracy
- Resolve merge conflict timestamp in `main.rs` to reflect latest update

Signed-off-by: mingcheng <mingcheng@apache.org>

* feat: update version to 1.3.3 and add grok keyword 🚀

- Bump version from 1.3.2 to 1.3.3 in Cargo.toml
- Add "grok" to keywords list in package metadata

* feat: add CLI check for OpenAI API and model availability 🔍

- Introduce --check flag in CLI to verify API key and model
- Implement check_model function to list and validate available models
- Integrate check logic in main.rs with error handling
- Comment out unused dependencies in Cargo.toml
- Update package categories in Cargo.toml

* refactor: simplify string formatting in model validation 🛠️

- Update error message formatting in main.rs to use direct variable interpolation
- Simplify debug and error messages in openai.rs with consistent string formatting
- Remove redundant string concatenation for cleaner code readability

Signed-off-by: mingcheng <mingcheng@apache.org>

* feat: implement signoff feature for git commits ✍️

- Add support for signed-off-by line in commit messages with configurable option
- Refactor commit function to accept signoff parameter in git.rs
- Retrieve author name and email from repository config for signoff
- Remove redundant signoff logic from main.rs and centralize in git.rs
- Update commit call in main.rs to pass signoff requirement

Signed-off-by: mingcheng <mingcheng@apache.org>

---------

Signed-off-by: mingcheng <mingcheng@apache.org>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: implement signoff feature for commit messages ✍️

- Add signoff option to CLI arguments in `cli.rs`
- Implement author name and email retrieval in `git.rs`
- Append signoff to commit message in `main.rs` if enabled
- Add tests for author name and email functions in `git.rs`

Signed-off-by: mingcheng <mingcheng@apache.org>

* feat: add auto signoff detection from environment variable ✍️

- Implement detection of GIT_AUTO_SIGNOFF environment variable
- Enable signoff if environment variable is set to true or 1
- Update logic to combine CLI signoff option with environment variable check

Signed-off-by: mingcheng <mingcheng@apache.org>

* docs: update README with new environment variable for signoff 📚

- Add `AIGITCOMMIT_SIGNOFF` environment variable to README
- Mention auto sign-off feature when variable is set to true

Signed-off-by: mingcheng <mingcheng@apache.org>

* style: update log message formatting in git and openai modules 🖌️ (#13)

- Replace static string formatting with variable interpolation in log messages
- Apply consistent formatting for trace logs across `git.rs` and `openai.rs`

Signed-off-by: mingcheng <mingcheng@apache.org>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* docs: correct environment variable name in README 📚

- Update `AIGITCOMMIT_SIGNOFF` to `GIT_AUTO_SIGNOFF` in README for consistency
- Reflect the correct variable used in the code for auto signoff feature

Signed-off-by: mingcheng <mingcheng@apache.org>

* style: update log message formatting in git and openai modules 🖌️ (#13)

- Replace static string formatting with variable interpolation in log messages
- Apply consistent formatting for trace logs across `git.rs` and `openai.rs`

Signed-off-by: mingcheng <mingcheng@apache.org>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* docs: correct environment variable name in README 📚

- Update `AIGITCOMMIT_SIGNOFF` to `GIT_AUTO_SIGNOFF` in README for consistency
- Reflect the correct variable used in the code for auto signoff feature

Signed-off-by: mingcheng <mingcheng@apache.org>

* docs: update file modification timestamps 📅

- Adjust last modified timestamps in `main.rs` and `openai.rs` for accuracy
- Resolve merge conflict timestamp in `main.rs` to reflect latest update

Signed-off-by: mingcheng <mingcheng@apache.org>

* feat: update version to 1.3.3 and add grok keyword 🚀

- Bump version from 1.3.2 to 1.3.3 in Cargo.toml
- Add "grok" to keywords list in package metadata

* feat: add CLI check for OpenAI API and model availability 🔍

- Introduce --check flag in CLI to verify API key and model
- Implement check_model function to list and validate available models
- Integrate check logic in main.rs with error handling
- Comment out unused dependencies in Cargo.toml
- Update package categories in Cargo.toml

* refactor: simplify string formatting in model validation 🛠️

- Update error message formatting in main.rs to use direct variable interpolation
- Simplify debug and error messages in openai.rs with consistent string formatting
- Remove redundant string concatenation for cleaner code readability

Signed-off-by: mingcheng <mingcheng@apache.org>

* feat: implement signoff feature for git commits ✍️

- Add support for signed-off-by line in commit messages with configurable option
- Refactor commit function to accept signoff parameter in git.rs
- Retrieve author name and email from repository config for signoff
- Remove redundant signoff logic from main.rs and centralize in git.rs
- Update commit call in main.rs to pass signoff requirement

Signed-off-by: mingcheng <mingcheng@apache.org>

---------

Signed-off-by: mingcheng <mingcheng@apache.org>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.3.19 to 0.3.20.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](tokio-rs/tracing@tracing-subscriber-0.3.19...tracing-subscriber-0.3.20)

---
updated-dependencies:
- dependency-name: tracing-subscriber
  dependency-version: 0.3.20
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [slab](https://github.com/tokio-rs/slab) from 0.4.10 to 0.4.11.
- [Release notes](https://github.com/tokio-rs/slab/releases)
- [Changelog](https://github.com/tokio-rs/slab/blob/master/CHANGELOG.md)
- [Commits](tokio-rs/slab@v0.4.10...v0.4.11)

---
updated-dependencies:
- dependency-name: slab
  dependency-version: 0.4.11
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Introduce `.coderabbit.yaml` for automated code reviews
- Configure language to en-US and define path filters
- Enable high-level summaries and auto-review with clippy

Signed-off-by: mingcheng <mingcheng@apache.org>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Add signoff option to CLI arguments in `cli.rs`
- Implement author name and email retrieval in `git.rs`
- Append signoff to commit message in `main.rs` if enabled
- Add tests for author name and email functions in `git.rs`

Signed-off-by: mingcheng <mingcheng@apache.org>
- Implement detection of GIT_AUTO_SIGNOFF environment variable
- Enable signoff if environment variable is set to true or 1
- Update logic to combine CLI signoff option with environment variable check

Signed-off-by: mingcheng <mingcheng@apache.org>
- Add `AIGITCOMMIT_SIGNOFF` environment variable to README
- Mention auto sign-off feature when variable is set to true

Signed-off-by: mingcheng <mingcheng@apache.org>
- Replace static string formatting with variable interpolation in log messages
- Apply consistent formatting for trace logs across `git.rs` and `openai.rs`

Signed-off-by: mingcheng <mingcheng@apache.org>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Update `AIGITCOMMIT_SIGNOFF` to `GIT_AUTO_SIGNOFF` in README for consistency
- Reflect the correct variable used in the code for auto signoff feature

Signed-off-by: mingcheng <mingcheng@apache.org>
- Replace static string formatting with variable interpolation in log messages
- Apply consistent formatting for trace logs across `git.rs` and `openai.rs`

Signed-off-by: mingcheng <mingcheng@apache.org>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Update `AIGITCOMMIT_SIGNOFF` to `GIT_AUTO_SIGNOFF` in README for consistency
- Reflect the correct variable used in the code for auto signoff feature

Signed-off-by: mingcheng <mingcheng@apache.org>
- Adjust last modified timestamps in `main.rs` and `openai.rs` for accuracy
- Resolve merge conflict timestamp in `main.rs` to reflect latest update

Signed-off-by: mingcheng <mingcheng@apache.org>
- Bump version from 1.3.2 to 1.3.3 in Cargo.toml
- Add "grok" to keywords list in package metadata
- Introduce --check flag in CLI to verify API key and model
- Implement check_model function to list and validate available models
- Integrate check logic in main.rs with error handling
- Comment out unused dependencies in Cargo.toml
- Update package categories in Cargo.toml
- Update error message formatting in main.rs to use direct variable interpolation
- Simplify debug and error messages in openai.rs with consistent string formatting
- Remove redundant string concatenation for cleaner code readability

Signed-off-by: mingcheng <mingcheng@apache.org>
- Add support for signed-off-by line in commit messages with configurable option
- Refactor commit function to accept signoff parameter in git.rs
- Retrieve author name and email from repository config for signoff
- Remove redundant signoff logic from main.rs and centralize in git.rs
- Update commit call in main.rs to pass signoff requirement

Signed-off-by: mingcheng <mingcheng@apache.org>
- Add instructions for generating git commit messages
- Include details on diff-based message creation
- Remove signed-off-by message from commit instructions
- Update examples to reflect recent commit styles

Signed-off-by: mingcheng <mingcheng@apache.org>
- Update version from 1.3.3 to 1.4.0 in Cargo.toml
- Enhance system template with additional instructions
- Simplify and clarify template content for better usability
- Remove redundant information to streamline template
- Ensure template aligns with latest commit message standards

Signed-off-by: mingcheng <mingcheng@apache.org>
@coderabbitai

coderabbitai Bot commented Sep 21, 2025

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chroe/prompt-optimize

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai

sourcery-ai Bot commented Sep 21, 2025 •

Copy link
Copy Markdown

Reviewer's Guide

This PR optimizes prompt handling by introducing a model availability check via a new CLI flag, refactors signoff logic into the Git layer, updates project metadata and dependencies, refines documentation, and adds a coderabbit configuration file.

File-Level Changes

Change Details Files
Add --check flag with model availability validation
  • Introduce check option in CLI definition
  • Remove deprecated check API reachability call in main
  • Invoke new client.check_model(&model_name) when --check is enabled
  • Implement check_model in OpenAI client to list models and verify the specified one
src/cli.rs
src/main.rs
src/openai.rs
Move commit signoff logic into Git.commit
  • Pass need_signoff flag to repository.commit in main and remove inline signoff there
  • Extend Git::commit signature to accept need_signoff and create a signature
  • Append Signed-off-by trailer inside Git::commit when requested
  • Add doc comments for author/email, diff, and logs helpers
src/main.rs
src/git.rs
Update project version, keywords, and dependencies
  • Bump package version from 1.3.2 to 1.4.0
  • Add grok keyword and simplify categories
  • Comment out unused serde and strum dependencies
Cargo.toml
Refine README content and add references
  • Adjust tool description phrasing for clarity
  • Insert a References section with links to Conventional Commits guides
  • Clean up minor formatting inconsistencies
README.md
Add coderabbit configuration file
  • Introduce .coderabbit.yaml with review and lint settings
.coderabbit.yaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@mingcheng
mingcheng requested a review from Copilot September 21, 2025 11:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the commit message generation workflow by implementing on-demand OpenAI model validation, centralizing Git commit operations, and updating the system prompt to enforce Conventional Commits standards.

  • Adds a --check CLI option to validate OpenAI API key and model availability before processing
  • Refactors commit signing logic from main into the Git layer using proper Git signature API
  • Updates system prompt template with comprehensive Conventional Commits specification and formatting rules

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
templates/system.txt Complete rewrite to enforce Conventional Commits specification with detailed formatting rules
src/openai.rs Replaces deprecated API check with model-specific validation method
src/main.rs Removes commit sign-off logic and integrates new check option workflow
src/git.rs Centralizes commit operations with proper signature handling and sign-off support
src/cli.rs Adds new --check CLI option for API validation
README.md Updates description and adds semantic commit message references
Cargo.toml Version bump and dependency cleanup
.coderabbit.yaml Adds code review automation configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread templates/system.txt
@@ -1,31 +1,62 @@
You are an experienced senior in software development with years of experience contributing to the open-source community.
You are an expert in generating Git commit messages following the Conventional Commits specification, focusing on creating precise, meaningful, and standardized commit documentation. English must be your primary language.

Copilot AI Sep 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the PR title 'chroe/prompt optimize' - it should be 'chore/prompt optimize'.

Copilot uses AI. Check for mistakes.
Comment thread src/git.rs
Comment on lines +40 to +43
pub fn commit(&self, message: &str, need_signoff: bool) -> Result<(), Box<dyn Error>> {
// Get the current index (staged changes)

let mut message = message.to_string();

Copilot AI Sep 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message parameter is converted to a mutable String but the original parameter could be changed to mut message: String to avoid the clone operation and make the intent clearer.

Suggested change
pub fn commit(&self, message: &str, need_signoff: bool) -> Result<(), Box<dyn Error>> {
// Get the current index (staged changes)
let mut message = message.to_string();
pub fn commit(&self, mut message: String, need_signoff: bool) -> Result<(), Box<dyn Error>> {
// Get the current index (staged changes)

Copilot uses AI. Check for mistakes.
Comment thread src/cli.rs

#[arg(
long,
help = "Check the openai api key and model name whether is available",

Copilot AI Sep 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text has grammatical issues. It should be 'Check whether the OpenAI API key and model name are available' or 'Check if the OpenAI API key and model name are available'.

Suggested change
help = "Check the openai api key and model name whether is available",
help = "Check whether the OpenAI API key and model name are available",

Copilot uses AI. Check for mistakes.
@mingcheng mingcheng closed this Sep 21, 2025
@mingcheng
mingcheng deleted the chroe/prompt-optimize branch September 21, 2025 11:24
@mingcheng
mingcheng restored the chroe/prompt-optimize branch September 21, 2025 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants