delete unused structs

This commit is contained in:
Lunny Xiao
2022-10-16 23:11:28 +08:00
committed by Jason Song
parent 4c2d976629
commit 482832da76
19 changed files with 190 additions and 782 deletions

View File

@@ -5,7 +5,6 @@
package builds
import (
"fmt"
"net/http"
bots_model "code.gitea.io/gitea/models/bots"
@@ -46,7 +45,7 @@ func List(ctx *context.Context) {
page = 1
}
opts := bots_model.FindBuildOptions{
opts := bots_model.FindRunOptions{
ListOptions: db.ListOptions{
Page: page,
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
@@ -58,7 +57,7 @@ func List(ctx *context.Context) {
} else {
opts.IsClosed = util.OptionalBoolFalse
}
builds, err := bots_model.FindBuilds(opts)
builds, total, err := bots_model.FindRuns(ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return
@@ -69,12 +68,6 @@ func List(ctx *context.Context) {
return
}
total, err := bots_model.CountBuilds(opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return
}
ctx.Data["Builds"] = builds
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5)
@@ -83,67 +76,3 @@ func List(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplListBuilds)
}
func ViewBuild(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
}
ctx.Data["Name"] = build.Name + " - " + ctx.Tr("repo.builds")
ctx.Data["PageIsBuildList"] = true
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.BuildStage
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.Name {
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)
}

View File

@@ -1189,10 +1189,14 @@ func RegisterRoutes(m *web.Route) {
m.Group("/builds", func() {
m.Get("", builds.List)
m.Group("/{index}", func() {
m.Get("", builds.ViewBuild)
m.Get("/{workflow}/job/{jobname}/logs", builds.GetBuildJobLogs)
})
m.Combo("/run/{runid}").
Get(dev.BuildView).
Post(bindIgnErr(dev.BuildViewRequest{}), dev.BuildViewPost)
m.Combo("/run/{runid}/jobs/{jobid}").
Get(dev.BuildView).
Post(bindIgnErr(dev.BuildViewRequest{}), dev.BuildViewPost)
}, reqRepoBuildsReader, builds.MustEnableBuilds)
m.Group("/wiki", func() {