(ctx context.Context, c *cli.Command)
| 14 | ) |
| 15 | |
| 16 | func CollaboratorsAddAutoComplete(ctx context.Context, c *cli.Command) error { |
| 17 | var err error |
| 18 | appName := CurrentAppCompletion(ctx, c) |
| 19 | if appName == "" { |
| 20 | return nil |
| 21 | } |
| 22 | |
| 23 | apps, err := appsList(ctx) |
| 24 | if err != nil { |
| 25 | debug.Println("fail to get apps list:", err) |
| 26 | return nil |
| 27 | } |
| 28 | |
| 29 | client, err := config.ScalingoClient(ctx) |
| 30 | if err != nil { |
| 31 | return errors.Wrapf(ctx, err, "fail to get Scalingo client") |
| 32 | } |
| 33 | currentAppCollaborators, err := client.CollaboratorsList(ctx, appName) |
| 34 | if err != nil { |
| 35 | return nil |
| 36 | } |
| 37 | |
| 38 | var apiError error |
| 39 | ch := make(chan string) |
| 40 | var wg sync.WaitGroup |
| 41 | wg.Add(len(apps)) |
| 42 | for _, app := range apps { |
| 43 | go func(app *scalingo.App) { |
| 44 | defer wg.Done() |
| 45 | appCollaborators, erro := client.CollaboratorsList(ctx, app.Name) |
| 46 | if erro != nil { |
| 47 | config.C.Logger.Println(erro.Error()) |
| 48 | apiError = erro |
| 49 | return |
| 50 | } |
| 51 | for _, col := range appCollaborators { |
| 52 | ch <- col.Email |
| 53 | } |
| 54 | }(app) |
| 55 | } |
| 56 | |
| 57 | setEmails := make(map[string]bool) |
| 58 | go func() { |
| 59 | for content := range ch { |
| 60 | setEmails[content] = true |
| 61 | } |
| 62 | }() |
| 63 | wg.Wait() |
| 64 | close(ch) |
| 65 | |
| 66 | if apiError != nil { |
| 67 | return nil |
| 68 | } |
| 69 | |
| 70 | for email := range setEmails { |
| 71 | isAlreadyCollaborator := false |
| 72 | for _, currentAppCol := range currentAppCollaborators { |
| 73 | if currentAppCol.Email == email { |
no test coverage detected