forked from kyma-project/test-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (51 loc) · 1.64 KB
/
main.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
62
package main
import (
"flag"
"github.com/kyma-project/test-infra/pkg/jobguard/v2"
"os"
"github.com/sirupsen/logrus"
"k8s.io/test-infra/prow/config/secret"
"k8s.io/test-infra/prow/flagutil"
)
type options struct {
debug bool
dryRun bool
github flagutil.GitHubOptions
jobguardOptions v2.Options
expContextRegexp string
}
func gatherOptions(fs *flag.FlagSet, args ...string) options {
var o options
fs.BoolVar(&o.debug, "debug", false, "Enable debug logging.")
fs.BoolVar(&o.dryRun, "dry-run", false, "Enable dry run.")
fs.StringVar(&o.expContextRegexp, "expected-contexts-regexp", "", "Regular expression with expected contexts.")
o.jobguardOptions.AddFlags(fs)
o.github.AddFlags(fs)
fs.Parse(args)
return o
}
func main() {
o := gatherOptions(flag.NewFlagSet(os.Args[0], flag.ExitOnError), os.Args[1:]...)
if o.debug {
logrus.SetLevel(logrus.DebugLevel)
}
var token string
if o.github.TokenPath == "" {
logrus.Fatal("Missing github token path")
}
token = o.github.TokenPath
if err := secret.Add(token); err != nil {
logrus.WithError(err).Fatal("Could not start SecretAgent.")
}
logrus.Debugf("%+v", o)
githubStatus, err := o.github.GitHubClientWithLogFields(o.dryRun, logrus.Fields{"component": "github-status"})
if err != nil {
logrus.WithError(err).Fatal("Could not start GitHub client.")
}
o.jobguardOptions.PredicateFunc = v2.RegexpPredicate(o.expContextRegexp)
jobGuardClient := v2.NewClient(githubStatus, o.jobguardOptions)
if err := jobGuardClient.Run(); err != nil {
logrus.WithError(err).Fatal("JobGuard caught error.")
}
logrus.Infoln("All required checks have successful state.")
}