rename builds -> bots

This commit is contained in:
Lunny Xiao 2022-11-21 16:18:12 +08:00 committed by Jason Song
parent c61ac24c1c
commit 2ecb59c092
24 changed files with 81 additions and 78 deletions

View File

@ -56,7 +56,7 @@ func (Run) TableName() string {
} }
func (run *Run) HTMLURL() string { func (run *Run) HTMLURL() string {
return fmt.Sprintf("%s/builds/runs/%d", run.Repo.HTMLURL(), run.Index) return fmt.Sprintf("%s/bots/runs/%d", run.Repo.HTMLURL(), run.Index)
} }
// LoadAttributes load Repo TriggerUser if not loaded // LoadAttributes load Repo TriggerUser if not loaded

View File

@ -127,7 +127,7 @@ func (task *Task) GetBuildViewLink() string {
if task.Job == nil || task.Job.Run == nil || task.Job.Run.Repo == nil { if task.Job == nil || task.Job.Run == nil || task.Job.Run.Repo == nil {
return "" return ""
} }
return task.Job.Run.Repo.Link() + "/builds/runs/" + strconv.FormatInt(task.ID, 10) return task.Job.Run.Repo.Link() + "/bots/runs/" + strconv.FormatInt(task.ID, 10)
} }
func (task *Task) GetCommitLink() string { func (task *Task) GetCommitLink() string {

View File

@ -175,7 +175,7 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
r.Config = new(PullRequestsConfig) r.Config = new(PullRequestsConfig)
case unit.TypeIssues: case unit.TypeIssues:
r.Config = new(IssuesConfig) r.Config = new(IssuesConfig)
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects, unit.TypePackages, unit.TypeBuilds: case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects, unit.TypePackages, unit.TypeBots:
fallthrough fallthrough
default: default:
r.Config = new(UnitConfig) r.Config = new(UnitConfig)

View File

@ -28,7 +28,7 @@ const (
TypeExternalTracker // 7 ExternalTracker TypeExternalTracker // 7 ExternalTracker
TypeProjects // 8 Kanban board TypeProjects // 8 Kanban board
TypePackages // 9 Packages TypePackages // 9 Packages
TypeBuilds // 10 Builds TypeBots // 10 Bots
) )
// Value returns integer value for unit type // Value returns integer value for unit type
@ -56,8 +56,8 @@ func (u Type) String() string {
return "TypeProjects" return "TypeProjects"
case TypePackages: case TypePackages:
return "TypePackages" return "TypePackages"
case TypeBuilds: case TypeBots:
return "TypeBuilds" return "TypeBots"
} }
return fmt.Sprintf("Unknown Type %d", u) return fmt.Sprintf("Unknown Type %d", u)
} }
@ -81,7 +81,7 @@ var (
TypeExternalTracker, TypeExternalTracker,
TypeProjects, TypeProjects,
TypePackages, TypePackages,
TypeBuilds, TypeBots,
} }
// DefaultRepoUnits contains the default unit types // DefaultRepoUnits contains the default unit types
@ -293,11 +293,11 @@ var (
perm.AccessModeRead, perm.AccessModeRead,
} }
UnitBuilds = Unit{ UnitBots = Unit{
TypeBuilds, TypeBots,
"repo.builds", "repo.bots",
"/builds", "/bots",
"repo.builds.desc", "repo.bots.desc",
7, 7,
perm.AccessModeOwner, perm.AccessModeOwner,
} }
@ -313,7 +313,7 @@ var (
TypeExternalWiki: UnitExternalWiki, TypeExternalWiki: UnitExternalWiki,
TypeProjects: UnitProjects, TypeProjects: UnitProjects,
TypePackages: UnitPackages, TypePackages: UnitPackages,
TypeBuilds: UnitBuilds, TypeBots: UnitBots,
} }
) )

View File

@ -104,7 +104,7 @@ func TransferLogs(ctx context.Context, filename string) (func(), error) {
} }
defer f.Close() defer f.Close()
if _, err := storage.Builds.Save(filename, f, -1); err != nil { if _, err := storage.Bots.Save(filename, f, -1); err != nil {
return nil, fmt.Errorf("storage save %q: %w", filename, err) return nil, fmt.Errorf("storage save %q: %w", filename, err)
} }
return remove, nil return remove, nil
@ -119,7 +119,7 @@ func openLogs(ctx context.Context, inStorage bool, filename string) (io.ReadSeek
} }
return f, nil return f, nil
} }
f, err := storage.Builds.Open(filename) f, err := storage.Bots.Open(filename)
if err != nil { if err != nil {
return nil, fmt.Errorf("storage open %q: %w", filename, err) return nil, fmt.Errorf("storage open %q: %w", filename, err)
} }

View File

@ -807,7 +807,7 @@ func Contexter(ctx context.Context) func(next http.Handler) http.Handler {
ctx.Data["UnitIssuesGlobalDisabled"] = unit.TypeIssues.UnitGlobalDisabled() ctx.Data["UnitIssuesGlobalDisabled"] = unit.TypeIssues.UnitGlobalDisabled()
ctx.Data["UnitPullsGlobalDisabled"] = unit.TypePullRequests.UnitGlobalDisabled() ctx.Data["UnitPullsGlobalDisabled"] = unit.TypePullRequests.UnitGlobalDisabled()
ctx.Data["UnitProjectsGlobalDisabled"] = unit.TypeProjects.UnitGlobalDisabled() ctx.Data["UnitProjectsGlobalDisabled"] = unit.TypeProjects.UnitGlobalDisabled()
ctx.Data["UnitBuildsGlobalDisabled"] = unit.TypeBuilds.UnitGlobalDisabled() ctx.Data["UnitBotsGlobalDisabled"] = unit.TypeBots.UnitGlobalDisabled()
ctx.Data["locale"] = locale ctx.Data["locale"] = locale
ctx.Data["AllLangs"] = translation.AllLangs() ctx.Data["AllLangs"] = translation.AllLangs()

View File

@ -1043,7 +1043,7 @@ func UnitTypes() func(ctx *Context) {
ctx.Data["UnitTypeExternalTracker"] = unit_model.TypeExternalTracker ctx.Data["UnitTypeExternalTracker"] = unit_model.TypeExternalTracker
ctx.Data["UnitTypeProjects"] = unit_model.TypeProjects ctx.Data["UnitTypeProjects"] = unit_model.TypeProjects
ctx.Data["UnitTypePackages"] = unit_model.TypePackages ctx.Data["UnitTypePackages"] = unit_model.TypePackages
ctx.Data["UnitTypeBuilds"] = unit_model.TypeBuilds ctx.Data["UnitTypeBots"] = unit_model.TypeBots
} }
} }

View File

@ -45,12 +45,12 @@ func NewNotifier() base.Notifier {
} }
func notify(repo *repo_model.Repository, doer *user_model.User, ref string, evt webhook.HookEventType, payload api.Payloader) error { func notify(repo *repo_model.Repository, doer *user_model.User, ref string, evt webhook.HookEventType, payload api.Payloader) error {
if unit.TypeBuilds.UnitGlobalDisabled() { if unit.TypeBots.UnitGlobalDisabled() {
return nil return nil
} }
if err := repo.LoadUnits(db.DefaultContext); err != nil { if err := repo.LoadUnits(db.DefaultContext); err != nil {
return fmt.Errorf("repo.LoadUnits: %w", err) return fmt.Errorf("repo.LoadUnits: %w", err)
} else if !repo.UnitEnabled(unit.TypeBuilds) { } else if !repo.UnitEnabled(unit.TypeBots) {
return nil return nil
} }

View File

@ -20,10 +20,10 @@ var (
} }
) )
func newBuilds() { func newBots() {
sec := Cfg.Section("bots") sec := Cfg.Section("bots")
if err := sec.MapTo(&Bots); err != nil { if err := sec.MapTo(&Bots); err != nil {
log.Fatal("Failed to map Builds settings: %v", err) log.Fatal("Failed to map Bots settings: %v", err)
} }
Bots.Storage = getStorage("bots_log", "", nil) Bots.Storage = getStorage("bots_log", "", nil)

View File

@ -1079,7 +1079,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
newPackages() newPackages()
newBuilds() newBots()
if err = Cfg.Section("ui").MapTo(&UI); err != nil { if err = Cfg.Section("ui").MapTo(&UI); err != nil {
log.Fatal("Failed to map UI settings: %v", err) log.Fatal("Failed to map UI settings: %v", err)

View File

@ -127,8 +127,8 @@ var (
// Packages represents packages storage // Packages represents packages storage
Packages ObjectStorage Packages ObjectStorage
// Builds represents builds storage // Bots represents bots storage
Builds ObjectStorage Bots ObjectStorage
) )
// Init init the stoarge // Init init the stoarge
@ -200,6 +200,6 @@ func initPackages() (err error) {
func initBots() (err error) { func initBots() (err error) {
log.Info("Initialising Bots storage with type: %s", setting.Bots.Storage.Type) log.Info("Initialising Bots storage with type: %s", setting.Bots.Storage.Type)
Builds, err = NewStorage(setting.Bots.Storage.Type, &setting.Bots.Storage) Bots, err = NewStorage(setting.Bots.Storage.Type, &setting.Bots.Storage)
return err return err
} }

View File

@ -1227,11 +1227,11 @@ projects.open = Open
projects.close = Close projects.close = Close
projects.board.assigned_to = Assigned to projects.board.assigned_to = Assigned to
builds = Builds bots = Bots
builds.desc = Manage builds bots.desc = Manage bots
builds.opened_by = opened %[1]s by %[2]s bots.opened_by = opened %[1]s by %[2]s
builds.open_tab = %d Open bots.open_tab = %d Open
builds.closed_tab = %d Closed bots.closed_tab = %d Closed
issues.desc = Organize bug reports, tasks and milestones. issues.desc = Organize bug reports, tasks and milestones.
issues.filter_assignees = Filter Assignee issues.filter_assignees = Filter Assignee

View File

@ -1,8 +1,8 @@
// Copyright 2018 The Gitea Authors. All rights reserved. // Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package builds package bots
import ( import (
"net/http" "net/http"
@ -18,28 +18,28 @@ import (
) )
const ( const (
tplListBuilds base.TplName = "repo/builds/list" tplListBots base.TplName = "repo/bots/list"
tplViewBuild base.TplName = "repo/builds/view" tplViewBuild base.TplName = "repo/bots/view"
) )
// MustEnableBuilds check if builds are enabled in settings // MustEnableBots check if bots are enabled in settings
func MustEnableBuilds(ctx *context.Context) { func MustEnableBots(ctx *context.Context) {
if unit.TypeBuilds.UnitGlobalDisabled() { if unit.TypeBots.UnitGlobalDisabled() {
ctx.NotFound("EnableTypeBuilds", nil) ctx.NotFound("MustEnableBots", nil)
return return
} }
if ctx.Repo.Repository != nil { if ctx.Repo.Repository != nil {
if !ctx.Repo.CanRead(unit.TypeBuilds) { if !ctx.Repo.CanRead(unit.TypeBots) {
ctx.NotFound("MustEnableBuilds", nil) ctx.NotFound("MustEnableBots", nil)
return return
} }
} }
} }
func List(ctx *context.Context) { func List(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.builds") ctx.Data["Title"] = ctx.Tr("repo.bots")
ctx.Data["PageIsBuilds"] = true ctx.Data["PageIsBots"] = true
defaultBranch, err := ctx.Repo.GitRepo.GetDefaultBranch() defaultBranch, err := ctx.Repo.GitRepo.GetDefaultBranch()
if err != nil { if err != nil {
@ -118,11 +118,11 @@ func List(ctx *context.Context) {
return return
} }
ctx.Data["Builds"] = runs ctx.Data["Runs"] = runs
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5) pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5)
pager.SetDefaultParams(ctx) pager.SetDefaultParams(ctx)
ctx.Data["Page"] = pager ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplListBuilds) ctx.HTML(http.StatusOK, tplListBots)
} }

View File

@ -1,4 +1,8 @@
package builds // Copyright 2022 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 bots
import ( import (
"context" "context"
@ -18,7 +22,7 @@ import (
) )
func View(ctx *context_module.Context) { func View(ctx *context_module.Context) {
ctx.Data["PageIsBuilds"] = true ctx.Data["PageIsBots"] = true
runIndex := ctx.ParamsInt64("run") runIndex := ctx.ParamsInt64("run")
jobIndex := ctx.ParamsInt64("job") jobIndex := ctx.ParamsInt64("job")
ctx.Data["RunIndex"] = runIndex ctx.Data["RunIndex"] = runIndex
@ -31,7 +35,6 @@ func View(ctx *context_module.Context) {
run := job.Run run := job.Run
ctx.Data["Build"] = run ctx.Data["Build"] = run
// ctx.Data["Build"] = &bots_model.Run{Title: "test", Index: 123, Status: bots_model.StatusRunning}
ctx.HTML(http.StatusOK, tplViewBuild) ctx.HTML(http.StatusOK, tplViewBuild)
} }

View File

@ -490,13 +490,13 @@ func SettingsPost(ctx *context.Context) {
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePackages) deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePackages)
} }
if form.EnableBuilds && !unit_model.TypeBuilds.UnitGlobalDisabled() { if form.EnableBots && !unit_model.TypeBots.UnitGlobalDisabled() {
units = append(units, repo_model.RepoUnit{ units = append(units, repo_model.RepoUnit{
RepoID: repo.ID, RepoID: repo.ID,
Type: unit_model.TypeBuilds, Type: unit_model.TypeBots,
}) })
} else if !unit_model.TypeBuilds.UnitGlobalDisabled() { } else if !unit_model.TypeBots.UnitGlobalDisabled() {
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeBuilds) deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeBots)
} }
if form.EnablePulls && !unit_model.TypePullRequests.UnitGlobalDisabled() { if form.EnablePulls && !unit_model.TypePullRequests.UnitGlobalDisabled() {

View File

@ -36,7 +36,7 @@ import (
"code.gitea.io/gitea/routers/web/misc" "code.gitea.io/gitea/routers/web/misc"
"code.gitea.io/gitea/routers/web/org" "code.gitea.io/gitea/routers/web/org"
"code.gitea.io/gitea/routers/web/repo" "code.gitea.io/gitea/routers/web/repo"
"code.gitea.io/gitea/routers/web/repo/builds" "code.gitea.io/gitea/routers/web/repo/bots"
"code.gitea.io/gitea/routers/web/user" "code.gitea.io/gitea/routers/web/user"
user_setting "code.gitea.io/gitea/routers/web/user/setting" user_setting "code.gitea.io/gitea/routers/web/user/setting"
"code.gitea.io/gitea/routers/web/user/setting/security" "code.gitea.io/gitea/routers/web/user/setting/security"
@ -679,7 +679,7 @@ func RegisterRoutes(m *web.Route) {
reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(unit.TypeIssues, unit.TypePullRequests) reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(unit.TypeIssues, unit.TypePullRequests)
reqRepoProjectsReader := context.RequireRepoReader(unit.TypeProjects) reqRepoProjectsReader := context.RequireRepoReader(unit.TypeProjects)
reqRepoProjectsWriter := context.RequireRepoWriter(unit.TypeProjects) reqRepoProjectsWriter := context.RequireRepoWriter(unit.TypeProjects)
reqRepoBuildsReader := context.RequireRepoReader(unit.TypeBuilds) reqRepoBotsReader := context.RequireRepoReader(unit.TypeBots)
reqPackageAccess := func(accessMode perm.AccessMode) func(ctx *context.Context) { reqPackageAccess := func(accessMode perm.AccessMode) func(ctx *context.Context) {
return func(ctx *context.Context) { return func(ctx *context.Context) {
@ -1212,22 +1212,22 @@ func RegisterRoutes(m *web.Route) {
}, reqRepoProjectsWriter, context.RepoMustNotBeArchived()) }, reqRepoProjectsWriter, context.RepoMustNotBeArchived())
}, reqRepoProjectsReader, repo.MustEnableProjects) }, reqRepoProjectsReader, repo.MustEnableProjects)
m.Group("/builds", func() { m.Group("/bots", func() {
m.Get("", builds.List) m.Get("", bots.List)
m.Group("/runs/{run}", func() { m.Group("/runs/{run}", func() {
m.Combo(""). m.Combo("").
Get(builds.View). Get(bots.View).
Post(bindIgnErr(builds.ViewRequest{}), builds.ViewPost) Post(bindIgnErr(bots.ViewRequest{}), bots.ViewPost)
m.Group("/jobs/{job}", func() { m.Group("/jobs/{job}", func() {
m.Combo(""). m.Combo("").
Get(builds.View). Get(bots.View).
Post(bindIgnErr(builds.ViewRequest{}), builds.ViewPost) Post(bindIgnErr(bots.ViewRequest{}), bots.ViewPost)
m.Post("/rerun", builds.Rerun) m.Post("/rerun", bots.Rerun)
}) })
m.Post("/cancel", builds.Cancel) m.Post("/cancel", bots.Cancel)
}) })
}, reqRepoBuildsReader, builds.MustEnableBuilds) }, reqRepoBotsReader, bots.MustEnableBots)
m.Group("/wiki", func() { m.Group("/wiki", func() {
m.Combo("/"). m.Combo("/").

View File

@ -148,7 +148,7 @@ type RepoSettingForm struct {
EnableProjects bool EnableProjects bool
EnablePackages bool EnablePackages bool
EnablePulls bool EnablePulls bool
EnableBuilds bool EnableBots bool
PullsIgnoreWhitespace bool PullsIgnoreWhitespace bool
PullsAllowMerge bool PullsAllowMerge bool
PullsAllowRebase bool PullsAllowRebase bool

View File

@ -1,8 +1,8 @@
<div class="issue list"> <div class="issue list">
{{range .Builds}} {{range .Runs}}
<li class="item df py-3"> <li class="item df py-3">
<div class="issue-item-left df"> <div class="issue-item-left df">
{{template "repo/builds/status" .Status}} {{template "repo/bots/status" .Status}}
</div> </div>
<div class="issue-item-main f1 fc df"> <div class="issue-item-main f1 fc df">
<div class="issue-item-top-row"> <div class="issue-item-top-row">

View File

@ -16,12 +16,12 @@
<div class="twelve wide column content"> <div class="twelve wide column content">
<div id="issue-filters" class="ui stackable grid"> <div id="issue-filters" class="ui stackable grid">
<div class="six wide column"> <div class="six wide column">
{{template "repo/builds/openclose" .}} {{template "repo/bots/openclose" .}}
</div> </div>
</div> </div>
<div id="issue-actions" class="ui stackable grid hide"> <div id="issue-actions" class="ui stackable grid hide">
<div class="six wide column"> <div class="six wide column">
{{template "repo/builds/openclose" .}} {{template "repo/bots/openclose" .}}
</div> </div>
<div class="ui divider"></div> <div class="ui divider"></div>
{{/* Ten wide does not cope well and makes the columns stack. {{/* Ten wide does not cope well and makes the columns stack.
@ -41,7 +41,7 @@
</div> </div>
</div> </div>
</div> </div>
{{template "repo/builds/build_list" .}} {{template "repo/bots/build_list" .}}
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,10 +1,10 @@
<div class="ui compact tiny menu"> <div class="ui compact tiny menu">
<a class="{{if not .IsShowClosed}}active{{end}} item" href="{{$.Link}}?workflow={{.CurWorkflow}}&state=open"> <a class="{{if not .IsShowClosed}}active{{end}} item" href="{{$.Link}}?workflow={{.CurWorkflow}}&state=open">
{{svg "octicon-issue-opened" 16 "mr-3"}} {{svg "octicon-issue-opened" 16 "mr-3"}}
{{.locale.Tr "repo.builds.open_tab" $.NumOpenRuns}} {{.locale.Tr "repo.bots.open_tab" $.NumOpenRuns}}
</a> </a>
<a class="{{if .IsShowClosed}}active{{end}} item" href="{{$.Link}}?workflow={{.CurWorkflow}}&state=closed"> <a class="{{if .IsShowClosed}}active{{end}} item" href="{{$.Link}}?workflow={{.CurWorkflow}}&state=closed">
{{svg "octicon-issue-closed" 16 "mr-3"}} {{svg "octicon-issue-closed" 16 "mr-3"}}
{{.locale.Tr "repo.builds.closed_tab" $.NumClosedRuns}} {{.locale.Tr "repo.bots.closed_tab" $.NumClosedRuns}}
</a> </a>
</div> </div>

View File

@ -183,9 +183,9 @@
</a> </a>
{{end}} {{end}}
{{ if and (not .UnitBuildsGlobalDisabled) (.Permission.CanRead $.UnitTypeBuilds)}} {{ if and (not .UnitBotsGlobalDisabled) (.Permission.CanRead $.UnitTypeBots)}}
<a class="{{if .PageIsBuilds}}active{{end}} item" href="{{.RepoLink}}/builds"> <a class="{{if .PageIsBots}}active{{end}} item" href="{{.RepoLink}}/bots">
{{svg "octicon-play"}} {{.locale.Tr "repo.builds"}} {{svg "octicon-play"}} {{.locale.Tr "repo.bots"}}
{{if .Repository.NumOpenRuns}} {{if .Repository.NumOpenRuns}}
<span class="ui blue small label">{{CountFmt .Repository.NumOpenRuns}}</span> <span class="ui blue small label">{{CountFmt .Repository.NumOpenRuns}}</span>
{{end}} {{end}}

View File

@ -420,16 +420,16 @@
</div> </div>
</div> </div>
{{$isBuildsEnabled := .Repository.UnitEnabled $.UnitTypeBuilds}} {{$isBotsEnabled := .Repository.UnitEnabled $.UnitTypeBots}}
<div class="inline field"> <div class="inline field">
<label>{{.locale.Tr "repo.builds"}}</label> <label>{{.locale.Tr "repo.bots"}}</label>
{{if .UnitTypeBuilds.UnitGlobalDisabled}} {{if .UnitTypeBots.UnitGlobalDisabled}}
<div class="ui checkbox tooltip disabled" data-content="{{.locale.Tr "repo.unit_disabled"}}"> <div class="ui checkbox tooltip disabled" data-content="{{.locale.Tr "repo.unit_disabled"}}">
{{else}} {{else}}
<div class="ui checkbox"> <div class="ui checkbox">
{{end}} {{end}}
<input class="enable-system" name="enable_builds" type="checkbox" {{if $isBuildsEnabled}}checked{{end}}> <input class="enable-system" name="enable_bots" type="checkbox" {{if $isBotsEnabled}}checked{{end}}>
<label>{{.locale.Tr "repo.settings.builds_desc"}}</label> <label>{{.locale.Tr "repo.settings.bots_desc"}}</label>
</div> </div>
</div> </div>