add most tables
This commit is contained in:
@@ -147,7 +147,7 @@ MESSAGE_BUMP:
|
||||
}
|
||||
|
||||
// TODO: find new task and send to client
|
||||
task, err := bots_model.GetCurTaskByUUID(msg.RunnerUUID)
|
||||
task, err := bots_model.GetCurBuildByUUID(msg.RunnerUUID)
|
||||
if err != nil {
|
||||
log.Error("websocket[%s] get task failed: %v", r.RemoteAddr, err)
|
||||
break
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package builds
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
bots_model "code.gitea.io/gitea/models/bots"
|
||||
@@ -45,7 +46,7 @@ func List(ctx *context.Context) {
|
||||
page = 1
|
||||
}
|
||||
|
||||
opts := bots_model.FindTaskOptions{
|
||||
opts := bots_model.FindBuildOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: page,
|
||||
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
|
||||
@@ -57,24 +58,24 @@ func List(ctx *context.Context) {
|
||||
} else {
|
||||
opts.IsClosed = util.OptionalBoolFalse
|
||||
}
|
||||
tasks, err := bots_model.FindTasks(opts)
|
||||
builds, err := bots_model.FindBuilds(opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err := tasks.LoadTriggerUser(); err != nil {
|
||||
if err := builds.LoadTriggerUser(); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
total, err := bots_model.CountTasks(opts)
|
||||
total, err := bots_model.CountBuilds(opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Tasks"] = tasks
|
||||
ctx.Data["Builds"] = builds
|
||||
|
||||
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5)
|
||||
pager.SetDefaultParams(ctx)
|
||||
@@ -85,15 +86,64 @@ func List(ctx *context.Context) {
|
||||
|
||||
func ViewBuild(ctx *context.Context) {
|
||||
index := ctx.ParamsInt64("index")
|
||||
task, err := bots_model.GetTaskByRepoAndIndex(ctx.Repo.Repository.ID, index)
|
||||
build, err := bots_model.GetBuildByRepoAndIndex(ctx.Repo.Repository.ID, index)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Title"] = task.Title + " - " + ctx.Tr("repo.builds")
|
||||
ctx.Data["Title"] = build.Title + " - " + ctx.Tr("repo.builds")
|
||||
ctx.Data["PageIsBuildList"] = true
|
||||
ctx.Data["Build"] = task
|
||||
ctx.Data["Build"] = build
|
||||
statuses, err := bots_model.GetBuildWorkflows(build.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["WorkflowsStatuses"] = statuses
|
||||
|
||||
ctx.HTML(http.StatusOK, tplViewBuild)
|
||||
}
|
||||
|
||||
func GetBuildJobLogs(ctx *context.Context) {
|
||||
index := ctx.ParamsInt64("index")
|
||||
build, err := bots_model.GetBuildByRepoAndIndex(ctx.Repo.Repository.ID, index)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
workflows, err := bots_model.GetBuildWorkflows(build.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
var buildJob *bots_model.BuildJob
|
||||
wf := ctx.Params("workflow")
|
||||
jobname := ctx.Params("jobname")
|
||||
LOOP_WORKFLOWS:
|
||||
for workflow, jobs := range workflows {
|
||||
if workflow == wf {
|
||||
for _, job := range jobs {
|
||||
if jobname == job.Jobname {
|
||||
buildJob = job
|
||||
break LOOP_WORKFLOWS
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if buildJob == nil {
|
||||
ctx.Error(http.StatusNotFound, fmt.Sprintf("workflow %s job %s not exist", wf, jobname))
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: if buildJob.LogToFile is true, read the logs from the file
|
||||
|
||||
logs, err := bots_model.GetBuildLogs(build.ID, buildJob.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, logs)
|
||||
}
|
||||
|
||||
@@ -1175,6 +1175,7 @@ func RegisterRoutes(m *web.Route) {
|
||||
m.Get("", builds.List)
|
||||
m.Group("/{index}", func() {
|
||||
m.Get("", builds.ViewBuild)
|
||||
m.Get("/{workflow}/job/{jobname}/logs", builds.GetBuildJobLogs)
|
||||
})
|
||||
}, reqRepoBuildsReader, builds.MustEnableBuilds)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user