diff options
Diffstat (limited to 'tools/gerrit-hook/main.go')
| -rw-r--r-- | tools/gerrit-hook/main.go | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/tools/gerrit-hook/main.go b/tools/gerrit-hook/main.go deleted file mode 100644 index ccd2ad6..0000000 --- a/tools/gerrit-hook/main.go +++ /dev/null @@ -1,68 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "log/syslog" - "os" - "path" -) - -// config represents the configuration for the gerrit hook -type config struct { - GerritUrl string `json:"gerritUrl"` - GerritUser string `json:"gerritUser"` - GerritPassword string `json:"gerritPassword"` - BuildKiteToken string `json:"buildKiteToken"` - BuildKiteOrganization string `json:"buildKiteOrganization"` -} - -func loadConfig() (*config, error) { - configPath := "/var/run/agenix/gerrit/hooks" - - configJson, err := ioutil.ReadFile(configPath) - if err != nil { - return nil, fmt.Errorf("failed to read configuration file %s: %v", configPath, err) - } - - var cfg config - err = json.Unmarshal(configJson, &cfg) - if err != nil { - return nil, fmt.Errorf("failed to unmarshall configuration: %v", err) - } - - return &cfg, nil -} - -func main() { - log, err := syslog.New(syslog.LOG_INFO|syslog.LOG_USER, "gerrit-hook") - if err != nil { - fmt.Fprintf(os.Stderr, "failed to open syslog: %s\n", err) - os.Exit(1) - } - - log.Info(fmt.Sprintf("`gerrit-hook' called with arguments: %v\n", os.Args)) - - cmd := path.Base(os.Args[0]) - - cfg, err := loadConfig() - if err != nil { - os.Exit(1) - } - - switch cmd { - case "patchset-created": - trigger, err := triggerForPatchsetCreated() - if err != nil { - log.Crit(fmt.Sprintf("failed to create a trigger: %s", err)) - os.Exit(1) - } - gerritHookMain(cfg, log, trigger) - case "post-command": - postCommand(cfg) - default: - log.Info(fmt.Sprintf("`%s' is not a supported command", cmd)) - os.Exit(1) - } -} |
