Skip to content

Commit eabc9ba

Browse files
committed
Merge branch 'main' of https://github.com/slackapi/slack-cli into evegeris-sandbox-integration
2 parents c0b11c5 + cf06058 commit eabc9ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1486
-1811
lines changed

.claude/CLAUDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ make lint # Run golangci-lint
3131
golangci-lint --version # Verify linter version
3232
```
3333

34+
### Formatting
35+
36+
Always run `gofmt -w` on changed Go files after making edits to ensure proper formatting.
37+
3438
### Other Commands
3539

3640
```bash

cmd/app/add.go

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ package app
1616

1717
import (
1818
"context"
19-
"fmt"
2019

2120
"github.com/slackapi/slack-cli/internal/app"
2221
"github.com/slackapi/slack-cli/internal/cmdutil"
2322
"github.com/slackapi/slack-cli/internal/config"
2423
"github.com/slackapi/slack-cli/internal/experiment"
25-
"github.com/slackapi/slack-cli/internal/logger"
2624
"github.com/slackapi/slack-cli/internal/pkg/apps"
2725
"github.com/slackapi/slack-cli/internal/prompts"
2826
"github.com/slackapi/slack-cli/internal/shared"
@@ -186,11 +184,8 @@ func RunAddCommand(ctx context.Context, clients *shared.ClientFactory, selection
186184

187185
clients.Config.ManifestEnv = app.SetManifestEnvTeamVars(clients.Config.ManifestEnv, selection.App.TeamDomain, selection.App.IsDev)
188186

189-
// Set up event logger
190-
log := newAddLogger(clients, selection.Auth.TeamDomain)
191-
192187
// Install dev app or prod app to a workspace
193-
installedApp, installState, err := appInstall(ctx, clients, log, selection, orgGrantWorkspaceID)
188+
installedApp, installState, err := appInstall(ctx, clients, selection, orgGrantWorkspaceID)
194189
if err != nil {
195190
return ctx, installState, types.App{}, err // pass the installState because some callers may use it to handle the error
196191
}
@@ -201,74 +196,19 @@ func RunAddCommand(ctx context.Context, clients *shared.ClientFactory, selection
201196
return ctx, installState, installedApp, nil
202197
}
203198

204-
// newAddLogger creates a logger instance to receive event notifications
205-
func newAddLogger(clients *shared.ClientFactory, envName string) *logger.Logger {
206-
return logger.New(
207-
// OnEvent
208-
func(event *logger.LogEvent) {
209-
teamName := event.DataToString("teamName")
210-
appName := event.DataToString("appName")
211-
switch event.Name {
212-
case "app_install_manifest":
213-
// Ignore this event and format manifest outputs in create/update events
214-
case "app_install_manifest_create":
215-
_, _ = clients.IO.WriteOut().Write([]byte(style.Sectionf(style.TextSection{
216-
Emoji: "books",
217-
Text: "App Manifest",
218-
Secondary: []string{
219-
fmt.Sprintf(`Creating app manifest for "%s" in "%s"`, appName, teamName),
220-
},
221-
})))
222-
case "app_install_manifest_update":
223-
_, _ = clients.IO.WriteOut().Write([]byte("\n" + style.Sectionf(style.TextSection{
224-
Emoji: "books",
225-
Text: "App Manifest",
226-
Secondary: []string{
227-
fmt.Sprintf(`Updated app manifest for "%s" in "%s"`, appName, teamName),
228-
},
229-
})))
230-
case "app_install_start":
231-
_, _ = clients.IO.WriteOut().Write([]byte("\n" + style.Sectionf(style.TextSection{
232-
Emoji: "house",
233-
Text: "App Install",
234-
Secondary: []string{
235-
fmt.Sprintf(`Installing "%s" app to "%s"`, appName, teamName),
236-
},
237-
})))
238-
case "app_install_icon_success":
239-
iconPath := event.DataToString("iconPath")
240-
_, _ = clients.IO.WriteOut().Write([]byte(
241-
style.SectionSecondaryf("Updated app icon: %s", iconPath),
242-
))
243-
case "app_install_icon_error":
244-
iconError := event.DataToString("iconError")
245-
_, _ = clients.IO.WriteOut().Write([]byte(
246-
style.SectionSecondaryf("Error updating app icon: %s", iconError),
247-
))
248-
case "app_install_complete":
249-
_, _ = clients.IO.WriteOut().Write([]byte(
250-
style.SectionSecondaryf("Finished in %s", event.DataToString("installTime")),
251-
))
252-
default:
253-
// Ignore the event
254-
}
255-
},
256-
)
257-
}
258-
259199
// printAddSuccess will print a list of the environments
260200
func printAddSuccess(clients *shared.ClientFactory, cmd *cobra.Command, appInstance types.App) error {
261201
return runListCommand(cmd, clients)
262202
}
263203

264204
// appInstall will install an app to a team. It supports both local and deployed app types.
265-
func appInstall(ctx context.Context, clients *shared.ClientFactory, log *logger.Logger, selection *prompts.SelectedApp, orgGrantWorkspaceID string) (types.App, types.InstallState, error) {
205+
func appInstall(ctx context.Context, clients *shared.ClientFactory, selection *prompts.SelectedApp, orgGrantWorkspaceID string) (types.App, types.InstallState, error) {
266206
if selection != nil && selection.App.IsDev {
267207
// Install local dev app to a team
268-
installedApp, _, installState, err := appInstallDevAppFunc(ctx, clients, "", log, selection.Auth, selection.App)
208+
installedApp, _, installState, err := appInstallDevAppFunc(ctx, clients, "", selection.Auth, selection.App)
269209
return installedApp, installState, err
270210
} else {
271-
installState, installedApp, err := appInstallProdAppFunc(ctx, clients, log, selection.Auth, selection.App, orgGrantWorkspaceID)
211+
installState, installedApp, err := appInstallProdAppFunc(ctx, clients, selection.Auth, selection.App, orgGrantWorkspaceID)
272212
return installedApp, installState, err
273213
}
274214
}

cmd/app/delete.go

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

2121
"github.com/slackapi/slack-cli/internal/cmdutil"
2222
"github.com/slackapi/slack-cli/internal/iostreams"
23-
"github.com/slackapi/slack-cli/internal/logger"
2423
"github.com/slackapi/slack-cli/internal/pkg/apps"
2524
"github.com/slackapi/slack-cli/internal/prompts"
2625
"github.com/slackapi/slack-cli/internal/shared"
@@ -99,30 +98,14 @@ func RunDeleteCommand(ctx context.Context, clients *shared.ClientFactory, cmd *c
9998
}
10099
}
101100

102-
// Set up event logger and execute the command
103-
log := newDeleteLogger(clients, cmd, team)
104-
log.Data["appID"] = selection.App.AppID
105-
env, err := apps.Delete(ctx, clients, log, team, selection.App, selection.Auth)
106-
107-
return env, err
108-
}
101+
// Execute the command
102+
env, teamName, err := apps.Delete(ctx, clients, team, selection.App, selection.Auth)
103+
if err != nil {
104+
return env, err
105+
}
106+
printDeleteApp(ctx, clients, selection.App.AppID, teamName)
109107

110-
// newDeleteLogger creates a logger instance to receive event notifications
111-
func newDeleteLogger(clients *shared.ClientFactory, cmd *cobra.Command, envName string) *logger.Logger {
112-
ctx := cmd.Context()
113-
return logger.New(
114-
// OnEvent
115-
func(event *logger.LogEvent) {
116-
appID := event.DataToString("appID")
117-
teamName := event.DataToString("teamName")
118-
switch event.Name {
119-
case "on_apps_delete_app_success":
120-
printDeleteApp(ctx, clients, appID, teamName)
121-
default:
122-
// Ignore the event
123-
}
124-
},
125-
)
108+
return env, nil
126109
}
127110

128111
func confirmDeletion(ctx context.Context, IO iostreams.IOStreamer, app prompts.SelectedApp) (bool, error) {

cmd/app/link.go

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import (
1818
"context"
1919
"fmt"
2020
"path/filepath"
21-
"slices"
2221
"strings"
2322

2423
"github.com/slackapi/slack-cli/internal/cmdutil"
2524
"github.com/slackapi/slack-cli/internal/config"
2625
"github.com/slackapi/slack-cli/internal/iostreams"
2726
"github.com/slackapi/slack-cli/internal/pkg/apps"
27+
"github.com/slackapi/slack-cli/internal/prompts"
2828
"github.com/slackapi/slack-cli/internal/shared"
2929
"github.com/slackapi/slack-cli/internal/shared/types"
3030
"github.com/slackapi/slack-cli/internal/slackerror"
@@ -262,7 +262,7 @@ func LinkAppFooterSection(ctx context.Context, clients *shared.ClientFactory, ap
262262

263263
// promptExistingApp gathers details to represent app information
264264
func promptExistingApp(ctx context.Context, clients *shared.ClientFactory) (types.App, *types.SlackAuth, error) {
265-
slackAuth, err := promptTeamSlackAuth(ctx, clients)
265+
slackAuth, err := prompts.PromptTeamSlackAuth(ctx, clients, "Select the existing app team")
266266
if err != nil {
267267
return types.App{}, &types.SlackAuth{}, err
268268
}
@@ -291,61 +291,6 @@ func promptExistingApp(ctx context.Context, clients *shared.ClientFactory) (type
291291
return apps[0], slackAuth, nil
292292
}
293293

294-
// promptTeamSlackAuth retrieves an authenticated team from input
295-
func promptTeamSlackAuth(ctx context.Context, clients *shared.ClientFactory) (*types.SlackAuth, error) {
296-
allAuths, err := clients.Auth().Auths(ctx)
297-
if err != nil {
298-
return &types.SlackAuth{}, err
299-
}
300-
slices.SortFunc(allAuths, func(i, j types.SlackAuth) int {
301-
if i.TeamDomain == j.TeamDomain {
302-
return strings.Compare(i.TeamID, j.TeamID)
303-
}
304-
return strings.Compare(i.TeamDomain, j.TeamDomain)
305-
})
306-
var teamLabels []string
307-
for _, auth := range allAuths {
308-
teamLabels = append(
309-
teamLabels,
310-
style.TeamSelectLabel(auth.TeamDomain, auth.TeamID),
311-
)
312-
}
313-
selection, err := clients.IO.SelectPrompt(
314-
ctx,
315-
"Select the existing app team",
316-
teamLabels,
317-
iostreams.SelectPromptConfig{
318-
Required: true,
319-
Flag: clients.Config.Flags.Lookup("team"),
320-
},
321-
)
322-
if err != nil {
323-
return &types.SlackAuth{}, err
324-
}
325-
if selection.Prompt {
326-
clients.Auth().SetSelectedAuth(ctx, allAuths[selection.Index], clients.Config, clients.Os)
327-
return &allAuths[selection.Index], nil
328-
}
329-
teamMatch := false
330-
teamIndex := -1
331-
for ii, auth := range allAuths {
332-
if selection.Option == auth.TeamID || selection.Option == auth.TeamDomain {
333-
if teamMatch {
334-
return &types.SlackAuth{}, slackerror.New(slackerror.ErrMissingAppTeamID).
335-
WithMessage("The team cannot be determined by team domain").
336-
WithRemediation("Provide the team ID for the installed app")
337-
}
338-
teamMatch = true
339-
teamIndex = ii
340-
}
341-
}
342-
if !teamMatch {
343-
return &types.SlackAuth{}, slackerror.New(slackerror.ErrCredentialsNotFound)
344-
}
345-
clients.Auth().SetSelectedAuth(ctx, allAuths[teamIndex], clients.Config, clients.Os)
346-
return &allAuths[teamIndex], nil
347-
}
348-
349294
// promptAppID retrieves an app ID from user input
350295
func promptAppID(ctx context.Context, clients *shared.ClientFactory) (string, error) {
351296
if clients.Config.Flags.Lookup("app").Changed {

cmd/app/uninstall.go

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

2121
"github.com/slackapi/slack-cli/internal/cmdutil"
2222
"github.com/slackapi/slack-cli/internal/iostreams"
23-
"github.com/slackapi/slack-cli/internal/logger"
2423
"github.com/slackapi/slack-cli/internal/pkg/apps"
2524
"github.com/slackapi/slack-cli/internal/prompts"
2625
"github.com/slackapi/slack-cli/internal/shared"
@@ -94,30 +93,14 @@ func RunUninstallCommand(ctx context.Context, clients *shared.ClientFactory, cmd
9493
}
9594
}
9695

97-
// Set up event logger and execute the command
98-
log := newUninstallLogger(clients, cmd, teamDomain)
99-
log.Data["appID"] = selection.App.AppID
100-
env, err := apps.Uninstall(ctx, clients, log, teamDomain, selection.App, selection.Auth)
101-
102-
return env, err
103-
}
96+
// Execute the command
97+
env, teamName, err := apps.Uninstall(ctx, clients, teamDomain, selection.App, selection.Auth)
98+
if err != nil {
99+
return env, err
100+
}
101+
printUninstallApp(ctx, clients, selection.App.AppID, teamName)
104102

105-
// newUninstallLogger creates a logger instance to receive event notifications
106-
func newUninstallLogger(clients *shared.ClientFactory, cmd *cobra.Command, envName string) *logger.Logger {
107-
ctx := cmd.Context()
108-
return logger.New(
109-
// OnEvent
110-
func(event *logger.LogEvent) {
111-
appID := event.DataToString("appID")
112-
teamName := event.DataToString("teamName")
113-
switch event.Name {
114-
case "on_apps_uninstall_app_success":
115-
printUninstallApp(ctx, clients, appID, teamName)
116-
default:
117-
// Ignore the event
118-
}
119-
},
120-
)
103+
return env, nil
121104
}
122105

123106
func confirmUninstall(ctx context.Context, IO iostreams.IOStreamer, cmd *cobra.Command, selection prompts.SelectedApp) (bool, error) {

cmd/auth/auth_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"testing"
2020

2121
"github.com/slackapi/slack-cli/internal/hooks"
22-
"github.com/slackapi/slack-cli/internal/logger"
2322
"github.com/slackapi/slack-cli/internal/shared"
2423
"github.com/slackapi/slack-cli/internal/shared/types"
2524
"github.com/slackapi/slack-cli/internal/slackcontext"
@@ -32,7 +31,7 @@ type listMockObject struct {
3231
mock.Mock
3332
}
3433

35-
func (m *listMockObject) MockListFunction(ctx context.Context, clients *shared.ClientFactory, log *logger.Logger) ([]types.SlackAuth, error) {
34+
func (m *listMockObject) MockListFunction(ctx context.Context, clients *shared.ClientFactory) ([]types.SlackAuth, error) {
3635
args := m.Called()
3736
return args.Get(0).([]types.SlackAuth), args.Error(1)
3837
}

cmd/auth/list.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"fmt"
1919

2020
"github.com/slackapi/slack-cli/internal/iostreams"
21-
"github.com/slackapi/slack-cli/internal/logger"
2221
"github.com/slackapi/slack-cli/internal/pkg/auth"
2322
"github.com/slackapi/slack-cli/internal/shared"
2423
"github.com/slackapi/slack-cli/internal/shared/types"
@@ -52,34 +51,15 @@ func NewListCommand(clients *shared.ClientFactory) *cobra.Command {
5251
// runListCommand will execute the list command
5352
func runListCommand(cmd *cobra.Command, clients *shared.ClientFactory) error {
5453
ctx := cmd.Context()
55-
log := newListLogger(cmd, clients.IO)
56-
userAuthList, err := listFunc(ctx, clients, log)
54+
userAuthList, err := listFunc(ctx, clients)
5755
if err != nil {
5856
return err
5957
}
58+
printAuthList(cmd, clients.IO, userAuthList)
6059
printAuthListSuccess(cmd, clients.IO, userAuthList)
6160
return nil
6261
}
6362

64-
// newListLogger creates a logger instance to receive event notifications
65-
func newListLogger(cmd *cobra.Command, IO iostreams.IOStreamer) *logger.Logger {
66-
return logger.New(
67-
// OnEvent
68-
func(event *logger.LogEvent) {
69-
switch event.Name {
70-
case "on_auth_list":
71-
userAuthList := []types.SlackAuth{}
72-
if event.Data["userAuthList"] != nil {
73-
userAuthList = event.Data["userAuthList"].([]types.SlackAuth)
74-
}
75-
printAuthList(cmd, IO, userAuthList)
76-
default:
77-
// Ignore the event
78-
}
79-
},
80-
)
81-
}
82-
8363
// printAuthList will display a list of all authorizations available and highlight the default.
8464
// The output will be a list formatted as:
8565
//

cmd/auth/list_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"context"
1919
"testing"
2020

21-
"github.com/slackapi/slack-cli/internal/logger"
2221
"github.com/slackapi/slack-cli/internal/shared"
2322
"github.com/slackapi/slack-cli/internal/shared/types"
2423
"github.com/slackapi/slack-cli/internal/slackcontext"
@@ -32,7 +31,7 @@ type ListPkgMock struct {
3231
mock.Mock
3332
}
3433

35-
func (m *ListPkgMock) List(ctx context.Context, clients *shared.ClientFactory, log *logger.Logger) ([]types.SlackAuth, error) {
34+
func (m *ListPkgMock) List(ctx context.Context, clients *shared.ClientFactory) ([]types.SlackAuth, error) {
3635
m.Called()
3736
return []types.SlackAuth{}, nil
3837
}

0 commit comments

Comments
 (0)