diff --git a/models/actions/runner.go b/models/actions/runner.go index 0641659211a1..cb84794aa005 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/models/types" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/translation" @@ -28,7 +29,7 @@ type ActionRunner struct { Version string `xorm:"VARCHAR(64)"` OwnerID int64 `xorm:"index"` // org level runner, 0 means system Owner *user_model.User `xorm:"-"` - RepoID int64 `xorm:"index"` // repo level runner, if orgid also is zero, then it's a global + RepoID int64 `xorm:"index"` // repo level runner, if OwnerID also is zero, then it's a global Repo *repo_model.Repository `xorm:"-"` Description string `xorm:"TEXT"` Base int // 0 native 1 docker 2 virtual machine @@ -52,51 +53,25 @@ type ActionRunner struct { Deleted timeutil.TimeStamp `xorm:"deleted"` } -// RunnerType defines the runner type -type RunnerType int - -const ( - // RunnerTypeGlobal defines a global runner - RunnerTypeGlobal RunnerType = iota - - // RunnerTypeOrganization defines an organization runner - RunnerTypeOrganization - - // RunnerTypeRepository defines a repository runner - RunnerTypeRepository -) - -func (r *ActionRunner) Type() RunnerType { +// BelongsToOwnerName before calling, should guarantee that all attributes are loaded +func (r *ActionRunner) BelongsToOwnerName() string { if r.RepoID != 0 { - return RunnerTypeRepository + return r.Repo.FullName() } if r.OwnerID != 0 { - return RunnerTypeOrganization - } - return RunnerTypeGlobal -} - -func (rt RunnerType) LocaleString(locale translation.Locale) string { - switch rt { - case RunnerTypeGlobal: - return locale.Tr("actions.runners.global_type") - case RunnerTypeOrganization: - return locale.Tr("organization") - case RunnerTypeRepository: - return locale.Tr("repository") + return r.Owner.Name } - return locale.Tr("unknown") + return "" } -// Should guarantee that all attributes are loaded -func (r *ActionRunner) BelongsTo() string { +func (r *ActionRunner) BelongsToOwnerType() types.OwnerType { if r.RepoID != 0 { - return r.Repo.FullName() + return types.OwnerTypeRepository } if r.OwnerID != 0 { - return r.Owner.Name + return types.OwnerTypeOrganization } - return "" + return types.OwnerTypeSystemGlobal } func (r *ActionRunner) Status() runnerv1.RunnerStatus { diff --git a/models/types/ownertype.go b/models/types/ownertype.go new file mode 100644 index 000000000000..2f5ec1bd3cf5 --- /dev/null +++ b/models/types/ownertype.go @@ -0,0 +1,26 @@ +package types + +import "code.gitea.io/gitea/modules/translation" + +type OwnerType string + +const ( + OwnerTypeSystemGlobal = "system-global" + OwnerTypeIndividual = "individual" + OwnerTypeRepository = "repository" + OwnerTypeOrganization = "organization" +) + +func (o OwnerType) LocaleString(locale translation.Locale) string { + switch o { + case OwnerTypeSystemGlobal: + return locale.Tr("concept_system_global") + case OwnerTypeIndividual: + return locale.Tr("concept_person_individual") + case OwnerTypeRepository: + return locale.Tr("concept_code_repository") + case OwnerTypeOrganization: + return locale.Tr("concept_user_organization") + } + return locale.Tr("unknown") +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index b7faa76b0b8e..b2de33e68332 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -113,6 +113,11 @@ unknown = Unknown rss_feed = RSS Feed +concept_system_global = Global +concept_person_individual = Individual +concept_code_repository = Repository +concept_user_organization = Organization + [aria] navbar = Navigation Bar footer = Footer @@ -3409,7 +3414,6 @@ runners.status = Status runners.id = ID runners.name = Name runners.owner_type = Type -runners.type_global = Global runners.description = Description runners.labels = Labels runners.last_online = Last Online Time diff --git a/templates/shared/actions/runner_edit.tmpl b/templates/shared/actions/runner_edit.tmpl index ff12fbbcb4b2..657d565d643f 100644 --- a/templates/shared/actions/runner_edit.tmpl +++ b/templates/shared/actions/runner_edit.tmpl @@ -25,7 +25,7 @@
- {{.Runner.Type.LocaleString $.locale}} + {{.Runner.BelongsToOwnerType.LocaleString $.locale}}
diff --git a/templates/shared/actions/runner_list.tmpl b/templates/shared/actions/runner_list.tmpl index a92a4f18c9ce..7c786d880702 100644 --- a/templates/shared/actions/runner_list.tmpl +++ b/templates/shared/actions/runner_list.tmpl @@ -65,7 +65,7 @@ {{.ID}}

{{.Name}}

{{if .Version}}{{.Version}}{{else}}{{$.locale.Tr "unknown"}}{{end}} - {{.Type.LocaleString $.locale}} + {{.BelongsToOwnerType.LocaleString $.locale}} {{range .AllLabels}}{{.}}{{end}}