Skip to content

Commit 2dbdf93

Browse files
authored
chore: default to bolt-install experiment behavior for app selection (#162)
1 parent c186ffc commit 2dbdf93

File tree

2 files changed

+46
-77
lines changed

2 files changed

+46
-77
lines changed

internal/prompts/app_select.go

Lines changed: 43 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424

2525
"github.com/slackapi/slack-cli/internal/api"
2626
"github.com/slackapi/slack-cli/internal/cmdutil"
27-
"github.com/slackapi/slack-cli/internal/config"
28-
"github.com/slackapi/slack-cli/internal/experiment"
2927
"github.com/slackapi/slack-cli/internal/iostreams"
3028
authpkg "github.com/slackapi/slack-cli/internal/pkg/auth"
3129
"github.com/slackapi/slack-cli/internal/shared"
@@ -476,10 +474,6 @@ func AppSelectPrompt(
476474
filtered[id] = app
477475
}
478476
}
479-
manifestSource, err := clients.Config.ProjectConfig.GetManifestSource(ctx)
480-
if err != nil {
481-
return SelectedApp{}, err
482-
}
483477
type Selection struct {
484478
app SelectedApp
485479
label string
@@ -524,58 +518,54 @@ func AppSelectPrompt(
524518
return SelectedApp{}, slackerror.New(slackerror.ErrInstallationRequired)
525519
}
526520
case ShowAllApps, ShowInstalledAndNewApps:
527-
isManifestSourceLocal := manifestSource.Equals(config.ManifestSourceLocal)
528-
isBoltInstallEnabled := clients.Config.WithExperimentOn(experiment.BoltInstall)
529-
if isManifestSourceLocal || isBoltInstallEnabled {
530-
option := Selection{
531-
label: style.Secondary("Create a new app"),
532-
}
533-
options = append(options, option)
534-
switch {
535-
case types.IsAppID(clients.Config.AppFlag):
536-
// Skip to match the app ID later
537-
case teamFlag != "":
538-
// Check for an existing app ID
539-
selections := []SelectedApp{}
540-
for _, app := range filtered {
541-
switch teamFlag {
542-
case app.App.TeamID, app.App.TeamDomain:
543-
switch {
544-
case environment.Equals(ShowAllEnvironments):
545-
selections = append(selections, app)
546-
case environment.Equals(ShowHostedOnly) && !app.App.IsDev:
547-
selections = append(selections, app)
548-
case environment.Equals(ShowLocalOnly) && app.App.IsDev:
549-
selections = append(selections, app)
550-
}
521+
option := Selection{
522+
label: style.Secondary("Create a new app"),
523+
}
524+
options = append(options, option)
525+
switch {
526+
case types.IsAppID(clients.Config.AppFlag):
527+
// Skip to match the app ID later
528+
case teamFlag != "":
529+
// Check for an existing app ID
530+
selections := []SelectedApp{}
531+
for _, app := range filtered {
532+
switch teamFlag {
533+
case app.App.TeamID, app.App.TeamDomain:
534+
switch {
535+
case environment.Equals(ShowAllEnvironments):
536+
selections = append(selections, app)
537+
case environment.Equals(ShowHostedOnly) && !app.App.IsDev:
538+
selections = append(selections, app)
539+
case environment.Equals(ShowLocalOnly) && app.App.IsDev:
540+
selections = append(selections, app)
551541
}
552542
}
553-
switch len(selections) {
554-
case 0:
555-
// Skip to create a new app
556-
case 1:
557-
return selections[0], nil
558-
default:
559-
return SelectedApp{}, slackerror.New(slackerror.ErrAppFound).
560-
WithMessage("Multiple apps exist for the provided team")
561-
}
562-
// Create a new app if none exists
563-
auths, err := getAuths(ctx, clients)
564-
if err != nil {
565-
return SelectedApp{}, err
566-
}
567-
for _, auth := range auths {
568-
switch teamFlag {
569-
case auth.TeamID, auth.TeamDomain:
570-
app := SelectedApp{
571-
App: types.NewApp(),
572-
Auth: auth,
573-
}
574-
return app, nil
543+
}
544+
switch len(selections) {
545+
case 0:
546+
// Skip to create a new app
547+
case 1:
548+
return selections[0], nil
549+
default:
550+
return SelectedApp{}, slackerror.New(slackerror.ErrAppFound).
551+
WithMessage("Multiple apps exist for the provided team")
552+
}
553+
// Create a new app if none exists
554+
auths, err := getAuths(ctx, clients)
555+
if err != nil {
556+
return SelectedApp{}, err
557+
}
558+
for _, auth := range auths {
559+
switch teamFlag {
560+
case auth.TeamID, auth.TeamDomain:
561+
app := SelectedApp{
562+
App: types.NewApp(),
563+
Auth: auth,
575564
}
565+
return app, nil
576566
}
577-
return SelectedApp{}, slackerror.New(slackerror.ErrTeamNotFound)
578567
}
568+
return SelectedApp{}, slackerror.New(slackerror.ErrTeamNotFound)
579569
}
580570
}
581571
labels := []string{}

internal/prompts/app_select_test.go

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"time"
2121

2222
"github.com/slackapi/slack-cli/internal/api"
23-
"github.com/slackapi/slack-cli/internal/config"
2423
"github.com/slackapi/slack-cli/internal/hooks"
2524
"github.com/slackapi/slack-cli/internal/iostreams"
2625
"github.com/slackapi/slack-cli/internal/shared"
@@ -655,7 +654,6 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
655654
mockFlagApp string
656655
mockFlagTeam string
657656
mockFlagToken string
658-
mockManifestSource config.ManifestSource
659657
appPromptConfigEnvironment AppEnvironmentType
660658
appPromptConfigOptions []string
661659
appPromptConfigStatus AppInstallStatus
@@ -702,7 +700,6 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
702700
UserID: team2UserID,
703701
},
704702
},
705-
mockManifestSource: config.ManifestSourceLocal,
706703
appPromptConfigEnvironment: ShowAllEnvironments,
707704
appPromptConfigOptions: []string{
708705
"A1 team1 T1",
@@ -727,7 +724,6 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
727724
"returns new application if selected": {
728725
mockAuths: fakeAuthsByTeamDomainSlice,
729726
mockAppsDeployed: []types.App{},
730-
mockManifestSource: config.ManifestSourceLocal,
731727
appPromptConfigEnvironment: ShowHostedOnly,
732728
appPromptConfigOptions: []string{
733729
"Create a new app",
@@ -746,7 +742,6 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
746742
"errors if installation required and no apps saved": {
747743
mockAuths: fakeAuthsByTeamDomainSlice,
748744
mockAppsDeployed: []types.App{},
749-
mockManifestSource: config.ManifestSourceLocal,
750745
appPromptConfigEnvironment: ShowHostedOnly,
751746
appPromptConfigStatus: ShowInstalledAppsOnly,
752747
expectedError: slackerror.New(slackerror.ErrInstallationRequired),
@@ -772,7 +767,6 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
772767
appPromptResponseOption: "Create a new app",
773768
teamPromptResponseFlag: true,
774769
teamPromptResponseOption: team1TeamDomain,
775-
mockManifestSource: config.ManifestSourceLocal,
776770
expectedError: slackerror.New(slackerror.ErrAppExists).
777771
WithDetails(slackerror.ErrorDetails{{
778772
Message: `The app "A1" already exists for team "team1" (T1)`,
@@ -783,15 +777,14 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
783777
mockAuths: fakeAuthsByTeamDomainSlice,
784778
mockFlagApp: "deployed",
785779
mockFlagTeam: team1TeamID,
786-
mockManifestSource: config.ManifestSourceLocal,
787780
appPromptConfigEnvironment: ShowHostedOnly,
788781
appPromptConfigStatus: ShowInstalledAndNewApps,
789782
expectedSelection: SelectedApp{
790783
App: types.NewApp(),
791784
Auth: fakeAuthsByTeamDomain[team1TeamDomain],
792785
},
793786
},
794-
"selects existing application for app environment flag and team id flag if app saved": {
787+
"returns existing application for app environment flag and team id flag if app saved": {
795788
mockAuths: fakeAuthsByTeamDomainSlice,
796789
mockAppsDeployed: []types.App{
797790
{
@@ -802,7 +795,6 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
802795
},
803796
mockFlagApp: "deployed",
804797
mockFlagTeam: team2TeamID,
805-
mockManifestSource: config.ManifestSourceLocal,
806798
appPromptConfigEnvironment: ShowHostedOnly,
807799
appPromptConfigStatus: ShowAllApps,
808800
expectedSelection: SelectedApp{
@@ -851,6 +843,7 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
851843
"A1 team1 T1",
852844
"A2 team2 T2",
853845
},
846+
appPromptConfigStatus: ShowInstalledAndUninstalledApps,
854847
appPromptResponsePrompt: true,
855848
appPromptResponseIndex: 1,
856849
expectedSelection: SelectedApp{
@@ -1049,7 +1042,7 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
10491042
mockFlagTeam: "TNOTFOUND",
10501043
appPromptConfigEnvironment: ShowAllEnvironments,
10511044
appPromptConfigStatus: ShowAllApps,
1052-
expectedError: slackerror.New(slackerror.ErrAppNotFound),
1045+
expectedError: slackerror.New(slackerror.ErrTeamNotFound),
10531046
},
10541047
"errors if deployed app environment flag for local app prompt": {
10551048
mockFlagApp: "deploy",
@@ -1064,22 +1057,19 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
10641057
"errors if deployed app environment flag and team id flag for local app prompt": {
10651058
mockFlagApp: "deployed",
10661059
mockFlagTeam: team1TeamID,
1067-
mockManifestSource: config.ManifestSourceLocal,
10681060
appPromptConfigEnvironment: ShowLocalOnly,
10691061
appPromptConfigStatus: ShowInstalledAndNewApps,
10701062
expectedError: slackerror.New(slackerror.ErrDeployedAppNotSupported),
10711063
},
10721064
"errors if local app environment flag and team id flag for hosted app prompt": {
10731065
mockFlagApp: "local",
10741066
mockFlagTeam: team1TeamID,
1075-
mockManifestSource: config.ManifestSourceLocal,
10761067
appPromptConfigEnvironment: ShowHostedOnly,
10771068
appPromptConfigStatus: ShowInstalledAndNewApps,
10781069
expectedError: slackerror.New(slackerror.ErrLocalAppNotSupported),
10791070
},
10801071
"errors if team id flag does not have authorization": {
10811072
mockFlagTeam: team1TeamID,
1082-
mockManifestSource: config.ManifestSourceLocal,
10831073
appPromptConfigEnvironment: ShowHostedOnly,
10841074
appPromptConfigStatus: ShowInstalledAndNewApps,
10851075
expectedError: slackerror.New(slackerror.ErrTeamNotFound),
@@ -1128,7 +1118,6 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
11281118
mockAuthWithTeamIDTeamID: team1TeamID,
11291119
mockFlagTeam: team1TeamID,
11301120
mockFlagToken: fakeAuthsByTeamDomain[team1TeamDomain].Token,
1131-
mockManifestSource: config.ManifestSourceLocal,
11321121
appPromptConfigStatus: ShowInstalledAndNewApps,
11331122
appPromptConfigEnvironment: ShowHostedOnly,
11341123
expectedSelection: SelectedApp{
@@ -1145,7 +1134,6 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
11451134
mockAuthWithTeamIDTeamID: team1TeamID,
11461135
mockFlagTeam: team1TeamID,
11471136
mockFlagToken: fakeAuthsByTeamDomain[team1TeamDomain].Token,
1148-
mockManifestSource: config.ManifestSourceLocal,
11491137
appPromptConfigStatus: ShowAllApps,
11501138
appPromptConfigEnvironment: ShowLocalOnly,
11511139
expectedSelection: SelectedApp{
@@ -1361,16 +1349,7 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
13611349
nil,
13621350
)
13631351
clientsMock.AddDefaultMocks()
1364-
projectConfigMock := config.NewProjectConfigMock()
1365-
projectConfigMock.On(
1366-
"GetManifestSource",
1367-
mock.Anything,
1368-
).Return(
1369-
tt.mockManifestSource,
1370-
nil,
1371-
)
13721352
clientsMock.Config.AppFlag = tt.mockFlagApp
1373-
clientsMock.Config.ProjectConfig = projectConfigMock
13741353
clientsMock.Config.TeamFlag = tt.mockFlagTeam
13751354
clientsMock.Config.TokenFlag = tt.mockFlagToken
13761355
clients := shared.NewClientFactory(clientsMock.MockClientFactory())

0 commit comments

Comments
 (0)