mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 13:28:25 +00:00
Add builds UI
This commit is contained in:
@@ -37,11 +37,13 @@ var upgrader = websocket.Upgrader{
|
||||
var pongWait = 60 * time.Second
|
||||
|
||||
type Message struct {
|
||||
Version int //
|
||||
Type int // message type, 1 register 2 error
|
||||
RunnerUUID string // runner uuid
|
||||
ErrCode int // error code
|
||||
ErrContent string // errors message
|
||||
Version int //
|
||||
Type int // message type, 1 register 2 error 3 task 4 no task
|
||||
RunnerUUID string // runner uuid
|
||||
ErrCode int // error code
|
||||
ErrContent string // errors message
|
||||
EventName string
|
||||
EventPayload string
|
||||
}
|
||||
|
||||
func Serve(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -112,7 +114,7 @@ MESSAGE_BUMP:
|
||||
Version: 1,
|
||||
Type: 2,
|
||||
ErrCode: 1,
|
||||
ErrContent: "type is not supported",
|
||||
ErrContent: fmt.Sprintf("message type %d is not supported", msg.Type),
|
||||
}
|
||||
bs, err := json.Marshal(&returnMsg)
|
||||
if err != nil {
|
||||
@@ -145,5 +147,42 @@ MESSAGE_BUMP:
|
||||
}
|
||||
|
||||
// TODO: find new task and send to client
|
||||
task, err := bots_model.GetCurTaskByUUID(msg.RunnerUUID)
|
||||
if err != nil {
|
||||
log.Error("websocket[%s] get task failed: %v", r.RemoteAddr, err)
|
||||
break
|
||||
}
|
||||
if task == nil {
|
||||
returnMsg := Message{
|
||||
Version: 1,
|
||||
Type: 4,
|
||||
}
|
||||
bs, err := json.Marshal(&returnMsg)
|
||||
if err != nil {
|
||||
log.Error("websocket[%s] marshal message failed: %v", r.RemoteAddr, err)
|
||||
break MESSAGE_BUMP
|
||||
}
|
||||
err = c.WriteMessage(mt, bs)
|
||||
if err != nil {
|
||||
log.Error("websocket[%s] sent message failed: %v", r.RemoteAddr, err)
|
||||
}
|
||||
} else {
|
||||
returnMsg := Message{
|
||||
Version: 1,
|
||||
Type: 3,
|
||||
EventName: task.Event.Event(),
|
||||
EventPayload: task.EventPayload,
|
||||
}
|
||||
bs, err := json.Marshal(&returnMsg)
|
||||
if err != nil {
|
||||
log.Error("websocket[%s] marshal message failed: %v", r.RemoteAddr, err)
|
||||
break
|
||||
}
|
||||
err = c.WriteMessage(mt, bs)
|
||||
if err != nil {
|
||||
log.Error("websocket[%s] sent message failed: %v", r.RemoteAddr, err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package builds
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
bots_model "code.gitea.io/gitea/models/bots"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
const (
|
||||
tplListBuilds base.TplName = "repo/builds/list"
|
||||
tplViewBuild base.TplName = "repo/builds/view"
|
||||
)
|
||||
|
||||
// MustEnableBuilds check if builds are enabled in settings
|
||||
func MustEnableBuilds(ctx *context.Context) {
|
||||
if unit.TypeBuilds.UnitGlobalDisabled() {
|
||||
ctx.NotFound("EnableTypeBuilds", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.Repo.Repository != nil {
|
||||
if !ctx.Repo.CanRead(unit.TypeBuilds) {
|
||||
ctx.NotFound("MustEnableBuilds", nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func List(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.builds")
|
||||
ctx.Data["PageIsBuildList"] = true
|
||||
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
opts := bots_model.FindTaskOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: page,
|
||||
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
|
||||
},
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
}
|
||||
if ctx.FormString("state") == "closed" {
|
||||
opts.IsClosed = util.OptionalBoolTrue
|
||||
} else {
|
||||
opts.IsClosed = util.OptionalBoolFalse
|
||||
}
|
||||
tasks, err := bots_model.FindTasks(opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err := tasks.LoadTriggerUser(); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
total, err := bots_model.CountTasks(opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Tasks"] = tasks
|
||||
|
||||
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5)
|
||||
pager.SetDefaultParams(ctx)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
ctx.HTML(http.StatusOK, tplListBuilds)
|
||||
}
|
||||
|
||||
func ViewBuild(ctx *context.Context) {
|
||||
index := ctx.ParamsInt64("index")
|
||||
task, err := bots_model.GetTaskByRepoAndIndex(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["PageIsBuildList"] = true
|
||||
ctx.Data["Build"] = task
|
||||
|
||||
ctx.HTML(http.StatusOK, tplViewBuild)
|
||||
}
|
||||
@@ -489,6 +489,15 @@ func SettingsPost(ctx *context.Context) {
|
||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePackages)
|
||||
}
|
||||
|
||||
if form.EnableBuilds && !unit_model.TypeBuilds.UnitGlobalDisabled() {
|
||||
units = append(units, repo_model.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: unit_model.TypeBuilds,
|
||||
})
|
||||
} else if !unit_model.TypeBuilds.UnitGlobalDisabled() {
|
||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeBuilds)
|
||||
}
|
||||
|
||||
if form.EnablePulls && !unit_model.TypePullRequests.UnitGlobalDisabled() {
|
||||
units = append(units, repo_model.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"code.gitea.io/gitea/routers/web/misc"
|
||||
"code.gitea.io/gitea/routers/web/org"
|
||||
"code.gitea.io/gitea/routers/web/repo"
|
||||
"code.gitea.io/gitea/routers/web/repo/builds"
|
||||
"code.gitea.io/gitea/routers/web/user"
|
||||
user_setting "code.gitea.io/gitea/routers/web/user/setting"
|
||||
"code.gitea.io/gitea/routers/web/user/setting/security"
|
||||
@@ -665,6 +666,7 @@ func RegisterRoutes(m *web.Route) {
|
||||
reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(unit.TypeIssues, unit.TypePullRequests)
|
||||
reqRepoProjectsReader := context.RequireRepoReader(unit.TypeProjects)
|
||||
reqRepoProjectsWriter := context.RequireRepoWriter(unit.TypeProjects)
|
||||
reqRepoBuildsReader := context.RequireRepoReader(unit.TypeBuilds)
|
||||
|
||||
reqPackageAccess := func(accessMode perm.AccessMode) func(ctx *context.Context) {
|
||||
return func(ctx *context.Context) {
|
||||
@@ -1169,6 +1171,13 @@ func RegisterRoutes(m *web.Route) {
|
||||
}, reqRepoProjectsWriter, context.RepoMustNotBeArchived())
|
||||
}, reqRepoProjectsReader, repo.MustEnableProjects)
|
||||
|
||||
m.Group("/builds", func() {
|
||||
m.Get("", builds.List)
|
||||
m.Group("/{index}", func() {
|
||||
m.Get("", builds.ViewBuild)
|
||||
})
|
||||
}, reqRepoBuildsReader, builds.MustEnableBuilds)
|
||||
|
||||
m.Group("/wiki", func() {
|
||||
m.Combo("/").
|
||||
Get(repo.Wiki).
|
||||
|
||||
Reference in New Issue
Block a user