11package com.github.blarc.ai.commits.intellij.plugin
22
33import com.github.blarc.ai.commits.intellij.plugin.AICommitsBundle.message
4+ import com.intellij.openapi.project.Project
45import com.intellij.openapi.ui.ValidationInfo
56import com.intellij.openapi.vcs.FilePath
67import com.intellij.openapi.vcs.changes.Change
78import com.intellij.ui.dsl.builder.Cell
89import com.intellij.ui.layout.ValidationInfoBuilder
910import com.intellij.util.ui.ColumnInfo
1011import com.intellij.util.ui.ComponentWithEmptyText
12+ import git4idea.repo.GitRepository
13+ import git4idea.repo.GitRepositoryManager
1114import javax.swing.JComponent
1215
13- fun <T , O > createColumn (name : String , formatter : (T ) -> O ) : ColumnInfo <T , O > {
16+ fun <T , O > createColumn (name : String , formatter : (T ) -> O ): ColumnInfo <T , O > {
1417 return object : ColumnInfo <T , O >(name) {
1518 override fun valueOf (item : T ): O {
1619 return formatter(item)
@@ -19,10 +22,10 @@ fun <T, O> createColumn(name: String, formatter: (T) -> O) : ColumnInfo<T, O> {
1922}
2023
2124fun ValidationInfoBuilder.notBlank (value : String ): ValidationInfo ? =
22- if (value.isBlank()) error(message(" validation.required" )) else null
25+ if (value.isBlank()) error(message(" validation.required" )) else null
2326
2427
25- fun ValidationInfoBuilder.temperatureValid (value : String ): ValidationInfo ? {
28+ fun ValidationInfoBuilder.temperatureValid (value : String ): ValidationInfo ? {
2629 if (value.isNotBlank()) {
2730 value.toFloatOrNull().let {
2831 if (it != null && it in 0.0 .. 2.0 ) {
@@ -34,10 +37,10 @@ fun ValidationInfoBuilder.temperatureValid(value: String): ValidationInfo? {
3437}
3538
3639fun ValidationInfoBuilder.unique (value : String , existingValues : Set <String >): ValidationInfo ? =
37- if (existingValues.contains(value)) error(message(" validation.unique" )) else null
40+ if (existingValues.contains(value)) error(message(" validation.unique" )) else null
3841
3942fun ValidationInfoBuilder.isInt (value : String ): ValidationInfo ? {
40- if (value.isBlank()){
43+ if (value.isBlank()) {
4144 return null
4245 }
4346
@@ -51,7 +54,7 @@ fun ValidationInfoBuilder.isInt(value: String): ValidationInfo? {
5154}
5255
5356fun ValidationInfoBuilder.isFloat (value : String ): ValidationInfo ? {
54- if (value.isBlank()){
57+ if (value.isBlank()) {
5558 return null
5659 }
5760
@@ -65,7 +68,7 @@ fun ValidationInfoBuilder.isFloat(value: String): ValidationInfo? {
6568}
6669
6770fun ValidationInfoBuilder.isDouble (value : String ): ValidationInfo ? {
68- if (value.isBlank()){
71+ if (value.isBlank()) {
6972 return null
7073 }
7174
@@ -79,7 +82,7 @@ fun ValidationInfoBuilder.isDouble(value: String): ValidationInfo? {
7982}
8083
8184// Adds emptyText method to all cells that contain a component that implements ComponentWithEmptyText class
82- fun <T >Cell<T>.emptyText (emptyText : String ) : Cell <T > where T : JComponent , T : ComponentWithEmptyText {
85+ fun <T > Cell<T>.emptyText (emptyText : String ): Cell <T > where T : JComponent , T : ComponentWithEmptyText {
8386 this .component.emptyText.text = emptyText
8487 return this
8588}
@@ -105,3 +108,19 @@ fun String.wrap(length: Int): String {
105108fun Change.filePath (): FilePath ? {
106109 return afterRevision?.file ? : beforeRevision?.file
107110}
111+
112+ fun Change.isSubmoduleChange (project : Project ): Boolean {
113+ val repositoryManager = GitRepositoryManager .getInstance(project)
114+
115+ val virtualFile = this .virtualFile ? : return false
116+ val fileRepositoryUrl = repositoryManager.getRepositoryForFileQuick(virtualFile)
117+ ?.remotes
118+ ?.firstOrNull()
119+ ?.firstUrl ? : return false
120+
121+ return repositoryManager.repositories
122+ .flatMap(GitRepository ::getSubmodules)
123+ .map { it.url }
124+ .any { it == fileRepositoryUrl }
125+ }
126+
0 commit comments