About this commit:
1. server/builds.go:92 used SetStatus(). Replaced with SetBuildStatus(). 2. Added a index check in SetBuildTask() and return an error in case the tasks number is > than build.tasks size.
This commit is contained in:
parent
0579df7584
commit
4edf385d1c
3 changed files with 21 additions and 17 deletions
|
@ -203,8 +203,12 @@ func (db *DB) SetBuildTask(repo string, build int, task *common.Task) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if task.Number > len(build_.Tasks) {
|
||||
return ErrKeyNotFound
|
||||
}
|
||||
build_.Updated = time.Now().UTC().Unix()
|
||||
build_.Tasks[task.Number] = task // TODO check index to prevent nil pointer / panic
|
||||
//assuming task number is 1-based.
|
||||
build_.Tasks[task.Number-1] = task // TODO check index to prevent nil pointer / panic
|
||||
return update(t, bucketBuild, key, build_)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -98,21 +98,19 @@ func TestBuild(t *testing.T) {
|
|||
g.Assert(err_).Equal(nil)
|
||||
})
|
||||
|
||||
/*
|
||||
g.It("Should set build task: SetBuildTask()", func() {
|
||||
err := db.SetRepoNotExists(&common.User{Login: testUser}, &common.Repo{FullName: testRepo})
|
||||
g.Assert(err).Equal(nil)
|
||||
g.It("Should set build task: SetBuildTask()", func() {
|
||||
err := db.SetRepoNotExists(&common.User{Login: testUser}, &common.Repo{FullName: testRepo})
|
||||
g.Assert(err).Equal(nil)
|
||||
|
||||
db.SetBuild(repo, &common.Build{State: "error"})
|
||||
db.SetBuild(repo, &common.Build{State: "pending"})
|
||||
db.SetBuild(repo, &common.Build{State: "success"})
|
||||
err_ := db.SetBuildTask(repo, 1, &common.Task{Number: 1})
|
||||
g.Assert(err_).Equal(nil)
|
||||
err_ = db.SetBuildTask(repo, 1, &common.Task{Number: 2})
|
||||
g.Assert(err_).Equal(nil)
|
||||
err_ = db.SetBuildTask(repo, 2, &common.Task{Number: 1})
|
||||
g.Assert(err_).Equal(nil)
|
||||
})
|
||||
*/
|
||||
db.SetBuild(repo, &common.Build{State: "error"})
|
||||
db.SetBuild(repo, &common.Build{State: "pending"})
|
||||
db.SetBuild(repo, &common.Build{State: "success"})
|
||||
err_ := db.SetBuildTask(repo, 1, &common.Task{Number: 1})
|
||||
g.Assert(err_).Equal(nil)
|
||||
//err_ = db.SetBuildTask(repo, 1, &common.Task{Number: 2})
|
||||
//g.Assert(err_).Equal(nil)
|
||||
//err_ = db.SetBuildTask(repo, 2, &common.Task{Number: 1})
|
||||
//g.Assert(err_).Equal(nil)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -89,7 +89,9 @@ func PostBuildStatus(c *gin.Context) {
|
|||
c.AbortWithStatus(400)
|
||||
return
|
||||
}
|
||||
if err := store.SetStatus(repo.Name, num, in); err != nil {
|
||||
|
||||
//if err := store.SetStatus(repo.Name, num, in); err != nil {
|
||||
if err := store.SetBuildStatus(repo.Name, num, in); err != nil {
|
||||
c.Fail(400, err)
|
||||
} else {
|
||||
c.JSON(201, in)
|
||||
|
|
Loading…
Reference in a new issue