Chromium Code Reviews| Index: go/autoroll/autoroll.go |
| diff --git a/go/autoroll/autoroll.go b/go/autoroll/autoroll.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ef42e40b4b0fbb88d052efd5f7633df405893846 |
| --- /dev/null |
| +++ b/go/autoroll/autoroll.go |
| @@ -0,0 +1,76 @@ |
| +package autoroll |
| + |
| +/* |
| + Convenience functions for retrieving AutoRoll CLs. |
| +*/ |
| + |
| +import ( |
| + "time" |
| + |
| + "go.skia.org/infra/go/rietveld" |
| + "go.skia.org/infra/go/util" |
| +) |
| + |
| +const ( |
| + RIETVELD_URL = "https://codereview.chromium.org" |
| + OWNER = "skia-deps-roller@chromium.org" |
| +) |
| + |
| +var r = rietveld.Rietveld{ |
| + Url: RIETVELD_URL, |
| +} |
| + |
| +// AutoRollIssue is a trimmed-down rietveld.Issue containing just the |
| +// fields we care about for AutoRoll CLs. |
| +type AutoRollIssue struct { |
| + Closed bool |
| + Committed bool |
| + Issue int |
| + Modified time.Time |
| +} |
| + |
| +func search(limit int, terms ...*rietveld.SearchTerm) ([]*AutoRollIssue, error) { |
| + terms = append(terms, rietveld.SearchOwner(OWNER)) |
| + res, err := r.Search(limit, terms...) |
| + if err != nil { |
| + return nil, err |
| + } |
| + rv := make([]*AutoRollIssue, 0, len(res)) |
| + for _, i := range res { |
| + rv = append(rv, &AutoRollIssue{ |
| + Closed: i.Closed, |
| + Committed: i.Committed, |
| + Issue: i.Issue, |
| + Modified: i.Modified, |
| + }) |
| + } |
| + return rv, nil |
| +} |
| + |
| +// GetRecentRolls returns |
| +func GetRecentRolls(modifiedAfter time.Time) ([]*AutoRollIssue, error) { |
| + return search(1000, rietveld.SearchModifiedAfter(modifiedAfter)) |
|
rmistry
2015/06/10 20:20:54
Make 1000 a const? speaking of which isnt 1000 a l
borenet
2015/06/11 11:40:10
It was just an arbitrarily high number, since my a
|
| +} |
| + |
| +func GetLastNRolls(n int) ([]*AutoRollIssue, error) { |
| + issues, err := search(n) |
| + if err != nil { |
| + return nil, err |
| + } |
| + if len(issues) <= n { |
| + return issues, nil |
| + } |
| + return issues[:n], nil |
| +} |
| + |
| +func AutoRollStatusPoller() (*util.PollingStatus, error) { |
| + var v []*AutoRollIssue |
| + return util.NewPollingStatus(&v, func(value interface{}) error { |
| + res, err := GetLastNRolls(10) |
| + if err != nil { |
| + return err |
| + } |
| + *value.(*[]*AutoRollIssue) = res |
| + return nil |
| + }, 1*time.Minute) |
| +} |