Skip to content

✨ feat(formatter): add diff truncator and enhance formatting with Dif…#43

Merged
samzong merged 1 commit intomainfrom
feat/formatter-2
Jan 22, 2026
Merged

✨ feat(formatter): add diff truncator and enhance formatting with Dif…#43
samzong merged 1 commit intomainfrom
feat/formatter-2

Conversation

@samzong
Copy link
Owner

@samzong samzong commented Jan 22, 2026

…fStatsSeparator constant and emoji prefix type inference

…fStatsSeparator constant and emoji prefix type inference

Signed-off-by: samzong <samzong.lu@gmail.com>
@samzong samzong merged commit 12bd65a into main Jan 22, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @samzong, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the commit message formatting capabilities by introducing a smart diff truncation system. This system intelligently reduces the size of large diffs presented to the user, focusing on retaining critical changes while omitting less important ones. Additionally, it refines the process of automatically determining commit types from emoji prefixes, leading to more accurate and standardized commit messages.

Highlights

  • Diff Truncation with Prioritization: Introduced a new intelligent diff truncator that prioritizes important files and hunks when the diff content exceeds a predefined limit, ensuring that the most relevant changes are preserved.
  • Enhanced Emoji Prefix Type Inference: Improved the logic for inferring commit types from leading emojis in commit messages, allowing for better normalization and consistency in formatting.
  • Git Diff Stats Integration: Added functionality to retrieve Git diff statistics (--numstat --summary) to inform the new diff truncation mechanism, enabling more granular control over what parts of a large diff are retained.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant enhancements to diff formatting and commit message generation. The new diff truncator intelligently prioritizes changes, ensuring that the most relevant information is presented within a given limit. Additionally, the system can now infer commit types from emoji prefixes, improving the flexibility and user experience of commit message formatting. The changes are well-integrated across internal/emoji, internal/formatter, internal/git, and internal/workflow modules, with corresponding test updates.

Comment on lines +231 to +255
if strings.Contains(path, "{") && strings.Contains(path, "}") {
oldPath := ""
newPath := ""
rest := path
for {
start := strings.Index(rest, "{")
end := strings.Index(rest, "}")
if start == -1 || end == -1 || end < start {
oldPath += rest
newPath += rest
break
}
oldPath += rest[:start]
newPath += rest[:start]
segment := rest[start+1 : end]
parts := strings.SplitN(segment, "=>", 2)
if len(parts) != 2 {
oldPath += "{" + segment + "}"
newPath += "{" + segment + "}"
} else {
oldPath += strings.TrimSpace(parts[0])
newPath += strings.TrimSpace(parts[1])
}
rest = rest[end+1:]
}

Choose a reason for hiding this comment

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

medium

The splitRenamePath function, particularly the logic for handling {old => new} syntax, is quite complex and involves multiple string manipulations and conditional checks. While it appears to cover the intended cases, such intricate parsing logic can be brittle and prone to edge-case bugs. Consider adding more dedicated unit tests for this function with various rename path formats (e.g., paths with multiple {} blocks, nested {} blocks, or malformed {} blocks) to ensure its robustness and correctness.

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.

1 participant