-
Notifications
You must be signed in to change notification settings - Fork 31
feat: support SLACK_CLI_APP_ICON_PATH env var for icon override #519
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
Changes from 2 commits
23afd93
5176129
c9abb30
14c811f
b626cec
95ded37
d7e7ccd
d599052
8df3140
87a4646
061e54f
2778c01
3a8c3e5
805fdaf
ac8245a
f57be2f
f498dc2
ed4c940
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 |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import ( | |
| ) | ||
|
|
||
| // Environment Variable constants | ||
| const slackAppIconPathEnv = "SLACK_CLI_APP_ICON_PATH" | ||
| const slackAutoRequestAAAEnv = "SLACK_AUTO_REQUEST_AAA" | ||
| const slackConfigDirEnv = "SLACK_CONFIG_DIR" | ||
| const slackDisableTelemetryEnv = "SLACK_DISABLE_TELEMETRY" | ||
|
|
@@ -41,6 +42,7 @@ type Config struct { | |
| APIHostFlag string | ||
| APIHostResolved string | ||
| AppFlag string | ||
| AppIconPathFlag 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. 👾 thought: Interesting to find "app icon path" reads more clear than "CLI app icon path" but this ought not block decision on: - SLACK_APP_ICON_PATH
+ SLACK_CLI_APP_ICON_PATH🌲 ramble: I'm curious now again if "file" path needs to be specified in these values? Curious if path is clear enough on it's own...
Contributor
Author
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. i can change it to CLIAppIconPath! i was matching it to the other vars here but it doesnt have to |
||
| AutoRequestAAAFlag bool | ||
| ConfigDirFlag string | ||
| DebugEnabled bool | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,12 @@ func (c *Config) LoadEnvironmentVariables() error { | |
| c.ConfigDirFlag = configDir | ||
| } | ||
|
|
||
| // Load app icon path from environment variables | ||
| var appIconPath = strings.TrimSpace(c.os.Getenv(slackAppIconPathEnv)) | ||
|
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. 📠 issue: This might not capture values from the
Contributor
Author
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. yup all other env vars are read from system ! |
||
| if appIconPath != "" { | ||
| c.AppIconPathFlag = appIconPath | ||
| } | ||
|
|
||
| // Disable telemetry if either disable-telemetry or test-version environment variables | ||
| var disableTelemetry = strings.TrimSpace(c.os.Getenv(slackDisableTelemetryEnv)) | ||
| var testVersion = strings.TrimSpace(c.os.Getenv(version.EnvTestVersion)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,13 +218,7 @@ 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" | ||
| } | ||
| } | ||
|
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. 📸 thought: Keeping this inline might be alright to avoided redirected logic? ⛈️ ramble: I might suggest we instead also extract the "upload" logic that follows this since it's duplicated too, but I'd much prefer the |
||
| iconPath := resolveIconPath(ctx, clients, slackManifest.Icon) | ||
| if iconPath != "" { | ||
| err = updateIcon(ctx, clients, iconPath, app.AppID, token, manifest.IsFunctionRuntimeSlackHosted()) | ||
| if err != nil { | ||
|
|
@@ -524,12 +518,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(ctx, clients, slackManifest.Icon) | ||
| if iconPath != "" { | ||
| _, iconErr := clients.API().IconSet(ctx, clients.Fs, token, app.AppID, iconPath) | ||
| if iconErr != nil { | ||
|
|
@@ -649,6 +638,25 @@ func appendLocalToDisplayName(manifest *types.AppManifest) { | |
| } | ||
| } | ||
|
|
||
| // resolveIconPath determines the icon file path using the priority chain: | ||
| // SLACK_CLI_APP_ICON_PATH env var > manifest icon field > icon.png in project root | ||
| func resolveIconPath(ctx context.Context, clients *shared.ClientFactory, manifestIcon string) string { | ||
| if envIconPath := clients.Config.AppIconPathFlag; envIconPath != "" { | ||
| if _, err := os.Stat(envIconPath); !os.IsNotExist(err) { | ||
| return envIconPath | ||
| } | ||
|
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: Is this a check we should also include for |
||
| clients.IO.PrintDebug(ctx, "SLACK_CLI_APP_ICON_PATH file not found: %s", envIconPath) | ||
| _, _ = clients.IO.WriteOut().Write([]byte(style.SectionSecondaryf("Warning: icon path from SLACK_CLI_APP_ICON_PATH not found: %s", envIconPath))) | ||
|
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.
|
||
| } | ||
| if manifestIcon != "" { | ||
| return manifestIcon | ||
| } | ||
| if _, err := os.Stat("icon.png"); !os.IsNotExist(err) { | ||
| return "icon.png" | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| // 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 { | ||
| var span opentracing.Span | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.