-
Notifications
You must be signed in to change notification settings - Fork 34
feat: add slack manifest diff command #591
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
fb3aa95
1a99403
5e518f0
79d0468
2a8816b
d58fd8e
db6aa47
1e70330
ea65069
9cab9ad
413f272
d1cf988
79d3a36
8370ed7
e585fa9
2093f53
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Copyright 2022-2026 Salesforce, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package manifest | ||
|
|
||
| import ( | ||
| "github.com/opentracing/opentracing-go" | ||
| "github.com/slackapi/slack-cli/internal/app" | ||
| "github.com/slackapi/slack-cli/internal/cmdutil" | ||
| "github.com/slackapi/slack-cli/internal/manifest" | ||
| "github.com/slackapi/slack-cli/internal/prompts" | ||
| "github.com/slackapi/slack-cli/internal/shared" | ||
| "github.com/slackapi/slack-cli/internal/style" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // NewDiffCommand implements the "manifest diff" command, which prints the | ||
| // differences between the project manifest and the app settings on Slack. | ||
| func NewDiffCommand(clients *shared.ClientFactory) *cobra.Command { | ||
| return &cobra.Command{ | ||
| Use: "diff", | ||
| Short: "Show differences between the project manifest and app settings", | ||
| Long: "Compare the project manifest with app settings and print any differences.", | ||
| Example: style.ExampleCommandsf([]style.ExampleCommand{ | ||
| {Command: "manifest diff", Meaning: "Show differences between project manifest and app settings"}, | ||
| {Command: "manifest diff --app A0123456789 --token xoxp-...", Meaning: "Show manifest differences without prompts"}, | ||
| }), | ||
| Args: cobra.NoArgs, | ||
| PreRunE: func(cmd *cobra.Command, args []string) error { | ||
| return cmdutil.IsValidProjectDirectory(clients) | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := cmd.Context() | ||
| span, ctx := opentracing.StartSpanFromContext(ctx, "cmd.manifest.diff") | ||
| defer span.Finish() | ||
|
|
||
| selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| clients.Config.ManifestEnv = app.SetManifestEnvTeamVars(clients.Config.ManifestEnv, selection.App.TeamDomain, selection.App.IsDev) | ||
|
|
||
| localManifest, err := clients.AppClient().Manifest.GetManifestLocal(ctx, clients.SDKConfig, clients.HookExecutor) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| remoteManifest, err := clients.AppClient().Manifest.GetManifestRemote(ctx, selection.Auth.Token, selection.App.AppID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| diffs, err := manifest.Diff(localManifest.AppManifest, remoteManifest.AppManifest) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if !diffs.HasDifferences() { | ||
| clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{ | ||
| Emoji: "books", | ||
| Text: "App Manifest", | ||
| Secondary: []string{"Project manifest and app settings match"}, | ||
| })) | ||
| return nil | ||
|
Member
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. note: We don't return a non-zero exit code when there is a manifest diff. Ideally, we should. However, |
||
| } | ||
|
|
||
| manifest.DisplayDiffs(ctx, clients.IO, diffs) | ||
| return nil | ||
| }, | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Copyright 2022-2026 Salesforce, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package manifest | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/slackapi/slack-cli/internal/app" | ||
| "github.com/slackapi/slack-cli/internal/hooks" | ||
| "github.com/slackapi/slack-cli/internal/prompts" | ||
| "github.com/slackapi/slack-cli/internal/shared" | ||
| "github.com/slackapi/slack-cli/internal/shared/types" | ||
| "github.com/slackapi/slack-cli/test/testutil" | ||
| "github.com/spf13/cobra" | ||
| "github.com/stretchr/testify/mock" | ||
| ) | ||
|
|
||
| func TestDiffCommand(t *testing.T) { | ||
| testutil.TableTestCommand(t, testutil.CommandTests{ | ||
| "prints match message when manifests match": { | ||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| appSelectMock := prompts.NewAppSelectMock() | ||
| appSelectPromptFunc = appSelectMock.AppSelectPrompt | ||
| appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return( | ||
| prompts.SelectedApp{ | ||
| App: types.App{AppID: "A001"}, | ||
| Auth: types.SlackAuth{Token: "xapp"}, | ||
| }, nil) | ||
| manifestMock := &app.ManifestMockObject{} | ||
| manifestMock.On("GetManifestLocal", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{ | ||
| AppManifest: types.AppManifest{ | ||
| DisplayInformation: types.DisplayInformation{Name: "App"}, | ||
| }, | ||
| }, nil) | ||
| manifestMock.On("GetManifestRemote", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{ | ||
| AppManifest: types.AppManifest{ | ||
| DisplayInformation: types.DisplayInformation{Name: "App"}, | ||
| }, | ||
| }, nil) | ||
| cf.AppClient().Manifest = manifestMock | ||
| cf.SDKConfig = hooks.NewSDKConfigMock() | ||
| }, | ||
| ExpectedOutputs: []string{"match"}, | ||
| }, | ||
| "prints differences when project and app settings disagree": { | ||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| appSelectMock := prompts.NewAppSelectMock() | ||
| appSelectPromptFunc = appSelectMock.AppSelectPrompt | ||
| appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return( | ||
| prompts.SelectedApp{ | ||
| App: types.App{AppID: "A002"}, | ||
| Auth: types.SlackAuth{Token: "xapp"}, | ||
| }, nil) | ||
| manifestMock := &app.ManifestMockObject{} | ||
| manifestMock.On("GetManifestLocal", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{ | ||
| AppManifest: types.AppManifest{ | ||
| DisplayInformation: types.DisplayInformation{Name: "Project Name"}, | ||
| }, | ||
| }, nil) | ||
| manifestMock.On("GetManifestRemote", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{ | ||
| AppManifest: types.AppManifest{ | ||
| DisplayInformation: types.DisplayInformation{Name: "Remote Name"}, | ||
| }, | ||
| }, nil) | ||
| cf.AppClient().Manifest = manifestMock | ||
| cf.SDKConfig = hooks.NewSDKConfigMock() | ||
| }, | ||
| ExpectedOutputs: []string{ | ||
| "display_information.name", | ||
| "Project Name", | ||
| "Remote Name", | ||
| }, | ||
| }, | ||
| }, func(clients *shared.ClientFactory) *cobra.Command { | ||
| return NewDiffCommand(clients) | ||
| }) | ||
| } |
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.
note: I feel we should say
App SettingsSlack API, but the CLI currently references App Settings, so I thought I'd stay consistent.