-
Notifications
You must be signed in to change notification settings - Fork 39
feat: conclude set-icon experiment #623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -220,7 +220,7 @@ func Install(ctx context.Context, clients *shared.ClientFactory, auth types.Slac | |
|
|
||
| iconPath := resolveIconPath(ctx, clients, slackManifest.Icon) | ||
| if iconPath != "" { | ||
| err = updateIcon(ctx, clients, iconPath, app.AppID, token, manifest.IsFunctionRuntimeSlackHosted()) | ||
| err = updateIcon(ctx, clients, iconPath, app.AppID, token) | ||
| if err != nil { | ||
| clients.IO.PrintDebug(ctx, "icon error: %s", err) | ||
| _, _ = clients.IO.WriteOut().Write([]byte(style.SectionSecondaryf("Error updating app icon: %s", err))) | ||
|
|
@@ -516,17 +516,14 @@ func InstallLocalApp(ctx context.Context, clients *shared.ClientFactory, orgGran | |
| return app, result, installState, err | ||
| } | ||
|
|
||
| // upload icon for non-hosted apps (gated behind set-icon experiment) | ||
| if clients.Config.WithExperimentOn(experiment.SetIcon) { | ||
| iconPath := resolveIconPath(ctx, clients, slackManifest.Icon) | ||
| if iconPath != "" { | ||
| _, iconErr := clients.API().IconSet(ctx, clients.Fs, token, app.AppID, iconPath) | ||
| if iconErr != nil { | ||
| clients.IO.PrintDebug(ctx, "icon error: %s", iconErr) | ||
| _, _ = clients.IO.WriteOut().Write([]byte(style.SectionSecondaryf("Error updating app icon: %s", iconErr))) | ||
| } else { | ||
| _, _ = clients.IO.WriteOut().Write([]byte(style.SectionSecondaryf("Updated app icon: %s", iconPath))) | ||
| } | ||
| iconPath := resolveIconPath(ctx, clients, slackManifest.Icon) | ||
| if iconPath != "" { | ||
| _, iconErr := clients.API().IconSet(ctx, clients.Fs, token, app.AppID, iconPath) | ||
| if iconErr != nil { | ||
| clients.IO.PrintDebug(ctx, "icon error: %s", iconErr) | ||
| _, _ = clients.IO.WriteOut().Write([]byte(style.SectionSecondaryf("Error updating app icon: %s", iconErr))) | ||
| } else { | ||
| _, _ = clients.IO.WriteOut().Write([]byte(style.SectionSecondaryf("Updated app icon: %s", iconPath))) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -661,28 +658,16 @@ func resolveIconPath(ctx context.Context, clients *shared.ClientFactory, manifes | |
| } | ||
|
|
||
| // updateIcon will upload the new icon to the Slack API | ||
| func updateIcon(ctx context.Context, clients *shared.ClientFactory, iconPath, appID string, token string, isHosted bool) error { | ||
| func updateIcon(ctx context.Context, clients *shared.ClientFactory, iconPath, appID string, token string) error { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🪓 suggestion: This function is used once in |
||
| var span opentracing.Span | ||
| span, ctx = opentracing.StartSpanFromContext(ctx, "updateIcon") | ||
| defer span.Finish() | ||
|
|
||
| var err error | ||
| if clients.Config.WithExperimentOn(experiment.SetIcon) { | ||
| _, err = clients.API().IconSet(ctx, clients.Fs, token, appID, iconPath) | ||
| } else if isHosted { | ||
| // DEPRECATED: Prefer IconSet once the SetIcon experiment concludes | ||
| _, err = clients.API().Icon(ctx, clients.Fs, token, appID, iconPath) | ||
| } else { | ||
| return nil | ||
| } | ||
| _, err := clients.API().IconSet(ctx, clients.Fs, token, appID, iconPath) | ||
| if err != nil { | ||
| // TODO: separate the icon upload into a different function because if an error is returned | ||
| // the new app_id might be ignored and next time we'll create another app. | ||
| return fmt.Errorf("%s %s", err, iconPath) | ||
| } | ||
|
|
||
| // Save a md5 hash of the icon in environments.yaml | ||
| // env.IconHash = iconResp.MD5Hash | ||
| return nil | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,15 +16,13 @@ package apps | |
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/slackapi/slack-cli/internal/api" | ||
| "github.com/slackapi/slack-cli/internal/app" | ||
| "github.com/slackapi/slack-cli/internal/cache" | ||
| "github.com/slackapi/slack-cli/internal/config" | ||
| "github.com/slackapi/slack-cli/internal/experiment" | ||
| "github.com/slackapi/slack-cli/internal/shared" | ||
| "github.com/slackapi/slack-cli/internal/shared/types" | ||
| "github.com/slackapi/slack-cli/internal/slackcontext" | ||
|
|
@@ -1811,45 +1809,11 @@ func Test_resolveIconPath(t *testing.T) { | |
|
|
||
| func Test_updateIcon(t *testing.T) { | ||
| tests := map[string]struct { | ||
| isHosted bool | ||
| experimentOn bool | ||
| expectIconSet bool | ||
| expectIcon bool | ||
| expectSkip bool | ||
| mockError error | ||
| expectedError bool | ||
| }{ | ||
| "experiment on + hosted app uses IconSet": { | ||
| isHosted: true, | ||
| experimentOn: true, | ||
| expectIconSet: true, | ||
| }, | ||
| "experiment on + non-hosted app uses IconSet": { | ||
| isHosted: false, | ||
| experimentOn: true, | ||
| expectIconSet: true, | ||
| }, | ||
| "experiment off + hosted app uses Icon": { | ||
| isHosted: true, | ||
| experimentOn: false, | ||
| expectIcon: true, | ||
| }, | ||
| "experiment off + non-hosted app skips upload": { | ||
| isHosted: false, | ||
| experimentOn: false, | ||
| expectSkip: true, | ||
| }, | ||
| "succeeds with IconSet": {}, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧪 note: This test doesn't seem so useful without mock data included. Another comment suggested deleting the function it's testing and IMHO this is supported here. Otherwise I'd suggest including:
|
||
| "returns error from IconSet": { | ||
| isHosted: false, | ||
| experimentOn: true, | ||
| expectIconSet: true, | ||
| mockError: fmt.Errorf("api error"), | ||
| expectedError: true, | ||
| }, | ||
| "returns error from Icon": { | ||
| isHosted: true, | ||
| experimentOn: false, | ||
| expectIcon: true, | ||
| mockError: fmt.Errorf("api error"), | ||
| expectedError: true, | ||
| }, | ||
|
|
@@ -1860,35 +1824,19 @@ func Test_updateIcon(t *testing.T) { | |
| clientsMock := shared.NewClientsMock() | ||
| clientsMock.AddDefaultMocks() | ||
|
|
||
| if tc.experimentOn { | ||
| clientsMock.Config.ExperimentsFlag = []string{string(experiment.SetIcon)} | ||
| clientsMock.Config.LoadExperiments(ctx, func(_ context.Context, _ string, _ ...interface{}) {}) | ||
| } | ||
|
|
||
| clientsMock.API.On("IconSet", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). | ||
| Return(api.IconResult{}, tc.mockError) | ||
| clientsMock.API.On("Icon", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). | ||
| Return(api.IconResult{}, tc.mockError) | ||
|
|
||
| clients := shared.NewClientFactory(clientsMock.MockClientFactory()) | ||
| err := updateIcon(ctx, clients, "icon.png", "A001", "xoxe-token", tc.isHosted) | ||
| err := updateIcon(ctx, clients, "icon.png", "A001", "xoxe-token") | ||
|
|
||
| if tc.expectedError { | ||
| require.Error(t, err) | ||
| } else { | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| if tc.expectIconSet { | ||
| clientsMock.API.AssertCalled(t, "IconSet", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) | ||
| clientsMock.API.AssertNotCalled(t, "Icon") | ||
| } else if tc.expectIcon { | ||
| clientsMock.API.AssertCalled(t, "Icon", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) | ||
| clientsMock.API.AssertNotCalled(t, "IconSet") | ||
| } else if tc.expectSkip { | ||
| clientsMock.API.AssertNotCalled(t, "Icon") | ||
| clientsMock.API.AssertNotCalled(t, "IconSet") | ||
| } | ||
| clientsMock.API.AssertCalled(t, "IconSet", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a little easier to read methinks