func sendMapToPipeviz(m *ingest.Message, r *git.Repository) { addr, err := githelp.GetTargetAddr(r) // Find the target pipeviz instance from the git config if err != nil { log.Fatalln("Could not find target address in config:", err) } msg, err := json.Marshal(m) if err != nil { log.Fatalln("JSON encoding failed with err:", err) } //dump, _ := json.MarshalIndent(m, "", " ") //fmt.Println(string(dump)) client := http.Client{Timeout: 3 * time.Second} resp, err := client.Post(addr, "application/json", bytes.NewReader(msg)) if err != nil { log.Fatalln("Error on sending to server:", err) } if resp.StatusCode < 200 || resp.StatusCode >= 300 { bod, err := ioutil.ReadAll(resp.Body) resp.Body.Close() if err != nil { log.Fatalf(err.Error()) } log.Fatalln("Message rejected by pipeviz server: %v", string(bod)) } }
func (ic *instrumentCmd) run(cmd *cobra.Command, args []string) { var err error repo := getRepoOrExit(args...) // If we can't get an ident, error out _, err = githelp.GetRepoIdent(repo) if err != nil { log.Fatalf("Failed to retrieve a stable identifier for this repository; hooks will not work correctly. Aborting.") } if ic.target == "" { ic.target, err = githelp.GetTargetAddr(repo) if err != nil { log.Fatalf("No pipeviz server target provided, and one is not already registered in git's config.") } } else { cfg, err := repo.Config() if err != nil { log.Fatalln("Error attempting to retrieve git config", err) } err = cfg.SetString("pipeviz.target", ic.target) if err != nil { log.Fatalln("Error while writing pipeviz target to config", err) } fmt.Println("Set target pipeviz server to", ic.target) } // Write the post-commit hook, unless user said no if !ic.ncom { f, err := os.Create(repo.Path() + "/hooks/post-commit") if err != nil { log.Fatalln("Error while attempting to open post-commit hook for writing:", err) } tmpl, err := template.New("post-commit").Funcs(template.FuncMap{ "binpath": osext.Executable, }).Parse(postCommit) if err != nil { log.Fatalln("Error while parsing script template:", err) } err = tmpl.Execute(f, nil) if err != nil { log.Fatalln("Error while writing to post-commit hook file:", err) } f.Chmod(0755) fmt.Println("Wrote post-commit hook.") } // Write the post-checkout hook, unless user said no if !ic.ncheck { f, err := os.Create(repo.Path() + "/hooks/post-checkout") if err != nil { log.Fatalln("Error while attempting to open post-commit hook for writing:", err) } tmpl, err := template.New("post-checkout").Funcs(template.FuncMap{ "binpath": osext.Executable, }).Parse(postCheckout) if err != nil { log.Fatalln("Error while parsing script template:", err) } err = tmpl.Execute(f, nil) if err != nil { log.Fatalln("Error while writing to post-checkout hook file:", err) } f.Chmod(0755) fmt.Println("Wrote post-checkout hook.") } if ic.refs || ic.history { syncHistory(repo, ic.history) } //repo.Free() }