-
Notifications
You must be signed in to change notification settings - Fork 0
/
outputs.go
48 lines (37 loc) · 856 Bytes
/
outputs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"os/exec"
)
type output struct {
repos []string
out string
}
func outputs(repos []Repo, results chan result, group bool) ([]output, error) {
seen := make(map[string][]result)
for range repos {
result := <-results
if result.err != nil {
if _, ok := result.err.(*exec.ExitError); !ok {
return nil, result.err
}
}
var key string
if group {
key = result.out
} else {
key = result.repo.Path
}
seen[key] = append(seen[key], result)
}
outputs := make([]output, 0)
// Every result has the same out, if group is false, results should be a
// slice with len = 1.
for _, results := range seen {
repos := make([]string, len(results))
for i, result := range results {
repos[i] = result.repo.Path
}
outputs = append(outputs, output{repos, results[0].out})
}
return outputs, nil
}