Skip to content

Conversation

@mingcheng
Copy link
Owner

@mingcheng mingcheng commented Oct 16, 2025

Summary by Sourcery

Refactor Git handling into a repository module, introduce structured commit message management, and optimize CLI and OpenAI integrations using build-time metadata

New Features:

  • Add GitMessage struct to encapsulate commit title, content, and signoff logic
  • Introduce --print-table option and render commit messages in a table format
  • Generate build-time package metadata with built crate and expose it via built_info

Enhancements:

  • Refactor Git client into repository module with unified get_author and Display implementation
  • Update OpenAI client to use built_info metadata for org ID, user agent, and headers
  • Replace hardcoded CLI metadata with values from built_info

Build:

  • Add build.rs to generate built_info using built crate and update Cargo.toml with build-dependencies

Documentation:

  • Add OpenSSF Best Practices badge to README

Tests:

  • Update repository and GitMessage tests to validate unified author retrieval and message formatting
  • Add test for print_table function

- add build.rs script to generate build-time metadata
- replace hardcoded constants with built_info module data
- update CLI command metadata to use generated package info
- fix missing closing bracket in authors field in Cargo.toml
- add built crate dependency for build-time information

Signed-off-by: mingcheng <[email protected]>
- include OpenSSF scorecard badge for security compliance visibility
- position badge alongside existing CI/CD status indicators

Signed-off-by: mingcheng <[email protected]>
@mingcheng mingcheng self-assigned this Oct 16, 2025
@mingcheng mingcheng added the enhancement New feature or request label Oct 16, 2025
@mingcheng mingcheng requested a review from Copilot October 16, 2025 07:52
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 16, 2025

Reviewer's Guide

This PR refactors core Git operations into a dedicated repository module, introduces a GitMessage abstraction for commit content and signoff logic, wires in build-time metadata via built_info for consistent CLI and OpenAI client configuration, adds a table-printing feature to the CLI, and updates dependencies, tests, and docs to support these changes.

Sequence diagram for commit flow with GitMessage and signoff logic

sequenceDiagram
    participant Main
    participant Cli
    participant GitMessage
    participant Git
    participant Author
    Main->>Cli: Parse CLI args
    Main->>Git: Open repository
    Main->>Git: get_author()
    Git->>Author: Return author info
    Main->>GitMessage: new(&Git, title, content, signoff)
    GitMessage->>Git: get_author() (if signoff)
    Git->>Author: Return author info
    GitMessage-->>Main: Return GitMessage
    Main->>Git: commit(&GitMessage)
    Git->>Author: get_author()
    Git->>Git: commit with signature
    Git-->>Main: Return result
Loading

Class diagram for refactored Git and new GitMessage types

classDiagram
    class Git {
        -repository: Repository
        +new(path: &str): Result<Git, Box<dyn Error>>
        +commit(message: &GitMessage): Result<(), Box<dyn Error>>
        +get_author(): Result<Author, Box<dyn Error>>
        +get_diff(): Result<String, Box<dyn Error>>
    }
    class Author {
        +name: String
        +email: String
    }
    class GitMessage {
        +title: String
        +content: String
        +new(repository: &Git, title: &str, content: &str, signoff: bool): Result<GitMessage, Box<dyn Error>>
        +is_empty(): bool
        +to_string(): String
    }
    Git --> Author : uses
    GitMessage --> Git : uses
Loading

Class diagram for updated CLI struct and print_table function

classDiagram
    class Cli {
        +print_table: bool
        +copy: bool
        +save: String
        +signoff: bool
        +yes: bool
        +other args...
    }
    class built_info {
        +PKG_NAME
        +PKG_DESCRIPTION
        +PKG_VERSION
        +PKG_AUTHORS
        +PKG_HOMEPAGE
    }
    class print_table {
        +print_table(title: &str, content: &str)
    }
    Cli --> built_info : uses
    print_table --> Cli : uses
Loading

Class diagram for OpenAI client refactored to use built_info

classDiagram
    class OpenAI {
        +new(...): OpenAI
        +create_chat(...): ...
        -client
    }
    class built_info {
        +PKG_NAME
        +PKG_DESCRIPTION
        +PKG_VERSION
        +PKG_AUTHORS
        +PKG_HOMEPAGE
    }
    OpenAI --> built_info : uses
Loading

File-Level Changes

Change Details Files
Rename and reorganize Git module into repository.rs
  • Converted git.rs to repository.rs and updated documentation
  • Replaced log with tracing for diagnostics
  • Updated lib.rs to remove old git module and export repository
src/repository.rs
src/lib.rs
Unify author retrieval and simplify commit signature flow
  • Merged get_author_name and get_author_email into get_author returning Author struct
  • Simplified commit() to accept GitMessage and dropped need_signoff flag
  • Added Display impl to Git for better string formatting
src/repository.rs
Extract commit message handling into GitMessage type
  • Added src/message.rs defining GitMessage with title, content, signoff logic
  • Moved signoff processing into GitMessage.new()
  • Implemented Display, to_string, and is_empty for GitMessage
src/message.rs
Enhance CLI with build metadata and table output
  • Introduced built_info module via build.rs to inject PKG_* constants
  • Updated clap definitions to use built_info for name, version, description, author
  • Added print_table flag and implemented print_table() using tabled crate
src/cli.rs
build.rs
Cargo.toml
Refactor OpenAI client to use built_info constants
  • Replaced hardcoded CMD and URLs with built_info::PKG_* in headers and org_id
  • Adjusted user_agent to include built_info description
  • Added tracing for model selection and updated imports
src/openai.rs
Integrate GitMessage in main workflow and conditional output
  • Split AI result into title/content and construct GitMessage
  • Switched to print_table() or raw output based on print_table flag
  • Updated commit call to repository.commit(&GitMessage) and clipboard logic
src/main.rs
Update documentation and badges
  • Added OpenSSF Best Practices badge to README
  • Updated Cargo.toml authors formatting and added tabled and built dependencies
README.md
Cargo.toml

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

@coderabbitai
Copy link

coderabbitai bot commented Oct 16, 2025

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.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/cli-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.

Copy link
Contributor

Copilot AI left a comment

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 CLI tool to optimize code organization and enhance functionality. The changes focus on modularizing the codebase by separating concerns into dedicated modules and integrating build-time metadata.

  • Restructured code by introducing new modules (message.rs, repository.rs) and removing hardcoded constants
  • Added table-formatted output option and integrated build-time metadata using the built crate
  • Simplified author handling by consolidating name and email retrieval into a single method

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/repository.rs Renamed from git.rs, consolidated author methods, refactored commit signature handling
src/message.rs New module for commit message handling with signoff functionality
src/openai.rs Updated imports and integrated build-time metadata for package info
src/main.rs Updated to use new modules and added table formatting support
src/cli.rs Integrated build-time metadata and added table printing functionality
src/lib.rs Updated module exports to reflect new structure
build.rs New build script for generating build-time metadata
Cargo.toml Fixed author email format and added new dependencies
README.md Added OpenSSF Best Practices badge

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

New security issues found

- name: Log in to the Container registry

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Copy link

Choose a reason for hiding this comment

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

security (yaml.github-actions.security.third-party-action-not-pinned-to-commit-sha): An action sourced from a third-party repository on GitHub is not pinned to a full length commit SHA. Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps mitigate the risk of a bad actor adding a backdoor to the action's repository, as they would need to generate a SHA-1 collision for a valid Git object payload.

Source: opengrep

uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Copy link

Choose a reason for hiding this comment

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

security (yaml.github-actions.security.third-party-action-not-pinned-to-commit-sha): An action sourced from a third-party repository on GitHub is not pinned to a full length commit SHA. Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps mitigate the risk of a bad actor adding a backdoor to the action's repository, as they would need to generate a SHA-1 collision for a valid Git object payload.

Source: opengrep


- name: Generate SBOM
if: github.event_name != 'pull_request'
uses: anchore/sbom-action@v0
Copy link

Choose a reason for hiding this comment

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

security (yaml.github-actions.security.third-party-action-not-pinned-to-commit-sha): An action sourced from a third-party repository on GitHub is not pinned to a full length commit SHA. Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps mitigate the risk of a bad actor adding a backdoor to the action's repository, as they would need to generate a SHA-1 collision for a valid Git object payload.

Source: opengrep

uses: actions/checkout@v4

- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
Copy link

Choose a reason for hiding this comment

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

security (yaml.github-actions.security.third-party-action-not-pinned-to-commit-sha): An action sourced from a third-party repository on GitHub is not pinned to a full length commit SHA. Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps mitigate the risk of a bad actor adding a backdoor to the action's repository, as they would need to generate a SHA-1 collision for a valid Git object payload.

Source: opengrep

uses: actions/checkout@v4

- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
Copy link

Choose a reason for hiding this comment

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

security (yaml.github-actions.security.third-party-action-not-pinned-to-commit-sha): An action sourced from a third-party repository on GitHub is not pinned to a full length commit SHA. Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps mitigate the risk of a bad actor adding a backdoor to the action's repository, as they would need to generate a SHA-1 collision for a valid Git object payload.

Source: opengrep

uses: actions/checkout@v4

- name: Setup Rust toolchain (${{ matrix.toolchain }})
uses: dtolnay/rust-toolchain@master
Copy link

Choose a reason for hiding this comment

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

security (yaml.github-actions.security.third-party-action-not-pinned-to-commit-sha): An action sourced from a third-party repository on GitHub is not pinned to a full length commit SHA. Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps mitigate the risk of a bad actor adding a backdoor to the action's repository, as they would need to generate a SHA-1 collision for a valid Git object payload.

Source: opengrep

uses: actions/checkout@v4

- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
Copy link

Choose a reason for hiding this comment

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

security (yaml.github-actions.security.third-party-action-not-pinned-to-commit-sha): An action sourced from a third-party repository on GitHub is not pinned to a full length commit SHA. Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release. Pinning to a particular SHA helps mitigate the risk of a bad actor adding a backdoor to the action's repository, as they would need to generate a SHA-1 collision for a valid Git object payload.

Source: opengrep

- add tabled dependency for structured output formatting
- implement print_table function with rounded styling and text wrapping
- add print_table CLI flag with default true value
- include comprehensive test case for table display functionality
- set table width limit to 120 characters with left alignment

Signed-off-by: mingcheng <[email protected]>
- update ghcr.yml to support multi-platform builds and add SBOM generation
- improve rust.yml with linting, security audit, and toolchain matrix testing
- add caching for faster builds and artifact attestations
- expand triggers for feature branches and semantic versioning tags
- optimize workflow steps for better error handling and performance

Signed-off-by: mingcheng <[email protected]>
@mingcheng mingcheng force-pushed the feature/cli-optimize branch from beecf99 to c28908f Compare October 16, 2025 09:48
@mingcheng mingcheng closed this Oct 16, 2025
@mingcheng mingcheng deleted the feature/cli-optimize branch October 16, 2025 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants