@@ -21,6 +21,7 @@ import com.intellij.ui.ScrollPaneFactory
2121import com.intellij.ui.SimpleListCellRenderer
2222import com.intellij.ui.components.JBCheckBox
2323import com.intellij.ui.components.JBLoadingPanel
24+ import com.intellij.ui.components.JBRadioButton
2425import com.intellij.ui.components.JBTextField
2526import com.intellij.ui.components.panels.Wrapper
2627import com.intellij.ui.dsl.builder.BottomGap
@@ -53,6 +54,7 @@ import software.aws.toolkits.core.utils.getLogger
5354import software.aws.toolkits.core.utils.tryOrNull
5455import software.aws.toolkits.jetbrains.AwsToolkit
5556import software.aws.toolkits.jetbrains.core.AwsClientManager
57+ import software.aws.toolkits.jetbrains.core.AwsResourceCache
5658import software.aws.toolkits.jetbrains.core.awsClient
5759import software.aws.toolkits.jetbrains.core.credentials.sono.lazilyGetUserId
5860import software.aws.toolkits.jetbrains.core.utils.buildMap
@@ -61,8 +63,10 @@ import software.aws.toolkits.jetbrains.gateway.connection.extractRepoName
6163import software.aws.toolkits.jetbrains.gateway.connection.normalizeRepoUrl
6264import software.aws.toolkits.jetbrains.gateway.welcomescreen.recursivelySetBackground
6365import software.aws.toolkits.jetbrains.gateway.welcomescreen.setDefaultBackgroundAndBorder
66+ import software.aws.toolkits.jetbrains.services.caws.CawsCodeRepository
6467import software.aws.toolkits.jetbrains.services.caws.CawsEndpoints
6568import software.aws.toolkits.jetbrains.services.caws.CawsProject
69+ import software.aws.toolkits.jetbrains.services.caws.CawsResources
6670import software.aws.toolkits.jetbrains.services.caws.InactivityTimeout
6771import software.aws.toolkits.jetbrains.services.caws.isSubscriptionFreeTier
6872import software.aws.toolkits.jetbrains.services.caws.isSupportedInFreeTier
@@ -105,7 +109,8 @@ class CawsSettings(
105109
106110 // intermediate values
107111 var connectionSettings : ClientConnectionSettings <* >? = null ,
108- var branchCloneType : BranchCloneType = BranchCloneType .EXISTING
112+ var branchCloneType : BranchCloneType = BranchCloneType .EXISTING ,
113+ var is3P : Boolean = false
109114)
110115
111116fun cawsWizard (lifetime : Lifetime , settings : CawsSettings = CawsSettings ()) = MultistagePanelContainer (
@@ -136,6 +141,10 @@ fun cawsWizard(lifetime: Lifetime, settings: CawsSettings = CawsSettings()) = Mu
136141 error(" Not implemented" )
137142 }
138143
144+ if (context.is3P) {
145+ context.branchCloneType = BranchCloneType .EXISTING
146+ }
147+
139148 if (context.branchCloneType == BranchCloneType .NEW_FROM_EXISTING ) {
140149 withTextAboveProgressBar(message(" caws.creating_branch" )) {
141150 cawsClient.createSourceRepositoryBranch {
@@ -334,27 +343,32 @@ class EnvironmentDetailsPanel(private val context: CawsSettings, lifetime: Lifet
334343
335344 row {
336345 label(message(" caws.workspace.details.branch_title" ))
337- .comment(message(" caws.workspace.details.create_branch_comment" ))
338346 }
339347
348+ row { comment(message(" caws.workspace.details.create_branch_comment" )) }
349+
350+ lateinit var branchOptions: Row
351+ lateinit var newBranchOption: Cell <JBRadioButton >
340352 lateinit var newBranch: Row
341353 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+ }
351364
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+ )
358372 }
359373 }.bind({ context.branchCloneType }, { context.branchCloneType = it })
360374
@@ -377,6 +391,16 @@ class EnvironmentDetailsPanel(private val context: CawsSettings, lifetime: Lifet
377391 linkedBranchCombo.proposeModelUpdate { model ->
378392 projectCombo.selected()?.let { project ->
379393 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+ }
380404 val branches = getBranchNames(project, repo.name, client)
381405 branches.forEach { model.addElement(it) }
382406 }
@@ -559,6 +583,14 @@ class EnvironmentDetailsPanel(private val context: CawsSettings, lifetime: Lifet
559583 .map { it.toSourceRepository() }
560584 .sortedBy { it.name }
561585
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+
562594 private fun getBranchNames (project : CawsProject , repo : String , client : CodeCatalystClient ) =
563595 client.listSourceRepositoryBranchesPaginator {
564596 it.spaceName(project.space)
0 commit comments