Skip to content

Commit

Permalink
Merge branch 'release/0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
itishermann committed Jun 28, 2024
2 parents 12308c0 + 279d4ba commit 2d1c216
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = me.itishermann.ollamacommitsummarizer
pluginName = ollama-commit-summarizer
pluginRepositoryUrl = https://github.com/itishermann/ollama-commit-summarizer
# SemVer format -> https://semver.org
pluginVersion = 0.1.0
pluginVersion = 0.1.1

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 232
Expand All @@ -16,7 +16,7 @@ platformVersion = 2023.2.7

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins =
platformPlugins = Git4Idea

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 8.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package me.itishermann.ollamacommitsummarizer.actions
import com.github.difflib.DiffUtils
import com.github.difflib.UnifiedDiffUtils
import com.github.difflib.patch.Patch
import com.github.weisj.jsvg.e
import com.intellij.notification.Notification
import com.intellij.notification.NotificationType
import com.intellij.notification.Notifications
Expand All @@ -15,6 +14,7 @@ import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.vcs.CommitMessageI
import com.intellij.openapi.vcs.VcsDataKeys
import com.intellij.openapi.vcs.VcsException
Expand All @@ -27,9 +27,10 @@ import me.itishermann.ollamacommitsummarizer.exceptions.NoChangeToCommitExceptio
import me.itishermann.ollamacommitsummarizer.services.OllamaService
import me.itishermann.ollamacommitsummarizer.settings.OllamaSettingsState
import org.jetbrains.annotations.NotNull
import git4idea.repo.GitRepository
import git4idea.repo.GitRepositoryManager
import java.util.*


class GenerateCommitAction: AnAction(), DumbAware {
private var processing: Boolean = false

Expand All @@ -56,8 +57,9 @@ class GenerateCommitAction: AnAction(), DumbAware {
?: return
val includedChanges = abstractCommitWorkflowHandler.ui.getIncludedChanges()
val baseDir = project.basePath
val currentBranch = getCurrentBranchName(project)
try {
val prompt = buildPrompt(includedChanges, baseDir!!)
val prompt = buildPrompt(includedChanges, baseDir!!, currentBranch!!)
generateCommitMessage(prompt, commitPanel, indicator)
} catch (e: NoChangeToCommitException) {
processing = false
Expand Down Expand Up @@ -109,7 +111,7 @@ class GenerateCommitAction: AnAction(), DumbAware {
}
}

private fun buildPrompt(includedChanges: List<Change>, baseDir: String): String {
private fun buildPrompt(includedChanges: List<Change>, baseDir: String, branchName: String): String {
val totalUnifiedDiffs: MutableList<String> = ArrayList()
if(includedChanges.isEmpty()) {
processing = false
Expand Down Expand Up @@ -139,6 +141,7 @@ class GenerateCommitAction: AnAction(), DumbAware {
var prompt = OllamaSettingsState.instance.state.prompt ?: throw IllegalStateException("Prompt is null")
prompt = prompt.replace("{{gitDiff}}", java.lang.String.join("\n", totalUnifiedDiffs))
prompt = prompt.replace("{{fileCount}}", includedChanges.size.toString())
prompt = prompt.replace("{{branchName}}", branchName)
return prompt
}

Expand All @@ -152,4 +155,19 @@ class GenerateCommitAction: AnAction(), DumbAware {
}
return VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(e.dataContext)
}

fun getCurrentBranchName(project: Project): String? {

Check notice on line 159 in src/main/kotlin/me/itishermann/ollamacommitsummarizer/actions/GenerateCommitAction.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Function 'getCurrentBranchName' could be private
// Get the GitRepositoryManager for the project
val repositoryManager = GitRepositoryManager.getInstance(project)
// Get the list of repositories in the project
val repositories = repositoryManager.repositories
// If there are repositories available, get the current branch of the first repository
return if (repositories.isNotEmpty()) {
// TODO: Handle multiple repositoriess
val repository: GitRepository = repositories[0]
repository.currentBranch?.name
} else {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class OllamaSettingsComponent {
<ul>
<li>{{gitDiff}}: The git diff of the changes</li>
<li>{{fileCount}}: The number of files changed</li>
<li>{{branchName}}: The name of the current branch</li>
</ul>
""".trimIndent())
.createPanel()
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<vendor>itishermann</vendor>

<depends>com.intellij.modules.platform</depends>
<depends>Git4Idea</depends>

<extensions defaultExtensionNs="com.intellij">
<applicationConfigurable
Expand Down

0 comments on commit 2d1c216

Please sign in to comment.