+
{{.Runner.StatusLocaleName $.locale}}
-
+
{{if .LastOnline}}{{TimeSinceUnix .LastOnline $.locale}}{{else}}{{$.locale.Tr "never"}}{{end}}
-
+
{{range .Runner.AgentLabels}}
@@ -23,9 +23,9 @@
{{end}}
-
+
- {{.Runner.Type.String}}
+ {{.Runner.Type.LocaleString $.locale}}
diff --git a/templates/shared/actions/runner_list.tmpl b/templates/shared/actions/runner_list.tmpl
index cc9be78b04d6f..a92a4f18c9ce0 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.String}} |
+
{{.Type.LocaleString $.locale}} |
{{range .AllLabels}}{{.}}{{end}}
|
From b883b8ac780be178eee09dddd8a2bc00e0c7fa98 Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Tue, 2 May 2023 00:40:41 +0000
Subject: [PATCH 06/11] add a comment to func belongsto
---
models/actions/runner.go | 1 +
1 file changed, 1 insertion(+)
diff --git a/models/actions/runner.go b/models/actions/runner.go
index 792dbe83a17b5..18eeeab40f6c5 100644
--- a/models/actions/runner.go
+++ b/models/actions/runner.go
@@ -88,6 +88,7 @@ func (rt RunnerType) LocaleString(locale translation.Locale) string {
return locale.Tr("actions.runners.owner_type.unknown", rt)
}
+// Should guarantee that all attributes are loaded
func (r *ActionRunner) BelongsTo() string {
if r.RepoID != 0 {
return r.Repo.FullName()
From e34d55a5e119400e61693c53971ee4baa8422ff7 Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Mon, 8 May 2023 05:05:59 +0000
Subject: [PATCH 07/11] use global locale
---
models/actions/runner.go | 8 ++++----
options/locale/locale_en-US.ini | 5 +----
2 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/models/actions/runner.go b/models/actions/runner.go
index 18eeeab40f6c5..0641659211a12 100644
--- a/models/actions/runner.go
+++ b/models/actions/runner.go
@@ -79,13 +79,13 @@ func (r *ActionRunner) Type() RunnerType {
func (rt RunnerType) LocaleString(locale translation.Locale) string {
switch rt {
case RunnerTypeGlobal:
- return locale.Tr("actions.runners.owner_type.global")
+ return locale.Tr("actions.runners.global_type")
case RunnerTypeOrganization:
- return locale.Tr("actions.runners.owner_type.organization")
+ return locale.Tr("organization")
case RunnerTypeRepository:
- return locale.Tr("actions.runners.owner_type.repository")
+ return locale.Tr("repository")
}
- return locale.Tr("actions.runners.owner_type.unknown", rt)
+ return locale.Tr("unknown")
}
// Should guarantee that all attributes are loaded
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 92d03aa69e675..ea6727cd01b00 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -3394,10 +3394,7 @@ runners.status = Status
runners.id = ID
runners.name = Name
runners.owner_type = Type
-runners.owner_type.unknown = Unknown type: %s
-runners.owner_type.global = Global
-runners.owner_type.organization = Organization
-runners.owner_type.repository = Repository
+runners.type_global = Global
runners.description = Description
runners.labels = Labels
runners.last_online = Last Online Time
From 20b6817856e1a85b8b75d01cc00f2634823441d4 Mon Sep 17 00:00:00 2001
From: wxiaoguang
Date: Mon, 8 May 2023 17:44:30 +0800
Subject: [PATCH 08/11] introduce OwnerType
---
models/actions/runner.go | 47 ++++++-----------------
models/types/ownertype.go | 26 +++++++++++++
options/locale/locale_en-US.ini | 6 ++-
templates/shared/actions/runner_edit.tmpl | 2 +-
templates/shared/actions/runner_list.tmpl | 2 +-
5 files changed, 44 insertions(+), 39 deletions(-)
create mode 100644 models/types/ownertype.go
diff --git a/models/actions/runner.go b/models/actions/runner.go
index 0641659211a12..cb84794aa0050 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 0000000000000..2f5ec1bd3cf57
--- /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 b7faa76b0b8e3..b2de33e68332b 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 ff12fbbcb4b2f..657d565d643f4 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 a92a4f18c9ce0..7c786d8807028 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}}
|
From d6ce1b55f7cd36c7108e01008d4a64f48d7d4740 Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Thu, 11 May 2023 04:20:19 +0000
Subject: [PATCH 09/11] improve
---
models/{types => shared}/ownertype.go | 2 +-
options/locale/locale_en-US.ini | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
rename models/{types => shared}/ownertype.go (92%)
diff --git a/models/types/ownertype.go b/models/shared/ownertype.go
similarity index 92%
rename from models/types/ownertype.go
rename to models/shared/ownertype.go
index 2f5ec1bd3cf57..bcb8cc9222687 100644
--- a/models/types/ownertype.go
+++ b/models/shared/ownertype.go
@@ -16,7 +16,7 @@ func (o OwnerType) LocaleString(locale translation.Locale) string {
case OwnerTypeSystemGlobal:
return locale.Tr("concept_system_global")
case OwnerTypeIndividual:
- return locale.Tr("concept_person_individual")
+ return locale.Tr("concept_user_individual")
case OwnerTypeRepository:
return locale.Tr("concept_code_repository")
case OwnerTypeOrganization:
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index b2de33e68332b..aa137c9e7a491 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -114,7 +114,7 @@ unknown = Unknown
rss_feed = RSS Feed
concept_system_global = Global
-concept_person_individual = Individual
+concept_user_individual = Individual
concept_code_repository = Repository
concept_user_organization = Organization
From 9b95be6cd75cb657897164868bf7a9b7f5a07825 Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Fri, 12 May 2023 01:27:43 +0000
Subject: [PATCH 10/11] fix package path
---
models/actions/runner.go | 2 +-
models/shared/{ => types}/ownertype.go | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename models/shared/{ => types}/ownertype.go (100%)
diff --git a/models/actions/runner.go b/models/actions/runner.go
index cb84794aa0050..f1638eb0baa9c 100644
--- a/models/actions/runner.go
+++ b/models/actions/runner.go
@@ -11,7 +11,7 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
- "code.gitea.io/gitea/models/types"
+ "code.gitea.io/gitea/models/shared/types"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/translation"
diff --git a/models/shared/ownertype.go b/models/shared/types/ownertype.go
similarity index 100%
rename from models/shared/ownertype.go
rename to models/shared/types/ownertype.go
From a884580cc3259b6dbc54ff41e9bc9412d76e5570 Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Fri, 12 May 2023 05:51:28 +0000
Subject: [PATCH 11/11] add copyright
---
models/shared/types/ownertype.go | 3 +++
1 file changed, 3 insertions(+)
diff --git a/models/shared/types/ownertype.go b/models/shared/types/ownertype.go
index bcb8cc9222687..e6fe4e4cfda12 100644
--- a/models/shared/types/ownertype.go
+++ b/models/shared/types/ownertype.go
@@ -1,3 +1,6 @@
+// Copyright 2023 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
package types
import "code.gitea.io/gitea/modules/translation"