Skip to content

Commit 97bfac8

Browse files
committed
feat(knowledge): add history function provider for knowledge transfer
Introduce `HistoryFunctionProvider` to handle history-related operations for knowledge transfer. This includes file history retrieval and integration with the toolchain function provider system. Additionally, rename `BridgeCommandProvider` to `Bridge` for clarity.
1 parent cd724e3 commit 97bfac8

File tree

6 files changed

+63
-1
lines changed

6 files changed

+63
-1
lines changed

core/src/223/main/resources/META-INF/autodev-core.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@
258258
<toolchainFunctionProvider implementation="cc.unitmesh.devti.bridge.archview.ComponentViewFunctionProvider"/>
259259
<toolchainFunctionProvider implementation="cc.unitmesh.devti.bridge.archview.ContainerViewFunctionProvider"/>
260260
<toolchainFunctionProvider implementation="cc.unitmesh.devti.bridge.assessment.SccFunctionProvider"/>
261+
<toolchainFunctionProvider implementation="cc.unitmesh.devti.bridge.knowledge.HistoryFunctionProvider"/>
261262
</extensions>
262263

263264
<actions>

core/src/233/main/resources/META-INF/autodev-core.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@
258258
<toolchainFunctionProvider implementation="cc.unitmesh.devti.bridge.archview.ComponentViewFunctionProvider"/>
259259
<toolchainFunctionProvider implementation="cc.unitmesh.devti.bridge.archview.ContainerViewFunctionProvider"/>
260260
<toolchainFunctionProvider implementation="cc.unitmesh.devti.bridge.assessment.SccFunctionProvider"/>
261+
<toolchainFunctionProvider implementation="cc.unitmesh.devti.bridge.knowledge.HistoryFunctionProvider"/>
261262
</extensions>
262263

263264
<actions>

core/src/main/kotlin/cc/unitmesh/devti/bridge/BridgeCommandProvider.kt renamed to core/src/main/kotlin/cc/unitmesh/devti/bridge/Bridge.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,5 @@ sealed class Containerization(override val name: String) : BridgeCommandProvider
164164
*/
165165
sealed class KnowledgeTransfer(override val name: String) : BridgeCommandProvider {
166166
object Knowledge : KnowledgeTransfer("/knowledge")
167-
object History : KnowledgeTransfer("/history")
167+
object History : KnowledgeTransfer("history")
168168
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cc.unitmesh.devti.bridge.knowledge
2+
3+
import cc.unitmesh.devti.bridge.Assessment
4+
import cc.unitmesh.devti.bridge.KnowledgeTransfer
5+
import cc.unitmesh.devti.provider.RevisionProvider
6+
import cc.unitmesh.devti.provider.toolchain.ToolchainFunctionProvider
7+
import com.intellij.openapi.project.Project
8+
import com.intellij.openapi.project.guessProjectDir
9+
import com.intellij.openapi.vfs.VirtualFile
10+
import com.intellij.openapi.vfs.VirtualFileManager
11+
12+
class HistoryFunctionProvider : ToolchainFunctionProvider {
13+
override fun isApplicable(project: Project, funcName: String): Boolean = funcName == KnowledgeTransfer.History.name
14+
15+
override fun execute(
16+
project: Project,
17+
prop: String,
18+
args: List<Any>,
19+
allVariables: Map<String, Any?>
20+
): Any {
21+
val path = project.lookupFile(prop) ?: return "File not found"
22+
return RevisionProvider.provide()?.let {
23+
val changes = it.history(project, path)
24+
return changes ?: "No changes found for history provider"
25+
} ?: "No history provider found"
26+
}
27+
}
28+
29+
fun Project.lookupFile(path: String): VirtualFile? {
30+
val projectPath = this.guessProjectDir()?.toNioPath()
31+
val realpath = projectPath?.resolve(path)
32+
return VirtualFileManager.getInstance().findFileByUrl("file://${realpath?.toAbsolutePath()}")
33+
}

core/src/main/kotlin/cc/unitmesh/devti/provider/RevisionProvider.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cc.unitmesh.devti.provider
33
import com.intellij.codeInsight.completion.CompletionResultSet
44
import com.intellij.openapi.extensions.ExtensionPointName
55
import com.intellij.openapi.project.Project
6+
import com.intellij.openapi.vfs.VirtualFile
67
import com.intellij.psi.PsiElement
78

89
interface RevisionProvider {
@@ -22,6 +23,11 @@ interface RevisionProvider {
2223

2324
fun countHistoryChange(project: Project, element: PsiElement): Int
2425

26+
/**
27+
* Summary changes of one file
28+
*/
29+
fun history(project: Project, file: VirtualFile): String
30+
2531
companion object {
2632
private val EP_NAME: ExtensionPointName<RevisionProvider> =
2733
ExtensionPointName("cc.unitmesh.revisionProvider")

exts/ext-git/src/main/kotlin/cc/unitmesh/git/actions/vcs/GitRevisionProvider.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.intellij.openapi.vcs.changes.Change
1717
import com.intellij.openapi.vcs.changes.ChangeListManager
1818
import com.intellij.openapi.vcs.changes.CommitContext
1919
import com.intellij.openapi.vcs.changes.LocalChangeList
20+
import com.intellij.openapi.vfs.VirtualFile
2021
import com.intellij.psi.PsiElement
2122
import com.intellij.vcs.commit.ChangeListCommitState
2223
import com.intellij.vcs.commit.LocalChangesCommitter
@@ -122,4 +123,24 @@ class GitRevisionProvider : RevisionProvider {
122123
0
123124
}
124125
}
126+
127+
/**
128+
* Summary changes of one file, output format:
129+
* ```
130+
* filename: xxx
131+
* changes: $changeout
132+
* historyCommits: $historyCommitMessages
133+
* ```
134+
*/
135+
override fun history(project: Project, file: VirtualFile): String {
136+
val filePath: FilePath = VcsUtil.getFilePath(file)
137+
val history = GitFileHistory.collectHistory(project, filePath)
138+
val historyCommitMessages = history.joinToString("\n") { it.commitMessage.toString() }
139+
140+
return """
141+
|filename: ${file.name}
142+
|changes: ${history.size}
143+
|historyCommits: $historyCommitMessages
144+
""".trimMargin()
145+
}
125146
}

0 commit comments

Comments
 (0)