mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-02 04:32:23 +00:00
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
4edf385d1c
commit
987e85f261
3 changed files with 4 additions and 10 deletions
|
@ -3,11 +3,10 @@ package bolt
|
||||||
import (
|
import (
|
||||||
//"bytes"
|
//"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
"github.com/boltdb/bolt"
|
||||||
"github.com/drone/drone/common"
|
"github.com/drone/drone/common"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Build gets the specified build number for the
|
// Build gets the specified build number for the
|
||||||
|
@ -203,12 +202,13 @@ func (db *DB) SetBuildTask(repo string, build int, task *common.Task) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// check index to prevent nil pointer / panic
|
||||||
if task.Number > len(build_.Tasks) {
|
if task.Number > len(build_.Tasks) {
|
||||||
return ErrKeyNotFound
|
return ErrKeyNotFound
|
||||||
}
|
}
|
||||||
build_.Updated = time.Now().UTC().Unix()
|
build_.Updated = time.Now().UTC().Unix()
|
||||||
//assuming task number is 1-based.
|
//assuming task number is 1-based.
|
||||||
build_.Tasks[task.Number-1] = task // TODO check index to prevent nil pointer / panic
|
build_.Tasks[task.Number-1] = task
|
||||||
return update(t, bucketBuild, key, build_)
|
return update(t, bucketBuild, key, build_)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,10 +107,6 @@ func TestBuild(t *testing.T) {
|
||||||
db.SetBuild(repo, &common.Build{State: "success"})
|
db.SetBuild(repo, &common.Build{State: "success"})
|
||||||
err_ := db.SetBuildTask(repo, 1, &common.Task{Number: 1})
|
err_ := db.SetBuildTask(repo, 1, &common.Task{Number: 1})
|
||||||
g.Assert(err_).Equal(nil)
|
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,8 +89,6 @@ func PostBuildStatus(c *gin.Context) {
|
||||||
c.AbortWithStatus(400)
|
c.AbortWithStatus(400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//if err := store.SetStatus(repo.Name, num, in); err != nil {
|
|
||||||
if err := store.SetBuildStatus(repo.Name, num, in); err != nil {
|
if err := store.SetBuildStatus(repo.Name, num, in); err != nil {
|
||||||
c.Fail(400, err)
|
c.Fail(400, err)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue