@@ -21,6 +21,7 @@ import com.intellij.ui.ScrollPaneFactory
21
21
import com.intellij.ui.SimpleListCellRenderer
22
22
import com.intellij.ui.components.JBCheckBox
23
23
import com.intellij.ui.components.JBLoadingPanel
24
+ import com.intellij.ui.components.JBRadioButton
24
25
import com.intellij.ui.components.JBTextField
25
26
import com.intellij.ui.components.panels.Wrapper
26
27
import com.intellij.ui.dsl.builder.BottomGap
@@ -53,6 +54,7 @@ import software.aws.toolkits.core.utils.getLogger
53
54
import software.aws.toolkits.core.utils.tryOrNull
54
55
import software.aws.toolkits.jetbrains.AwsToolkit
55
56
import software.aws.toolkits.jetbrains.core.AwsClientManager
57
+ import software.aws.toolkits.jetbrains.core.AwsResourceCache
56
58
import software.aws.toolkits.jetbrains.core.awsClient
57
59
import software.aws.toolkits.jetbrains.core.credentials.sono.lazilyGetUserId
58
60
import software.aws.toolkits.jetbrains.core.utils.buildMap
@@ -61,8 +63,10 @@ import software.aws.toolkits.jetbrains.gateway.connection.extractRepoName
61
63
import software.aws.toolkits.jetbrains.gateway.connection.normalizeRepoUrl
62
64
import software.aws.toolkits.jetbrains.gateway.welcomescreen.recursivelySetBackground
63
65
import software.aws.toolkits.jetbrains.gateway.welcomescreen.setDefaultBackgroundAndBorder
66
+ import software.aws.toolkits.jetbrains.services.caws.CawsCodeRepository
64
67
import software.aws.toolkits.jetbrains.services.caws.CawsEndpoints
65
68
import software.aws.toolkits.jetbrains.services.caws.CawsProject
69
+ import software.aws.toolkits.jetbrains.services.caws.CawsResources
66
70
import software.aws.toolkits.jetbrains.services.caws.InactivityTimeout
67
71
import software.aws.toolkits.jetbrains.services.caws.isSubscriptionFreeTier
68
72
import software.aws.toolkits.jetbrains.services.caws.isSupportedInFreeTier
@@ -105,7 +109,8 @@ class CawsSettings(
105
109
106
110
// intermediate values
107
111
var connectionSettings : ClientConnectionSettings <* >? = null ,
108
- var branchCloneType : BranchCloneType = BranchCloneType .EXISTING
112
+ var branchCloneType : BranchCloneType = BranchCloneType .EXISTING ,
113
+ var is3P : Boolean = false
109
114
)
110
115
111
116
fun cawsWizard (lifetime : Lifetime , settings : CawsSettings = CawsSettings ()) = MultistagePanelContainer (
@@ -136,6 +141,10 @@ fun cawsWizard(lifetime: Lifetime, settings: CawsSettings = CawsSettings()) = Mu
136
141
error(" Not implemented" )
137
142
}
138
143
144
+ if (context.is3P) {
145
+ context.branchCloneType = BranchCloneType .EXISTING
146
+ }
147
+
139
148
if (context.branchCloneType == BranchCloneType .NEW_FROM_EXISTING ) {
140
149
withTextAboveProgressBar(message(" caws.creating_branch" )) {
141
150
cawsClient.createSourceRepositoryBranch {
@@ -334,27 +343,32 @@ class EnvironmentDetailsPanel(private val context: CawsSettings, lifetime: Lifet
334
343
335
344
row {
336
345
label(message(" caws.workspace.details.branch_title" ))
337
- .comment(message(" caws.workspace.details.create_branch_comment" ))
338
346
}
339
347
348
+ row { comment(message(" caws.workspace.details.create_branch_comment" )) }
349
+
350
+ lateinit var branchOptions: Row
351
+ lateinit var newBranchOption: Cell <JBRadioButton >
340
352
lateinit var newBranch: Row
341
353
buttonsGroup {
342
- row {
343
- radioButton(message(" caws.workspace.details.branch_new" ), BranchCloneType .NEW_FROM_EXISTING ).applyToComponent {
344
- isSelected = context.branchCloneType == BranchCloneType .NEW_FROM_EXISTING
345
- }.bindSelected(
346
- { context.branchCloneType == BranchCloneType .NEW_FROM_EXISTING },
347
- { if (it) context.branchCloneType = BranchCloneType .NEW_FROM_EXISTING }
348
- ).actionListener { event, component ->
349
- newBranch.visibleIf(component.selected)
350
- }
354
+ branchOptions = row {
355
+ newBranchOption = radioButton(message(" caws.workspace.details.branch_new" ), BranchCloneType .NEW_FROM_EXISTING )
356
+ .applyToComponent {
357
+ isSelected = context.branchCloneType == BranchCloneType .NEW_FROM_EXISTING
358
+ }.bindSelected(
359
+ { context.branchCloneType == BranchCloneType .NEW_FROM_EXISTING },
360
+ { if (it) context.branchCloneType = BranchCloneType .NEW_FROM_EXISTING }
361
+ ).actionListener { event, component ->
362
+ newBranch.visibleIf(component.selected)
363
+ }
351
364
352
- radioButton(message(" caws.workspace.details.branch_existing" ), BranchCloneType .EXISTING ).applyToComponent {
353
- isSelected = context.branchCloneType == BranchCloneType .EXISTING
354
- }.bindSelected(
355
- { context.branchCloneType == BranchCloneType .EXISTING },
356
- { if (it) context.branchCloneType = BranchCloneType .EXISTING }
357
- )
365
+ radioButton(message(" caws.workspace.details.branch_existing" ), BranchCloneType .EXISTING )
366
+ .applyToComponent {
367
+ isSelected = context.branchCloneType == BranchCloneType .EXISTING
368
+ }.bindSelected(
369
+ { context.branchCloneType == BranchCloneType .EXISTING },
370
+ { if (it) context.branchCloneType = BranchCloneType .EXISTING }
371
+ )
358
372
}
359
373
}.bind({ context.branchCloneType }, { context.branchCloneType = it })
360
374
@@ -377,6 +391,16 @@ class EnvironmentDetailsPanel(private val context: CawsSettings, lifetime: Lifet
377
391
linkedBranchCombo.proposeModelUpdate { model ->
378
392
projectCombo.selected()?.let { project ->
379
393
linkedRepoCombo.selected()?.let { repo ->
394
+ context.is3P = isRepo3P(project, repo.name)
395
+ if (context.is3P) {
396
+ branchOptions.visible(false )
397
+ newBranch.visible(false )
398
+ } else {
399
+ branchOptions.visible(true )
400
+ if (newBranchOption.component.isSelected) {
401
+ newBranch.visible(true )
402
+ }
403
+ }
380
404
val branches = getBranchNames(project, repo.name, client)
381
405
branches.forEach { model.addElement(it) }
382
406
}
@@ -559,6 +583,14 @@ class EnvironmentDetailsPanel(private val context: CawsSettings, lifetime: Lifet
559
583
.map { it.toSourceRepository() }
560
584
.sortedBy { it.name }
561
585
586
+ private fun isRepo3P (project : CawsProject , repo : String ): Boolean {
587
+ val connectionSettings = context.connectionSettings ? : throw RuntimeException (" ConnectionSettings was not set" )
588
+ val url = AwsResourceCache .getInstance().getResource(
589
+ CawsResources .cloneUrls(CawsCodeRepository (project.space, project.project, repo)), connectionSettings
590
+ ).toCompletableFuture().get()
591
+ return ! url.contains(CawsEndpoints .CAWS_GIT_PATTERN )
592
+ }
593
+
562
594
private fun getBranchNames (project : CawsProject , repo : String , client : CodeCatalystClient ) =
563
595
client.listSourceRepositoryBranchesPaginator {
564
596
it.spaceName(project.space)
0 commit comments