File tree Expand file tree Collapse file tree 6 files changed +63
-1
lines changed
223/main/resources/META-INF
233/main/resources/META-INF
main/kotlin/cc/unitmesh/devti
exts/ext-git/src/main/kotlin/cc/unitmesh/git/actions/vcs Expand file tree Collapse file tree 6 files changed +63
-1
lines changed Original file line number Diff line number Diff line change 258
258
<toolchainFunctionProvider implementation =" cc.unitmesh.devti.bridge.archview.ComponentViewFunctionProvider" />
259
259
<toolchainFunctionProvider implementation =" cc.unitmesh.devti.bridge.archview.ContainerViewFunctionProvider" />
260
260
<toolchainFunctionProvider implementation =" cc.unitmesh.devti.bridge.assessment.SccFunctionProvider" />
261
+ <toolchainFunctionProvider implementation =" cc.unitmesh.devti.bridge.knowledge.HistoryFunctionProvider" />
261
262
</extensions >
262
263
263
264
<actions >
Original file line number Diff line number Diff line change 258
258
<toolchainFunctionProvider implementation =" cc.unitmesh.devti.bridge.archview.ComponentViewFunctionProvider" />
259
259
<toolchainFunctionProvider implementation =" cc.unitmesh.devti.bridge.archview.ContainerViewFunctionProvider" />
260
260
<toolchainFunctionProvider implementation =" cc.unitmesh.devti.bridge.assessment.SccFunctionProvider" />
261
+ <toolchainFunctionProvider implementation =" cc.unitmesh.devti.bridge.knowledge.HistoryFunctionProvider" />
261
262
</extensions >
262
263
263
264
<actions >
Original file line number Diff line number Diff line change @@ -164,5 +164,5 @@ sealed class Containerization(override val name: String) : BridgeCommandProvider
164
164
*/
165
165
sealed class KnowledgeTransfer (override val name : String ) : BridgeCommandProvider {
166
166
object Knowledge : KnowledgeTransfer(" /knowledge" )
167
- object History : KnowledgeTransfer(" / history" )
167
+ object History : KnowledgeTransfer(" history" )
168
168
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package cc.unitmesh.devti.provider
3
3
import com.intellij.codeInsight.completion.CompletionResultSet
4
4
import com.intellij.openapi.extensions.ExtensionPointName
5
5
import com.intellij.openapi.project.Project
6
+ import com.intellij.openapi.vfs.VirtualFile
6
7
import com.intellij.psi.PsiElement
7
8
8
9
interface RevisionProvider {
@@ -22,6 +23,11 @@ interface RevisionProvider {
22
23
23
24
fun countHistoryChange (project : Project , element : PsiElement ): Int
24
25
26
+ /* *
27
+ * Summary changes of one file
28
+ */
29
+ fun history (project : Project , file : VirtualFile ): String
30
+
25
31
companion object {
26
32
private val EP_NAME : ExtensionPointName <RevisionProvider > =
27
33
ExtensionPointName (" cc.unitmesh.revisionProvider" )
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import com.intellij.openapi.vcs.changes.Change
17
17
import com.intellij.openapi.vcs.changes.ChangeListManager
18
18
import com.intellij.openapi.vcs.changes.CommitContext
19
19
import com.intellij.openapi.vcs.changes.LocalChangeList
20
+ import com.intellij.openapi.vfs.VirtualFile
20
21
import com.intellij.psi.PsiElement
21
22
import com.intellij.vcs.commit.ChangeListCommitState
22
23
import com.intellij.vcs.commit.LocalChangesCommitter
@@ -122,4 +123,24 @@ class GitRevisionProvider : RevisionProvider {
122
123
0
123
124
}
124
125
}
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
+ }
125
146
}
You can’t perform that action at this time.
0 commit comments