Skip to content

Conversation

@patou
Copy link
Owner

@patou patou commented Jul 26, 2022

No description provided.

@patou
Copy link
Owner Author

patou commented May 6, 2025

/gemini review

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

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 apply and reset methods. This could be refactored into a single function to improve maintainability.
  • Boolean Configuration: The boolean configuration variables are directly used in the previewCommit function. Consider using the values from the UI components directly to ensure the preview reflects the current UI state.
  • Clarity of Commit Message Construction: The previewCommit function could be made more readable by using a StringBuilder or 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.

Comment on lines +53 to +55
useUnicode.addChangeListener { previewCommit() }
insertInCursorPosition.addChangeListener { previewCommit() }
includeGitMojiDescription.addChangeListener { previewCommit() }

Choose a reason for hiding this comment

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

medium

Consider extracting this to a separate function to avoid duplication with the apply and reset methods. This will improve maintainability and readability.

Suggested change
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()

Choose a reason for hiding this comment

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

medium

Call updatePreviewCommit here instead of previewCommit to use the extracted function.

Suggested change
previewCommit()
updatePreviewCommit()

else -> textAfterUnicodeOptions.indexOf(textAfterUnicodeConfig)
}
languages.selectedIndex = languageOptions.indexOf(languagesConfig)
previewCommit()

Choose a reason for hiding this comment

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

medium

Call updatePreviewCommit here instead of previewCommit to use the extracted function.

Suggested change
previewCommit()
updatePreviewCommit()

Comment on lines +120 to 142
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
}

Choose a reason for hiding this comment

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

medium

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
}

@github-actions
Copy link
Contributor

github-actions bot commented May 6, 2025

Qodana Community for JVM

1 new problem were found

Inspection name Severity Problems
Return or assignment can be lifted out ◽️ Notice 1

💡 Qodana analysis was run in the pull request mode: only the changed files were checked

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/qodana-action@v2025.1.1
        with:
          upload-result: true
Contact Qodana team

Contact us at qodana-support@jetbrains.com

@patou patou closed this Dec 10, 2025
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