[MM-49989] Pass a context.Context to Client4 methods (#22922)

* Migrate all method in model/client4.go to accept a context.Context

* Fix th.*Client

* Fix remaining issues

* Empty commit to triger CI

* Fix test

* Add cancellation test

* Test that returned error is context.Canceled

* Fix bad merge

* Update mmctl code

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Ben Schumacher
2023-06-06 23:29:29 +02:00
коммит произвёл GitHub
родитель 7116e9267a
Коммит 6c82605df0
140 изменённых файлов: 7516 добавлений и 7333 удалений

Просмотреть файл

@@ -4,6 +4,7 @@
package commands
import (
"context"
"errors"
"fmt"
"net/http"
@@ -174,7 +175,7 @@ func createCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error
URL: url,
}
createdCommand, _, err := c.CreateCommand(newCommand)
createdCommand, _, err := c.CreateCommand(context.TODO(), newCommand)
if err != nil {
return errors.New("unable to create command '" + newCommand.DisplayName + "'. " + err.Error())
}
@@ -187,7 +188,7 @@ func createCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error
func listCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error {
var teams []*model.Team
if len(args) < 1 {
teamList, _, err := c.GetAllTeams("", 0, 10000)
teamList, _, err := c.GetAllTeams(context.TODO(), "", 0, 10000)
if err != nil {
return err
}
@@ -203,7 +204,7 @@ func listCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error {
errs = multierror.Append(errs, fmt.Errorf("unable to find team '%s'", args[i]))
continue
}
commands, _, err := c.ListCommands(team.Id, true)
commands, _, err := c.ListCommands(context.TODO(), team.Id, true)
if err != nil {
printer.PrintError("Unable to list commands for '" + team.Id + "'")
errs = multierror.Append(errs, fmt.Errorf("unable to list commands for '%s': %w", team.Id, err))
@@ -217,7 +218,7 @@ func listCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error {
}
func archiveCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error {
resp, err := c.DeleteCommand(args[0])
resp, err := c.DeleteCommand(context.TODO(), args[0])
if err != nil {
return errors.New("Unable to archive command '" + args[0] + "' error: " + err.Error())
}
@@ -289,7 +290,7 @@ func modifyCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error
}
}
modifiedCommand, _, err := c.UpdateCommand(command)
modifiedCommand, _, err := c.UpdateCommand(context.TODO(), command)
if err != nil {
return fmt.Errorf("unable to modify command '%s'. %s", command.DisplayName, err.Error())
}
@@ -311,7 +312,7 @@ func moveCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error {
return fmt.Errorf("unable to find command '%s'", args[1])
}
resp, err := c.MoveCommand(newTeam.Id, command.Id)
resp, err := c.MoveCommand(context.TODO(), newTeam.Id, command.Id)
if err != nil {
return fmt.Errorf("unable to move command '%s'. %s", command.Id, err.Error())
}