1
1
mirror of https://github.com/go-gitea/gitea synced 2025-11-01 20:08:25 +00:00

add most tables

This commit is contained in:
Lunny Xiao
2022-05-05 00:39:20 +08:00
committed by Jason Song
parent 5a479bb034
commit 2c4f6fd42f
25 changed files with 598 additions and 1466 deletions

View File

@@ -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)
}