mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-20 04:54:20 +00:00
ability to limit (or not) the log output
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
package bolt
|
package bolt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/drone/drone/common"
|
|
||||||
"github.com/boltdb/bolt"
|
"github.com/boltdb/bolt"
|
||||||
|
"github.com/drone/drone/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetTask gets the task at index N for the named
|
// GetTask gets the task at index N for the named
|
||||||
@@ -20,7 +22,7 @@ func (db *DB) GetTask(repo string, build int, task int) (*common.Task, error) {
|
|||||||
|
|
||||||
// GetTaskLogs gets the task logs at index N for
|
// GetTaskLogs gets the task logs at index N for
|
||||||
// the named repository and build number.
|
// the named repository and build number.
|
||||||
func (db *DB) GetTaskLogs(repo string, build int, task int) ([]byte, error) {
|
func (db *DB) GetTaskLogs(repo string, build int, task int) (io.Reader, error) {
|
||||||
key := []byte(repo + "/" + strconv.Itoa(build) + "/" + strconv.Itoa(task))
|
key := []byte(repo + "/" + strconv.Itoa(build) + "/" + strconv.Itoa(task))
|
||||||
|
|
||||||
var log []byte
|
var log []byte
|
||||||
@@ -29,8 +31,8 @@ func (db *DB) GetTaskLogs(repo string, build int, task int) ([]byte, error) {
|
|||||||
log, err = raw(t, bucketBuildLogs, key)
|
log, err = raw(t, bucketBuildLogs, key)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
buf := bytes.NewBuffer(log)
|
||||||
return log, err
|
return buf, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTaskList gets all tasks for the named repository
|
// GetTaskList gets all tasks for the named repository
|
||||||
|
@@ -33,4 +33,5 @@ func (db *DB) DeleteToken(token *common.Token) error {
|
|||||||
return db.Update(func(t *bolt.Tx) error {
|
return db.Update(func(t *bolt.Tx) error {
|
||||||
return delete(t, bucketUser, key)
|
return delete(t, bucketUser, key)
|
||||||
})
|
})
|
||||||
|
// TODO(bradrydzewski) remove token from users_token index
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,10 @@
|
|||||||
package datastore
|
package datastore
|
||||||
|
|
||||||
import "github.com/drone/drone/common"
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/drone/drone/common"
|
||||||
|
)
|
||||||
|
|
||||||
type Datastore interface {
|
type Datastore interface {
|
||||||
// GetUser gets a user by user login.
|
// GetUser gets a user by user login.
|
||||||
@@ -123,7 +127,7 @@ type Datastore interface {
|
|||||||
|
|
||||||
// GetTaskLogs gets the task logs at index N for
|
// GetTaskLogs gets the task logs at index N for
|
||||||
// the named repository and build number.
|
// the named repository and build number.
|
||||||
GetTaskLogs(string, int, int) ([]byte, error)
|
GetTaskLogs(string, int, int) (io.Reader, error)
|
||||||
|
|
||||||
// GetTaskList gets all tasks for the named repository
|
// GetTaskList gets all tasks for the named repository
|
||||||
// and build number.
|
// and build number.
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -54,13 +55,16 @@ func GetTasks(c *gin.Context) {
|
|||||||
func GetTaskLogs(c *gin.Context) {
|
func GetTaskLogs(c *gin.Context) {
|
||||||
ds := ToDatastore(c)
|
ds := ToDatastore(c)
|
||||||
repo := ToRepo(c)
|
repo := ToRepo(c)
|
||||||
|
full, _ := strconv.ParseBool(c.Params.ByName("full"))
|
||||||
build, _ := strconv.Atoi(c.Params.ByName("number"))
|
build, _ := strconv.Atoi(c.Params.ByName("number"))
|
||||||
task, _ := strconv.Atoi(c.Params.ByName("task"))
|
task, _ := strconv.Atoi(c.Params.ByName("task"))
|
||||||
|
|
||||||
logs, err := ds.GetTaskLogs(repo.FullName, build, task)
|
logs, err := ds.GetTaskLogs(repo.FullName, build, task)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.Fail(404, err)
|
||||||
|
} else if full {
|
||||||
|
io.Copy(c.Writer, logs)
|
||||||
} else {
|
} else {
|
||||||
c.Writer.Write(logs)
|
io.Copy(c.Writer, io.LimitReader(logs, 2000000))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user