Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/manifest/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func NewInfoCommand(clients *shared.ClientFactory) *cobra.Command {
cmd.Flags().StringVar(
&manifestFlags.source,
manifestFlagSource,
config.ManifestSourceLocal.String(),
"",
fmt.Sprintf(
"source of the app manifest (\"%s\" or \"%s\")",
config.ManifestSourceLocal.String(),
Expand Down
45 changes: 27 additions & 18 deletions cmd/manifest/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@ package manifest
import (
"context"
"encoding/json"
"fmt"
"path/filepath"
"strings"
"testing"

"github.com/slackapi/slack-cli/internal/app"
"github.com/slackapi/slack-cli/internal/config"
"github.com/slackapi/slack-cli/internal/experiment"
"github.com/slackapi/slack-cli/internal/hooks"
"github.com/slackapi/slack-cli/internal/prompts"
"github.com/slackapi/slack-cli/internal/shared"
"github.com/slackapi/slack-cli/internal/shared/types"
"github.com/slackapi/slack-cli/internal/slackerror"
"github.com/slackapi/slack-cli/internal/style"
"github.com/slackapi/slack-cli/test/testutil"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -113,7 +108,7 @@ func TestInfoCommand(t *testing.T) {
assert.Equal(t, string(manifest)+"\n", cm.GetStdoutOutput())
},
},
"gathers manifest.source from project configurations with the bolt experiment": {
"gathers manifest.source local from project configurations": {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
appSelectMock := prompts.NewAppSelectMock()
appSelectPromptFunc = appSelectMock.AppSelectPrompt
Expand All @@ -133,8 +128,6 @@ func TestInfoCommand(t *testing.T) {
},
}, nil)
cf.AppClient().Manifest = manifestMock
cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, string(experiment.BoltFrameworks))
cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug)
mockProjectConfig := config.NewProjectConfigMock()
mockProjectConfig.On("GetManifestSource", mock.Anything).Return(config.ManifestSourceLocal, nil)
cm.Config.ProjectConfig = mockProjectConfig
Expand All @@ -150,24 +143,40 @@ func TestInfoCommand(t *testing.T) {
assert.Equal(t, string(manifest)+"\n", cm.GetStdoutOutput())
},
},
"errors if project manifest source is remote with the bolt experiment": {
ExpectedError: slackerror.New(slackerror.ErrInvalidManifestSource).
WithMessage(`Cannot get manifest info from the "%s" source`, config.ManifestSourceRemote).
WithRemediation("%s", strings.Join([]string{
fmt.Sprintf("Find the current manifest on app settings: %s", style.LinkText("https://api.slack.com/apps")),
fmt.Sprintf("Set \"manifest.source\" to \"%s\" in \"%s\" to continue", config.ManifestSourceLocal, filepath.Join(".slack", "config.json")),
fmt.Sprintf("Read about manifest sourcing with %s", style.Commandf("manifest info --help", false)),
}, "\n")),
"gathers manifest.source remote from project configurations": {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cf.SDKConfig.WorkingDirectory = "."
cm.IO.AddDefaultMocks()
cm.Os.AddDefaultMocks()
cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, string(experiment.BoltFrameworks))
cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug)
mockProjectConfig := config.NewProjectConfigMock()
mockProjectConfig.On("GetManifestSource", mock.Anything).
Return(config.ManifestSource(config.ManifestSourceRemote), nil)
cm.Config.ProjectConfig = mockProjectConfig
manifestMock := &app.ManifestMockObject{}
manifestMock.On("GetManifestRemote", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{
AppManifest: types.AppManifest{
DisplayInformation: types.DisplayInformation{
Name: "app005",
},
},
}, nil)
cf.AppClient().Manifest = manifestMock
appSelectMock := prompts.NewAppSelectMock()
appSelectPromptFunc = appSelectMock.AppSelectPrompt
appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{
App: types.App{AppID: "A005"},
Auth: types.SlackAuth{Token: "xapp-example-005"},
}, nil)
},
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
mockManifest := types.AppManifest{
DisplayInformation: types.DisplayInformation{
Name: "app005",
},
}
manifest, err := json.MarshalIndent(mockManifest, "", " ")
require.NoError(t, err)
assert.Equal(t, string(manifest)+"\n", cm.GetStdoutOutput())
},
},
}, func(clients *shared.ClientFactory) *cobra.Command {
Expand Down
56 changes: 24 additions & 32 deletions cmd/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ package manifest
import (
"context"
"fmt"
"path/filepath"
"strings"

"github.com/slackapi/slack-cli/internal/cmdutil"
"github.com/slackapi/slack-cli/internal/config"
"github.com/slackapi/slack-cli/internal/experiment"
"github.com/slackapi/slack-cli/internal/prompts"
"github.com/slackapi/slack-cli/internal/shared"
"github.com/slackapi/slack-cli/internal/slackerror"
Expand Down Expand Up @@ -86,7 +84,7 @@ func NewCommand(clients *shared.ClientFactory) *cobra.Command {
cmd.Flags().StringVar(
&manifestFlags.source,
manifestFlagSource,
config.ManifestSourceLocal.String(),
"",
fmt.Sprintf(
"source of the app manifest (\"%s\" or \"%s\")",
config.ManifestSourceLocal.String(),
Expand All @@ -111,38 +109,32 @@ func getManifestSource(ctx context.Context, clients *shared.ClientFactory, cmd *
}
return config.ManifestSourceRemote, nil
}
if clients.Config.WithExperimentOn(experiment.BoltFrameworks) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪓 Nice to slowly remove the old BoltFrameworks experiment!

if !cmd.Flag(manifestFlagSource).Changed {
manifestConfigSource, err := clients.Config.ProjectConfig.GetManifestSource(ctx)
if err != nil {
return "", err
}
switch {
case manifestConfigSource.Equals(config.ManifestSourceLocal):
return manifestConfigSource, nil
case manifestConfigSource.Equals(config.ManifestSourceRemote):
return "", slackerror.New(slackerror.ErrInvalidManifestSource).
WithMessage(`Cannot get manifest info from the "%s" source`, config.ManifestSourceRemote).
WithRemediation("%s", strings.Join([]string{
fmt.Sprintf("Find the current manifest on app settings: %s", style.LinkText("https://api.slack.com/apps")),
fmt.Sprintf("Set \"manifest.source\" to \"%s\" in \"%s\" to continue", config.ManifestSourceLocal, filepath.Join(".slack", "config.json")),
fmt.Sprintf("Read about manifest sourcing with %s", style.Commandf("manifest info --help", false)),
}, "\n"))
Comment on lines -124 to -130
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📣 These error details are never reached due to the err from GetManifestSource above - opting to fallback to the default message if this errors!

}
if cmd.Flag(manifestFlagSource).Changed {
switch {
case config.ManifestSource(manifestFlags.source).Equals(config.ManifestSourceLocal):
return config.ManifestSourceLocal, nil
case config.ManifestSource(manifestFlags.source).Equals(config.ManifestSourceRemote):
return config.ManifestSourceRemote, nil
default:
return "", slackerror.New(slackerror.ErrInvalidFlag).
WithMessage(
"The \"--%s\" flag must be \"%s\" or \"%s\"",
manifestFlagSource,
config.ManifestSourceLocal,
config.ManifestSourceRemote,
)
}
}
manifestConfigSource, err := clients.Config.ProjectConfig.GetManifestSource(ctx)
if err != nil {
return "", err
}
switch {
case config.ManifestSource(manifestFlags.source).Equals(config.ManifestSourceLocal):
return config.ManifestSourceLocal, nil
case config.ManifestSource(manifestFlags.source).Equals(config.ManifestSourceRemote):
return config.ManifestSourceRemote, nil
case manifestConfigSource.Equals(config.ManifestSourceLocal):
return manifestConfigSource, nil
case manifestConfigSource.Equals(config.ManifestSourceRemote):
return manifestConfigSource, nil
default:
return "", slackerror.New(slackerror.ErrInvalidFlag).
WithMessage(
"The \"--%s\" flag must be \"%s\" or \"%s\"",
manifestFlagSource,
config.ManifestSourceLocal,
config.ManifestSourceRemote,
)
return "", slackerror.New(slackerror.ErrInvalidManifestSource)
}
}
Loading