Skip to content

Commit

Permalink
feat(review): remove unused methods and refactor computeDiff
Browse files Browse the repository at this point in the history
This commit removes the unused methods `computeDiff` and `singleCommitCalculateDiff` from the `VcsPrompting` class. It also refactors the `computeDiff` method to remove unnecessary code and improve readability.
  • Loading branch information
phodal committed Jan 11, 2024
1 parent d49f41f commit 5c59c2e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 68 deletions.
Expand Up @@ -66,7 +66,7 @@ open class CodeReviewAction : ChatBaseAction() {
doReviewWithChanges(project, details, selectList, stories)
}

fun doReviewWithChanges(
open fun doReviewWithChanges(
project: Project,
details: List<VcsFullCommitDetails>,
selectList: Array<out Change>,
Expand Down
67 changes: 0 additions & 67 deletions src/main/kotlin/cc/unitmesh/devti/prompting/VcsPrompting.kt
Expand Up @@ -139,73 +139,6 @@ class VcsPrompting(private val project: Project) {
return writer.toString()
}

fun computeDiff(includedChanges: List<Change>): String {
val changesByRepository = includedChanges
.mapNotNull { change ->
change.virtualFile?.let { file ->
gitRepositoryManager.getRepositoryForFileQuick(
file
) to change
}
}
.groupBy({ it.first }, { it.second })

return changesByRepository
.map { (repository, changes) ->
repository?.let {
val filePatches = IdeaTextPatchBuilder.buildPatch(
project,
changes,
repository.root.toNioPath(), false, true
)

val stringWriter = StringWriter()
stringWriter.write("Repository: ${repository.root.path}\n")
UnifiedDiffWriter.write(project, filePatches, stringWriter, "\n", null)
stringWriter.toString()
}
}
.joinToString("\n")
}

@Throws(VcsException::class, IOException::class)
fun singleCommitCalculateDiff(list: List<VcsFullCommitDetails>, project: Project): Pair<List<String>, String> {
val writer = StringWriter()
val summary: MutableList<String> = ArrayList()
for (detail in list) {
writer.write(
"""
Message: ${detail.fullMessage}
Changes:
""".trimIndent()
)
val subject = detail.subject
summary.add('"'.toString() + subject + "\"")
val filteredChanges = detail.changes.stream()
.filter { change: Change? ->
!isBinaryOrTooLarge(change!!)
}
.collect(Collectors.toList())

val shortChange = filteredChanges.subList(0, min(filteredChanges.size, 500))
val patches = IdeaTextPatchBuilder.buildPatch(
project,
shortChange,
Path.of(project.basePath!!),
false,
true
)
UnifiedDiffWriter.write(
project, project.stateStore.projectBasePath, patches, writer, "\n", null, emptyList()
)
}
val stringWriter = writer.toString()
val diff = trimDiff(stringWriter)
return Pair<List<String>, String>(summary, diff)
}

private val revisionRegex = Regex("\\(revision [^)]+\\)")
private val lineTip = "\\ No newline at end of file"

Expand Down

0 comments on commit 5c59c2e

Please sign in to comment.