-
Notifications
You must be signed in to change notification settings - Fork 31
feat: support png, jpg, jpeg, gif for icon auto-detection #509
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 |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ package apps | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "time" | ||
|
|
||
|
|
@@ -30,6 +30,7 @@ import ( | |
| "github.com/slackapi/slack-cli/internal/shared/types" | ||
| "github.com/slackapi/slack-cli/internal/slackerror" | ||
| "github.com/slackapi/slack-cli/internal/style" | ||
| "github.com/spf13/afero" | ||
| ) | ||
|
|
||
| // Constants for onlyCreateUpdateAppManifest parameter | ||
|
|
@@ -40,6 +41,23 @@ const ( | |
|
|
||
| const additionalManifestInfoNotice = "App manifest contains some components that may require additional information" | ||
|
|
||
| var supportedIconExtensions = []string{".png", ".jpg", ".jpeg", ".gif"} | ||
|
|
||
| func resolveIconPath(fs afero.Fs, manifestIcon string) string { | ||
|
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: Thoughts on moving this to |
||
| if manifestIcon != "" { | ||
| return manifestIcon | ||
| } | ||
| for _, dir := range []string{"assets", "."} { | ||
| for _, ext := range supportedIconExtensions { | ||
| candidate := filepath.Join(dir, "icon"+ext) | ||
| if _, err := fs.Stat(candidate); err == nil { | ||
| return candidate | ||
| } | ||
| } | ||
|
Comment on lines
+50
to
+56
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. question: It looks like the implementation will attempt to find the first image that matches the file extensions and use it when there is no path defined? |
||
| } | ||
| return "" | ||
| } | ||
|
|
||
| // Install installs the app to a team | ||
| func Install(ctx context.Context, clients *shared.ClientFactory, auth types.SlackAuth, onlyCreateUpdateAppManifest bool, app types.App, orgGrantWorkspaceID string) (types.App, types.InstallState, error) { | ||
| span, ctx := opentracing.StartSpanFromContext(ctx, "pkg.apps.install") | ||
|
|
@@ -218,13 +236,8 @@ func Install(ctx context.Context, clients *shared.ClientFactory, auth types.Slac | |
| } | ||
| } | ||
|
|
||
| // upload icon, default to icon.png | ||
| var iconPath = slackManifest.Icon | ||
| if iconPath == "" { | ||
| if _, err := os.Stat("icon.png"); !os.IsNotExist(err) { | ||
| iconPath = "icon.png" | ||
| } | ||
| } | ||
| // upload icon, default to assets/icon.{png,jpg,jpeg,gif} or icon.{png,jpg,jpeg,gif} | ||
| iconPath := resolveIconPath(clients.Fs, slackManifest.Icon) | ||
| if iconPath != "" { | ||
| err = updateIcon(ctx, clients, iconPath, app.AppID, token) | ||
| if err != nil { | ||
|
|
@@ -524,12 +537,7 @@ func InstallLocalApp(ctx context.Context, clients *shared.ClientFactory, orgGran | |
|
|
||
| // upload icon for non-hosted apps (gated behind set-icon experiment) | ||
| if clients.Config.WithExperimentOn(experiment.SetIcon) { | ||
| var iconPath = slackManifest.Icon | ||
| if iconPath == "" { | ||
| if _, err := os.Stat("icon.png"); !os.IsNotExist(err) { | ||
| iconPath = "icon.png" | ||
| } | ||
| } | ||
| iconPath := resolveIconPath(clients.Fs, slackManifest.Icon) | ||
| if iconPath != "" { | ||
| _, iconErr := clients.API().IconSet(ctx, clients.Fs, token, app.AppID, iconPath) | ||
| if iconErr != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,15 +27,19 @@ type SlackYaml struct { | |
| Hash string | ||
| } | ||
|
|
||
| var supportedIconExtensions = []string{".png", ".jpg", ".jpeg", ".gif"} | ||
|
|
||
| // hasValidIconPath returns false if icon path is provided but is not valid and true otherwise | ||
| func (sy *SlackYaml) hasValidIconPath() bool { | ||
| // verify icon path is valid if exists | ||
| var wd, err = os.Getwd() | ||
| if err == nil { | ||
| if sy.Icon == "" { // icon was not provided. Let's check if the default one exists | ||
| var defaultIconPath = "assets/icon.png" | ||
| if _, err := os.Stat(filepath.Join(wd, defaultIconPath)); !os.IsNotExist(err) { | ||
| sy.Icon = defaultIconPath | ||
| if sy.Icon == "" { | ||
| for _, ext := range supportedIconExtensions { | ||
| candidate := filepath.Join(wd, "assets", "icon"+ext) | ||
| if _, err := os.Stat(candidate); !os.IsNotExist(err) { | ||
| sy.Icon = filepath.Join("assets", "icon"+ext) | ||
| break | ||
| } | ||
|
Comment on lines
+37
to
+42
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: Since we're using this loop logic in 2 places, I think it would make sense to implement it as a function in |
||
| } | ||
| } else { | ||
| if _, err := os.Stat(filepath.Join(wd, sy.Icon)); os.IsNotExist(err) { | ||
|
|
||
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.
question: Just curious, have you tested all of these images types? I just want to make sure that the API supports each.