added some initial code for build list. will revisit.
This commit is contained in:
parent
087f92f41f
commit
ab3df4bd65
2 changed files with 36 additions and 4 deletions
|
@ -26,10 +26,32 @@ func (db *DB) GetBuild(repo string, build int) (*common.Build, error) {
|
||||||
// GetBuildList gets a list of recent builds for the
|
// GetBuildList gets a list of recent builds for the
|
||||||
// named repository.
|
// named repository.
|
||||||
func (db *DB) GetBuildList(repo string) ([]*common.Build, error) {
|
func (db *DB) GetBuildList(repo string) ([]*common.Build, error) {
|
||||||
// get the last build sequence number (stored in key in `bucketBuildSeq`)
|
// TODO (bradrydzewski) we can do this more efficiently
|
||||||
// get all builds where build number > sequent-20
|
var builds []*common.Build
|
||||||
// github.com/foo/bar/{number}
|
build, err := db.GetBuildLast(repo)
|
||||||
return nil, nil
|
if err == ErrKeyNotFound {
|
||||||
|
return builds, nil
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.View(func(t *bolt.Tx) error {
|
||||||
|
pos := build.Number - 25
|
||||||
|
if pos < 1 {
|
||||||
|
pos = 1
|
||||||
|
}
|
||||||
|
for i := pos; i <= build.Number; i++ {
|
||||||
|
key := []byte(repo + "/" + strconv.Itoa(i))
|
||||||
|
build := &common.Build{}
|
||||||
|
err = get(t, bucketBuild, key, build)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
builds = append(builds, build)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return builds, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBuildLast gets the last executed build for the
|
// GetBuildLast gets the last executed build for the
|
||||||
|
|
|
@ -52,5 +52,15 @@ func TestBuild(t *testing.T) {
|
||||||
g.Assert(build.State).Equal("pending")
|
g.Assert(build.State).Equal("pending")
|
||||||
g.Assert(build.Number).Equal(3)
|
g.Assert(build.Number).Equal(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
g.It("Should get the recent list of builds", func() {
|
||||||
|
db.InsertBuild(repo, &common.Build{State: "success"})
|
||||||
|
db.InsertBuild(repo, &common.Build{State: "success"})
|
||||||
|
db.InsertBuild(repo, &common.Build{State: "pending"})
|
||||||
|
|
||||||
|
builds, err := db.GetBuildList(repo)
|
||||||
|
g.Assert(err).Equal(nil)
|
||||||
|
g.Assert(len(builds)).Equal(3)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue