Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Commit 0b56cf0

Browse files
Bugfix/stack url dialog (#18)
* fix: added url validation and changed import stack screen interaction Signed-off-by: Adroaldo Neto <adroaldo.neto@zup.com.br> * fix: fixed handling for invalid url Signed-off-by: Adroaldo Neto <adroaldo.neto@zup.com.br> Signed-off-by: Adroaldo Neto <adroaldo.neto@zup.com.br>
1 parent 51aeddb commit 0b56cf0

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

src/main/kotlin/com/stackspot/intellij/actions/ImportStackAction.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import com.intellij.openapi.project.DumbAware
2222
import com.intellij.openapi.ui.Messages
2323
import com.stackspot.intellij.commands.listeners.NotifyStacksUpdatedCommandListener
2424
import com.stackspot.intellij.commands.stk.ImportStack
25+
import com.stackspot.intellij.commons.ErrorDialog
26+
import com.stackspot.intellij.commons.InputDialog.REPOSITORY_URL
27+
import com.stackspot.intellij.commons.isUrlValid
2528
import com.stackspot.intellij.ui.Icons
2629
import com.stackspot.intellij.ui.StackSpotTerminalRunner
2730

@@ -30,14 +33,20 @@ const val IMPORT_STACK = "Import Stack"
3033

3134
class ImportStackAction : AnAction(IMPORT_STACK, IMPORT_STACK, Icons.IMPORT_STACK), DumbAware {
3235
override fun actionPerformed(e: AnActionEvent) {
33-
val stackUrl = askForStackUrl()
36+
val stackUrl = askForStackUrl() ?: return
37+
38+
if (!stackUrl.isUrlValid()) {
39+
Messages.showErrorDialog(ErrorDialog.URL_IS_NOT_VALID_MESSAGE, ErrorDialog.URL_IS_NOT_VALID_TITLE)
40+
return
41+
}
42+
3443
val project = e.project
35-
if (stackUrl != null && project != null) {
44+
if (project != null) {
3645
ImportStack(stackUrl, StackSpotTerminalRunner(project)).run(NotifyStacksUpdatedCommandListener())
3746
}
3847
}
3948

4049
private fun askForStackUrl(): String? {
41-
return Messages.showInputDialog("Enter Stack GIT URL To Import", IMPORT_STACK, Messages.getQuestionIcon())
50+
return Messages.showInputDialog(REPOSITORY_URL, IMPORT_STACK, Messages.getQuestionIcon())
4251
}
4352
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.stackspot.intellij.commons
2+
3+
object InputDialog {
4+
const val REPOSITORY_URL = "Insert a stack repository URL"
5+
}
6+
7+
object ErrorDialog {
8+
const val URL_IS_NOT_VALID_MESSAGE = "Requested URL is not valid"
9+
const val URL_IS_NOT_VALID_TITLE = "Invalid URL"
10+
}
11+
12+
fun String?.isUrlValid(): Boolean {
13+
val regex = """((git|ssh|https)|(git@[\w\.]+))(:(//)?)([\w\.@\:/\-~]+)(/)?""".toRegex()
14+
return (this?.isNotEmpty() == true) && regex.matches(this)
15+
}

src/main/kotlin/com/stackspot/intellij/ui/project_wizard/panels/StackSpotNoStackfilesErrorPanel.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import com.stackspot.intellij.actions.IMPORT_STACK
2424
import com.stackspot.intellij.commands.BackgroundCommandRunner
2525
import com.stackspot.intellij.commands.listeners.NotifyProjectWizardImportedStack
2626
import com.stackspot.intellij.commands.stk.ImportStack
27+
import com.stackspot.intellij.commons.ErrorDialog.URL_IS_NOT_VALID_MESSAGE
28+
import com.stackspot.intellij.commons.ErrorDialog.URL_IS_NOT_VALID_TITLE
29+
import com.stackspot.intellij.commons.InputDialog.REPOSITORY_URL
30+
import com.stackspot.intellij.commons.isUrlValid
2731
import java.util.concurrent.Executors
2832
import javax.swing.JComponent
2933

@@ -57,20 +61,25 @@ class StackSpotNoStackfilesErrorPanel(val parentPanel: StackSpotParentPanel) {
5761
}
5862

5963
private fun askForStackUrl(): String? {
60-
return Messages.showInputDialog("Enter Stack GIT URL To Import", IMPORT_STACK, Messages.getQuestionIcon())
64+
return Messages.showInputDialog(REPOSITORY_URL, IMPORT_STACK, Messages.getQuestionIcon())
6165
}
6266

6367
private fun runImportStack() {
64-
val url = askForStackUrl()
68+
val url = askForStackUrl() ?: return
69+
70+
if (!url.isUrlValid()) {
71+
Messages.showErrorDialog(URL_IS_NOT_VALID_MESSAGE, URL_IS_NOT_VALID_TITLE)
72+
return
73+
}
74+
6575
parentPanel.showImportingStack()
76+
6677
val executor = Executors.newSingleThreadExecutor()
6778
executor.submit {
68-
if (!url.isNullOrEmpty()) {
6979
ImportStack(url, BackgroundCommandRunner(Constants.Paths.STK_HOME.toString()))
7080
.run(NotifyProjectWizardImportedStack(parentPanel))
71-
}
7281
}
7382
executor.shutdown()
7483
}
7584

76-
}
85+
}

0 commit comments

Comments
 (0)