// polyIgnoresAddHandler is for adding a new ignore rule. func polyIgnoresAddHandler(w http.ResponseWriter, r *http.Request) { user := login.LoggedInAs(r) if user == "" { util.ReportError(w, r, fmt.Errorf("Not logged in."), "You must be logged in to add an ignore rule.") return } req := &IgnoresRequest{} if err := parseJson(r, req); err != nil { util.ReportError(w, r, err, "Failed to parse submitted data.") return } if req.Filter == "" { util.ReportError(w, r, fmt.Errorf("Invalid Filter: %q", req.Filter), "Filters can't be empty.") return } d, err := human.ParseDuration(req.Duration) if err != nil { util.ReportError(w, r, err, "Failed to parse duration") return } ignoreRule := ignore.NewIgnoreRule(user, time.Now().Add(d), req.Filter, req.Note) if err != nil { util.ReportError(w, r, err, "Failed to create ignore rule.") return } if err = storages.IgnoreStore.Create(ignoreRule); err != nil { util.ReportError(w, r, err, "Failed to create ignore rule.") return } polyIgnoresJSONHandler(w, r) }
func _list(client traceservice.TraceServiceClient) (*traceservice.ListResponse, error) { req := &traceservice.ListRequest{} now := time.Now() b, err := human.ParseDuration(*begin) if err != nil { return nil, fmt.Errorf("Invalid begin value: %s", err) } e, err := human.ParseDuration(*end) if err != nil { return nil, fmt.Errorf("Invalid begin value: %s", err) } req.Begin = now.Add(-b).Unix() req.End = now.Add(-e).Unix() if *verbose { fmt.Printf("Requesting from %s to %s\n", now.Add(-b), now.Add(-e)) } return client.List(context.Background(), req) }
func main() { defer common.LogPanic() // Setup flags. dbConf := buildbot.DBConfigFromFlags() // Global init. common.InitWithMetrics(APP_NAME, graphiteServer) // Parse the time period. period, err := human.ParseDuration(*timePeriod) if err != nil { glog.Fatal(err) } // Initialize the buildbot database. if !*local { if err := dbConf.GetPasswordFromMetadata(); err != nil { glog.Fatal(err) } } if err := dbConf.InitDB(); err != nil { glog.Fatal(err) } // Initialize the BuildBucket client. c, err := auth.NewClient(*local, path.Join(*workdir, "oauth_token_cache"), buildbucket.DEFAULT_SCOPES...) if err != nil { glog.Fatal(err) } bb := buildbucket.NewClient(c) // Build the queue. repos := gitinfo.NewRepoMap(*workdir) for _, r := range REPOS { if _, err := repos.Repo(r); err != nil { glog.Fatal(err) } } q, err := build_queue.NewBuildQueue(period, repos, *scoreThreshold, *scoreDecay24Hr, BOT_BLACKLIST) if err != nil { glog.Fatal(err) } // Start scheduling builds in a loop. liveness := metrics.NewLiveness(APP_NAME) if err := scheduleBuilds(q, bb); err != nil { glog.Errorf("Failed to schedule builds: %v", err) } for _ = range time.Tick(time.Minute) { liveness.Update() if err := scheduleBuilds(q, bb); err != nil { glog.Errorf("Failed to schedule builds: %v", err) } } }
// commitsJSONHandler returns JSON info of a range of commits. // // Queries look like: // // /_/commits/?begin=h1&dur=h2&source=master // // Where: // - h1 and h2 are human time values, 2w, 3h, 1d, etc. Defaults // to begin=2w, dur=now(), where dur is the duration, i.e. the size // of the window. // - source is the source of the commits, like "master". Defaults // to "" which means include all sources. // // // Response is JSON of perftrace.CommitIDLong that looks like: // // [ // { // ts: 14070203, // id: "123abc", // source: "master", // author: "*****@*****.**", // desc: "Adds short commits." // }, // ... // ] // func commitsJSONHandler(w http.ResponseWriter, r *http.Request) { // Convert query params to time.Times. beginStr := r.FormValue("begin") if beginStr == "" { beginStr = "2w" } begin, err := human.ParseDuration(beginStr) if err != nil { util.ReportError(w, r, fmt.Errorf("Failed to parse duration."), "Invalid value for begin.") return } durStr := r.FormValue("dur") if durStr == "" { durStr = beginStr } dur, err := human.ParseDuration(durStr) if err != nil { util.ReportError(w, r, fmt.Errorf("Failed to parse duration."), "Invalid value for end.") return } if dur > begin { dur = begin } beginTime := time.Now().Add(-begin) endTime := beginTime.Add(dur) commits, err := branchTileBuilder.ListLong(beginTime, endTime, r.FormValue("source")) if err != nil { util.ReportError(w, r, err, "Failed to load commits") return } w.Header().Set("Content-Type", "application/json") enc := json.NewEncoder(w) if err := enc.Encode(commits); err != nil { glog.Errorf("Failed to write or encode output: %s", err) } }
func polyIgnoresUpdateHandler(w http.ResponseWriter, r *http.Request) { user := login.LoggedInAs(r) if user == "" { util.ReportError(w, r, fmt.Errorf("Not logged in."), "You must be logged in to update an ignore rule.") return } id, err := strconv.ParseInt(mux.Vars(r)["id"], 10, 0) if err != nil { util.ReportError(w, r, err, "ID must be valid integer.") return } req := &IgnoresRequest{} if err := parseJson(r, req); err != nil { util.ReportError(w, r, err, "Failed to parse submitted data.") return } if req.Filter == "" { util.ReportError(w, r, fmt.Errorf("Invalid Filter: %q", req.Filter), "Filters can't be empty.") return } d, err := human.ParseDuration(req.Duration) if err != nil { util.ReportError(w, r, err, "Failed to parse duration") return } ignoreRule := ignore.NewIgnoreRule(user, time.Now().Add(d), req.Filter, req.Note) if err != nil { util.ReportError(w, r, err, "Failed to create ignore rule.") return } ignoreRule.ID = int(id) err = storages.IgnoreStore.Update(int(id), ignoreRule) if err != nil { util.ReportError(w, r, err, "Unable to update ignore rule.") } else { // If update worked just list the current ignores and return them. polyIgnoresJSONHandler(w, r) } }