-
Notifications
You must be signed in to change notification settings - Fork 21
✨ Add a preview commit text in config #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request introduces a preview of the Git commit message in the configuration panel, allowing users to see how their commit message will look based on the selected options. This is a useful feature that enhances the user experience. The implementation is generally well-structured, but there are a few areas that could be improved for clarity and efficiency.
Summary of Findings
- Code Duplication: The logic for constructing the commit message preview is duplicated in the
applyandresetmethods. This could be refactored into a single function to improve maintainability. - Boolean Configuration: The boolean configuration variables are directly used in the
previewCommitfunction. Consider using the values from the UI components directly to ensure the preview reflects the current UI state. - Clarity of Commit Message Construction: The
previewCommitfunction could be made more readable by using aStringBuilderor similar approach to construct the commit message.
Merge Readiness
The pull request is a good addition to the plugin. However, I recommend addressing the identified issues before merging to improve code quality and maintainability. Specifically, refactoring the duplicated code and ensuring the preview accurately reflects the UI state would be beneficial. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.
| useUnicode.addChangeListener { previewCommit() } | ||
| insertInCursorPosition.addChangeListener { previewCommit() } | ||
| includeGitMojiDescription.addChangeListener { previewCommit() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting this to a separate function to avoid duplication with the apply and reset methods. This will improve maintainability and readability.
| useUnicode.addChangeListener { previewCommit() } | |
| insertInCursorPosition.addChangeListener { previewCommit() } | |
| includeGitMojiDescription.addChangeListener { previewCommit() } | |
| useUnicode.addChangeListener { updatePreviewCommit() } | |
| insertInCursorPosition.addChangeListener { updatePreviewCommit() } | |
| includeGitMojiDescription.addChangeListener { updatePreviewCommit() } |
| projectInstance.setValue(CONFIG_AFTER_UNICODE, textAfterUnicodeConfig) | ||
| instance.setValue(CONFIG_LANGUAGE, languagesConfig) | ||
| GitmojiLocale.loadTranslations() | ||
| previewCommit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| else -> textAfterUnicodeOptions.indexOf(textAfterUnicodeConfig) | ||
| } | ||
| languages.selectedIndex = languageOptions.indexOf(languagesConfig) | ||
| previewCommit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private fun previewCommit():Boolean { | ||
| var message = "" | ||
| if (insertInCursorPositionConfig) { | ||
| message += "Commit message|" | ||
| } | ||
| if (useUnicodeConfig) { | ||
| message += "✨" | ||
| } | ||
| else { | ||
| message += ":sparkles:" | ||
| } | ||
| message += textAfterUnicodeConfig | ||
| val selectionStart = message.length | ||
| if (includeGitMojiDescriptionConfig) { | ||
| message += "Introduce new features." | ||
| } | ||
| else if (!insertInCursorPositionConfig) { | ||
| message += "Commit message" | ||
| } | ||
| previewGitCommitMessage.text = message | ||
| previewGitCommitMessage.select(selectionStart, message.length) | ||
| return true | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is used to construct the preview commit message. Consider using a StringBuilder for better readability and performance. Also, directly use the values from the UI components (e.g., useUnicode.isSelected) instead of the config variables to ensure the preview reflects the current UI state. Finally, consider renaming this function to updatePreviewCommitText to better reflect what it does.
private fun updatePreviewCommitText(): Boolean {
val messageBuilder = StringBuilder()
if (insertInCursorPosition.isSelected) {
messageBuilder.append("Commit message|")
}
if (useUnicode.isSelected) {
messageBuilder.append("✨")
} else {
messageBuilder.append(":sparkles:")
}
messageBuilder.append(textAfterUnicode.selectedItem ?: "")
val selectionStart = messageBuilder.length
if (includeGitMojiDescription.isSelected) {
messageBuilder.append("Introduce new features.")
} else if (!insertInCursorPosition.isSelected) {
messageBuilder.append("Commit message")
}
val message = messageBuilder.toString()
previewGitCommitMessage.text = message
previewGitCommitMessage.select(selectionStart, message.length)
return true
}
Qodana Community for JVM1 new problem were found
💡 Qodana analysis was run in the pull request mode: only the changed files were checked View the detailed Qodana reportTo be able to view the detailed Qodana report, you can either:
To get - name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2025.1.1
with:
upload-result: trueContact Qodana teamContact us at qodana-support@jetbrains.com
|
No description provided.