mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 02:11:01 +00:00
endpoint to purge build logs
This commit is contained in:
parent
923de1c4f2
commit
cd0524e77e
2 changed files with 51 additions and 0 deletions
|
@ -103,6 +103,7 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl
|
|||
repo.POST("/builds/:number/approve", session.MustPush, server.PostApproval)
|
||||
repo.POST("/builds/:number/decline", session.MustPush, server.PostDecline)
|
||||
repo.DELETE("/builds/:number/:job", session.MustPush, server.DeleteBuild)
|
||||
repo.DELETE("/logs/:number", session.MustPush, server.DeleteBuildLogs)
|
||||
}
|
||||
|
||||
badges := e.Group("/api/badges/:owner/:name")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
@ -663,3 +664,52 @@ func PostBuild(c *gin.Context) {
|
|||
Config.Services.Queue.Push(context.Background(), task)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
///
|
||||
//
|
||||
|
||||
func DeleteBuildLogs(c *gin.Context) {
|
||||
repo := session.Repo(c)
|
||||
num, _ := strconv.Atoi(c.Params.ByName("number"))
|
||||
|
||||
build, err := store.GetBuildNumber(c, repo, num)
|
||||
if err != nil {
|
||||
c.AbortWithError(404, err)
|
||||
return
|
||||
}
|
||||
|
||||
procs, err := store.FromContext(c).ProcList(build)
|
||||
if err != nil {
|
||||
c.AbortWithError(404, err)
|
||||
return
|
||||
}
|
||||
|
||||
switch build.Status {
|
||||
case model.StatusRunning, model.StatusPending:
|
||||
c.String(400, "Cannot delete logs for a pending or running build")
|
||||
return
|
||||
}
|
||||
|
||||
for _, proc := range procs {
|
||||
buf := bytes.NewBufferString(fmt.Sprintf(deleteStr, proc.Name))
|
||||
lerr := store.FromContext(c).LogSave(proc, buf)
|
||||
if lerr != nil {
|
||||
err = lerr
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
c.String(400, "There was a problem deleting your logs. %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.String(204, "")
|
||||
}
|
||||
|
||||
var deleteStr = `[
|
||||
{
|
||||
"proc": %q,
|
||||
"pos": 0,
|
||||
"out": "LOGS PURGED\n"
|
||||
}
|
||||
]`
|
||||
|
|
Loading…
Reference in a new issue