forked from albertoleal/concourse-flake-hunter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.go
61 lines (49 loc) · 1.53 KB
/
search.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
49
50
51
52
53
54
55
56
57
58
59
60
61
package commands
import (
"fmt"
"regexp"
"github.com/albertoleal/concourse-flake-hunter/fly"
"github.com/albertoleal/concourse-flake-hunter/hunter"
"github.com/urfave/cli"
)
var SearchCommand = cli.Command{
Name: "search",
Usage: "search <arguments>",
Description: "Searches for flakes",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "show-one-offs",
Usage: "If set one off failures will be reported as well",
},
cli.IntFlag{
Name: "max-age, m",
Usage: "Lists builds that failed in the last n hours",
Value: -1,
},
},
Action: func(ctx *cli.Context) error {
if ctx.Args().First() == "" {
return cli.NewExitError("need to provide a pattern", 1)
}
client := ctx.App.Metadata["client"].(fly.Client)
searcher := hunter.NewSearcher(client)
spec := hunter.SearchSpec{
Pattern: regexp.MustCompile(ctx.Args().First()),
}
if ctx.Bool("show-one-offs") {
spec.ShowOneOffs = true
}
builds := searcher.Search(spec)
fmt.Printf("+-------+%-32s+%s\n", "----------------------------------", "-----------------------------------------------------")
fmt.Printf("| %-5s | %-32s | %s\n", "Ended", "Job", "Url")
fmt.Printf("+-------+%-32s+%s\n", "----------------------------------", "-----------------------------------------------------")
maxAge := ctx.Int("max-age")
for build := range builds {
if maxAge > 0 && age(build) > maxAge {
break
}
fmt.Printf("| %-5s | %-32s | %s\n", timeSince(build.EndTime), build.PipelineName+"/"+build.JobName, build.ConcourseURL)
}
return nil
},
}