-
Notifications
You must be signed in to change notification settings - Fork 37
refactor: remove context.Background() references from hooks #50
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 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 |
|---|---|---|
|
|
@@ -206,7 +206,7 @@ func TestDoctorCheckProjectDeps(t *testing.T) { | |
| mockHookUpdate := `{"name": "deno_slack_hooks", "current": "2.6.0", "latest": "2.7.0", "breaking": false, "update": true}` | ||
| mockUpdate := fmt.Sprintf(`{"name": "the Slack SDK", "releases": [%s, %s, %s]}`, mockSDKUpdate, mockAPIUpdate, mockHookUpdate) | ||
| mockUpdateScript := hooks.HookScript{Command: "echo updates"} | ||
| cm.HookExecutor.On("Execute", hooks.HookExecOpts{Hook: mockUpdateScript}). | ||
| cm.HookExecutor.On("Execute", mock.Anything, hooks.HookExecOpts{Hook: mockUpdateScript}). | ||
| Return(mockUpdate, nil) | ||
| return shared.NewClientFactory(cm.MockClientFactory(), func(clients *shared.ClientFactory) { | ||
| clients.SDKConfig.WorkingDirectory = "." | ||
|
|
@@ -351,7 +351,7 @@ func TestDoctorCheckProjectTooling(t *testing.T) { | |
| mockHookSetup: func(cm *shared.ClientsMock) *shared.ClientFactory { | ||
| mockDoctorHook := `{"versions": [{"name": "deno", "current": "1.0.0"}, {"name": "typescript", "current": "5.4.3"}]}` | ||
| mockDoctorScript := hooks.HookScript{Command: "echo checkup"} | ||
| cm.HookExecutor.On("Execute", hooks.HookExecOpts{Hook: mockDoctorScript}). | ||
| cm.HookExecutor.On("Execute", mock.Anything, hooks.HookExecOpts{Hook: mockDoctorScript}). | ||
| Return(mockDoctorHook, nil) | ||
| return shared.NewClientFactory(cm.MockClientFactory(), func(clients *shared.ClientFactory) { | ||
| clients.SDKConfig.WorkingDirectory = "." | ||
|
|
@@ -379,7 +379,7 @@ func TestDoctorCheckProjectTooling(t *testing.T) { | |
| mockHookSetup: func(cm *shared.ClientsMock) *shared.ClientFactory { | ||
| mockDoctorHook := `{"versions": [{"name": "deno", "current": "1.0.0", "message": "Secure runtimes make safer code", "error": {"message": "Something isn't right with this installation"}}]}` | ||
| mockDoctorScript := hooks.HookScript{Command: "echo checkup"} | ||
| cm.HookExecutor.On("Execute", hooks.HookExecOpts{Hook: mockDoctorScript}). | ||
| cm.HookExecutor.On("Execute", mock.Anything, hooks.HookExecOpts{Hook: mockDoctorScript}). | ||
|
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: I know a few of these lines are getting longer and could be expanded to multiple lines, but I wanted to keep the changes low since this PR was already getting a little large. |
||
| Return(mockDoctorHook, nil) | ||
| return shared.NewClientFactory(cm.MockClientFactory(), func(clients *shared.ClientFactory) { | ||
| clients.SDKConfig.WorkingDirectory = "." | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,7 +167,7 @@ func doctorHook(ctx context.Context, clients *shared.ClientFactory) (DoctorHookJ | |
| var hookExecOpts = hooks.HookExecOpts{ | ||
| Hook: clients.SDKConfig.Hooks.Doctor, | ||
| } | ||
| getDoctorHookJSON, err := clients.HookExecutor.Execute(hookExecOpts) | ||
| getDoctorHookJSON, err := clients.HookExecutor.Execute(ctx, hookExecOpts) | ||
|
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: This is the final result of the work - the new signature is |
||
| if err != nil { | ||
| return DoctorHookJSON{}, err | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,7 +106,7 @@ func getManifestInfo(ctx context.Context, clients *shared.ClientFactory, cmd *co | |
| } | ||
| switch { | ||
| case source.Equals(config.MANIFEST_SOURCE_LOCAL): | ||
| return getManifestInfoProject(clients) | ||
| return getManifestInfoProject(ctx, clients) | ||
| case source.Equals(config.MANIFEST_SOURCE_REMOTE): | ||
| return getManifestInfoRemote(ctx, clients) | ||
|
Comment on lines
+109
to
111
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: It's nice to see that both |
||
| default: | ||
|
|
@@ -115,8 +115,9 @@ func getManifestInfo(ctx context.Context, clients *shared.ClientFactory, cmd *co | |
| } | ||
|
|
||
| // getManifestInfoProject gathers app manifest information from "get-manifest" | ||
| func getManifestInfoProject(clients *shared.ClientFactory) (types.AppManifest, error) { | ||
| func getManifestInfoProject(ctx context.Context, clients *shared.ClientFactory) (types.AppManifest, error) { | ||
| slackManifest, err := clients.AppClient().Manifest.GetManifestLocal( | ||
| ctx, | ||
| clients.SDKConfig, | ||
| clients.HookExecutor, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,7 +164,7 @@ func hasValidDeploymentMethod( | |
| } | ||
| switch { | ||
| case manifestSource.Equals(config.MANIFEST_SOURCE_LOCAL): | ||
| manifest, err = clients.AppClient().Manifest.GetManifestLocal(clients.SDKConfig, clients.HookExecutor) | ||
| manifest, err = clients.AppClient().Manifest.GetManifestLocal(ctx, clients.SDKConfig, clients.HookExecutor) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -212,7 +212,7 @@ func deployHook(ctx context.Context, clients *shared.ClientFactory) (*logger.Log | |
| shell := hooks.HookExecutorDefaultProtocol{ | ||
| IO: clients.IO, | ||
| } | ||
| if _, err := shell.Execute(hookExecOpts); err != nil { | ||
| if _, err := shell.Execute(ctx, hookExecOpts); err != nil { | ||
|
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. 🔭 This change is super great to find! |
||
| return &log, err | ||
| } | ||
| // Follow successful hook executions with a newline to match section formatting | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,7 +123,7 @@ func runCreateCommand(clients *shared.ClientFactory, cmd *cobra.Command) error { | |
|
|
||
| var triggerArg api.TriggerRequest | ||
| if createFlags.triggerDef != "" { | ||
| triggerArg, err = triggerRequestFromDef(clients, createFlags, app.IsDev) | ||
| triggerArg, err = triggerRequestFromDef(ctx, clients, createFlags, app.IsDev) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -305,7 +305,7 @@ func triggerRequestFromFlags(flags createCmdFlags, isDev bool) api.TriggerReques | |
| return req | ||
| } | ||
|
|
||
| func triggerRequestViaHook(clients *shared.ClientFactory, path string, isDev bool) (api.TriggerRequest, error) { | ||
| func triggerRequestViaHook(ctx context.Context, clients *shared.ClientFactory, path string, isDev bool) (api.TriggerRequest, error) { | ||
|
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: Example of the cascading changes to pass
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. @mwbrooks Legend ⭐ These changes seem tedious, but I am so hopeful that future changes can make use of the real |
||
| if !clients.SDKConfig.Hooks.GetTrigger.IsAvailable() { | ||
| return api.TriggerRequest{}, slackerror.New(slackerror.ErrSDKHookGetTriggerNotFound) | ||
| } | ||
|
|
@@ -319,6 +319,7 @@ func triggerRequestViaHook(clients *shared.ClientFactory, path string, isDev boo | |
| hookExecOpts.Env[name] = val | ||
| } | ||
| triggerDefAsStr, err := clients.HookExecutor.Execute( | ||
| ctx, | ||
| hookExecOpts, | ||
| ) | ||
| if err != nil { | ||
|
|
@@ -350,10 +351,10 @@ func triggerRequestFromJSONFile(clients *shared.ClientFactory, path string, isDe | |
| return req, nil | ||
| } | ||
|
|
||
| func triggerRequestFromDef(clients *shared.ClientFactory, flags createCmdFlags, isDev bool) (api.TriggerRequest, error) { | ||
| func triggerRequestFromDef(ctx context.Context, clients *shared.ClientFactory, flags createCmdFlags, isDev bool) (api.TriggerRequest, error) { | ||
| if strings.HasSuffix(flags.triggerDef, ".json") { | ||
| return triggerRequestFromJSONFile(clients, flags.triggerDef, isDev) | ||
| } | ||
|
|
||
| return triggerRequestViaHook(clients, flags.triggerDef, isDev) | ||
| return triggerRequestViaHook(ctx, clients, flags.triggerDef, isDev) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,7 +256,7 @@ func TestTriggersCreateCommand(t *testing.T) { | |
| appSelectTeardown = setupMockCreateAppSelection(installedProdApp) | ||
| // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods | ||
|
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. 📚 Unrelated to the changes of this PR, we might revisit these comments soon since setting up default mocks is seeming standard before customized mocks from what I can tell.
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. 🗒️ Good call! I'll add a note to loop back on this after I finish the context work. It almost looks like we can just remove this TODO because it's setting up the default mocks and then adding custom ones. 🤔 |
||
| clientsMock.AddDefaultMocks() | ||
| clientsMock.HookExecutor.On("Execute", mock.Anything).Return("", nil) | ||
| clientsMock.HookExecutor.On("Execute", mock.Anything, mock.Anything).Return("", nil) | ||
| err := clients.AppClient().SaveDeployed(ctx, fakeApp) | ||
| require.NoError(t, err, "Cant write apps.json") | ||
| }, | ||
|
|
@@ -275,7 +275,7 @@ func TestTriggersCreateCommand(t *testing.T) { | |
| Return(types.EVERYONE, []string{}, nil).Once() | ||
| // TODO: testing chicken and egg: we need the default mocks in place before we can use any of the `clients` methods | ||
| clientsMock.AddDefaultMocks() | ||
| clientsMock.HookExecutor.On("Execute", mock.Anything).Return(`{}`, nil) | ||
| clientsMock.HookExecutor.On("Execute", mock.Anything, mock.Anything).Return(`{}`, nil) | ||
| err := clients.AppClient().SaveDeployed(ctx, fakeApp) | ||
| require.NoError(t, err, "Cant write apps.json") | ||
| var content = `export default {}` | ||
|
|
@@ -287,7 +287,7 @@ func TestTriggersCreateCommand(t *testing.T) { | |
| appSelectTeardown() | ||
| }, | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) { | ||
| clientsMock.HookExecutor.AssertCalled(t, "Execute", mock.Anything) | ||
| clientsMock.HookExecutor.AssertCalled(t, "Execute", mock.Anything, mock.Anything) | ||
| clientsMock.ApiInterface.AssertCalled(t, "WorkflowsTriggersCreate", 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.
note: A common change is updating mocks to support the added
ctx context.Contextargument.