Skip to content

Commit d37b869

Browse files
committed
refactor: remove DeployResult from Deploy func
1 parent 19f6896 commit d37b869

3 files changed

Lines changed: 14 additions & 34 deletions

File tree

cmd/platform/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func NewDeployCommand(clients *shared.ClientFactory) *cobra.Command {
8989
}
9090
default:
9191
showTriggers := triggers.ShowTriggers(clients, deployFlags.hideTriggers)
92-
_, err = deployFunc(ctx, clients, showTriggers, app)
92+
err = deployFunc(ctx, clients, showTriggers, app)
9393
if err != nil {
9494
return err
9595
}

cmd/platform/deploy_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/slackapi/slack-cli/internal/config"
2626
"github.com/slackapi/slack-cli/internal/hooks"
2727
"github.com/slackapi/slack-cli/internal/iostreams"
28-
"github.com/slackapi/slack-cli/internal/pkg/platform"
2928
"github.com/slackapi/slack-cli/internal/prompts"
3029
"github.com/slackapi/slack-cli/internal/shared"
3130
"github.com/slackapi/slack-cli/internal/shared/types"
@@ -44,9 +43,9 @@ type DeployPkgMock struct {
4443
mock.Mock
4544
}
4645

47-
func (m *DeployPkgMock) Deploy(ctx context.Context, clients *shared.ClientFactory, showPrompts bool, app types.App) (platform.DeployResult, error) {
46+
func (m *DeployPkgMock) Deploy(ctx context.Context, clients *shared.ClientFactory, showPrompts bool, app types.App) error {
4847
args := m.Called(ctx, clients, showPrompts, app)
49-
return args.Get(0).(platform.DeployResult), args.Error(1)
48+
return args.Error(0)
5049
}
5150

5251
// Setup a mock for Install package
@@ -79,9 +78,7 @@ func TestDeployCommand(t *testing.T) {
7978

8079
deployPkgMock := new(DeployPkgMock)
8180
deployFunc = deployPkgMock.Deploy
82-
deployPkgMock.On("Deploy", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(platform.DeployResult{
83-
AuthSession: "{}",
84-
}, nil)
81+
deployPkgMock.On("Deploy", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
8582

8683
appSelectMock := prompts.NewAppSelectMock()
8784
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{}, nil)

internal/pkg/platform/deploy.go

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package platform
1717
import (
1818
"archive/zip"
1919
"context"
20-
"encoding/json"
2120
"fmt"
2221
"io"
2322
"os"
@@ -37,25 +36,25 @@ import (
3736
)
3837

3938
// Deploy will package and upload an app to the Slack Platform
40-
func Deploy(ctx context.Context, clients *shared.ClientFactory, showTriggers bool, app types.App) (DeployResult, error) {
39+
func Deploy(ctx context.Context, clients *shared.ClientFactory, showTriggers bool, app types.App) error {
4140
span, ctx := opentracing.StartSpanFromContext(ctx, "cmd.deploy")
4241
defer span.Finish()
4342

4443
// Get auth token
4544
token := config.GetContextToken(ctx)
4645
if strings.TrimSpace(token) == "" {
47-
return DeployResult{}, slackerror.New(slackerror.ErrAuthToken)
46+
return slackerror.New(slackerror.ErrAuthToken)
4847
}
4948

5049
if app.IsNew() {
5150
err := slackerror.New("no app found to deploy")
52-
return DeployResult{}, slackerror.Wrap(err, slackerror.ErrAppDeploy)
51+
return slackerror.Wrap(err, slackerror.ErrAppDeploy)
5352
}
5453

5554
// Validate auth session
5655
authSession, err := clients.API().ValidateSession(ctx, token)
5756
if err != nil {
58-
return DeployResult{}, slackerror.Wrap(err, slackerror.ErrSlackAuth)
57+
return slackerror.Wrap(err, slackerror.ErrSlackAuth)
5958
}
6059

6160
// Add enterprise_id returned from auth session to app if exists
@@ -66,8 +65,6 @@ func Deploy(ctx context.Context, clients *shared.ClientFactory, showTriggers boo
6665
// TODO: should we also SetAppEnterpriseID for metrics tracking?
6766
}
6867

69-
authString, _ := json.Marshal(authSession)
70-
authSessionJSON := string(authString)
7168
if authSession.UserID != nil {
7269
ctx = config.SetContextUserID(ctx, *authSession.UserID)
7370
clients.EventTracker.SetAuthUserID(*authSession.UserID)
@@ -79,37 +76,31 @@ func Deploy(ctx context.Context, clients *shared.ClientFactory, showTriggers boo
7976
// updating an app manifest should happen before an app is deployed.
8077
manifest, err := clients.AppClient().Manifest.GetManifestRemote(ctx, token, app.AppID)
8178
if err != nil {
82-
return DeployResult{}, slackerror.Wrap(err, slackerror.ErrAppManifestAccess)
79+
return slackerror.Wrap(err, slackerror.ErrAppManifestAccess)
8380
}
84-
appName := manifest.DisplayInformation.Name
8581

8682
if showTriggers {
8783
// Generate an optional trigger when none exist
8884
_, err = triggers.TriggerGenerate(ctx, clients, app)
8985
if err != nil {
90-
return DeployResult{}, slackerror.Wrap(err, slackerror.ErrAppDeploy)
86+
return slackerror.Wrap(err, slackerror.ErrAppDeploy)
9187
}
9288
}
9389

9490
// deploy the app
95-
appID, deployTime, err := deployApp(ctx, clients, app, manifest, authSession)
91+
_, _, err = deployApp(ctx, clients, app, manifest, authSession)
9692
if err != nil {
97-
return DeployResult{}, slackerror.Wrap(err, slackerror.ErrAppDeploy)
93+
return slackerror.Wrap(err, slackerror.ErrAppDeploy)
9894
}
9995

10096
// Save app to apps.json
10197
if !clients.Config.SkipLocalFs() {
10298
if err := clients.AppClient().SaveDeployed(ctx, app); err != nil {
103-
return DeployResult{}, slackerror.Wrap(err, slackerror.ErrAppDeploy)
99+
return slackerror.Wrap(err, slackerror.ErrAppDeploy)
104100
}
105101
}
106102

107-
return DeployResult{
108-
AppName: appName,
109-
AppID: appID,
110-
DeployTime: deployTime,
111-
AuthSession: authSessionJSON,
112-
}, nil
103+
return nil
113104
}
114105

115106
func deployApp(ctx context.Context, clients *shared.ClientFactory, app types.App, manifest types.SlackYaml, authSession api.AuthSession) (string, string, error) {
@@ -246,14 +237,6 @@ func deploySuccessText(clients *shared.ClientFactory, app types.App, manifest ty
246237
})
247238
}
248239

249-
// DeployResult contains data collected during the deploy process for output
250-
type DeployResult struct {
251-
AppName string
252-
AppID string
253-
DeployTime string
254-
AuthSession string
255-
}
256-
257240
type packageResult struct {
258241
Filename string
259242
Size int64

0 commit comments

Comments
 (0)