From 9e5326e9be9e73c6b9ed997497876e853cbf57c3 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 27 Apr 2023 06:26:43 +0000 Subject: [PATCH 01/11] improve runner type display --- models/actions/runner.go | 34 ++++++++++++++++++++--- templates/shared/actions/runner_edit.tmpl | 2 +- templates/shared/actions/runner_list.tmpl | 2 +- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/models/actions/runner.go b/models/actions/runner.go index cce8b4f4431d3..d4dc4de4bb0ff 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -52,14 +52,40 @@ type ActionRunner struct { Deleted timeutil.TimeStamp `xorm:"deleted"` } -func (r *ActionRunner) OwnType() string { +// RunnerType defines the runner type +type RunnerType int //revive:disable-line:exported + +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 { if r.RepoID != 0 { - return fmt.Sprintf("Repo(%s)", r.Repo.FullName()) + return RunnerTypeRepository } if r.OwnerID != 0 { - return fmt.Sprintf("Org(%s)", r.Owner.Name) + return RunnerTypeOrganization + } + return RunnerTypeGlobal +} + +func (r RunnerType) String() string { + switch r { + case RunnerTypeGlobal: + return "Global" + case RunnerTypeOrganization: + return "Organization" + case RunnerTypeRepository: + return "Repository" } - return "Global" + return fmt.Sprintf("Unknown Type %d", r) } func (r *ActionRunner) Status() runnerv1.RunnerStatus { diff --git a/templates/shared/actions/runner_edit.tmpl b/templates/shared/actions/runner_edit.tmpl index d64479e19badf..dceffd13dc366 100644 --- a/templates/shared/actions/runner_edit.tmpl +++ b/templates/shared/actions/runner_edit.tmpl @@ -25,7 +25,7 @@
- {{.Runner.OwnType}} + {{.Runner.Type.String}}
diff --git a/templates/shared/actions/runner_list.tmpl b/templates/shared/actions/runner_list.tmpl index e738a581c329e..f24610118d095 100644 --- a/templates/shared/actions/runner_list.tmpl +++ b/templates/shared/actions/runner_list.tmpl @@ -65,7 +65,7 @@ {{.ID}}

{{.Name}}

{{.Version}} - {{.OwnType}} + {{.Type.String}} {{range .AllLabels}}{{.}}{{end}} From 310e85bd3b2d4f0b6f9a460bc76b9bb894b571db Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 27 Apr 2023 06:34:37 +0000 Subject: [PATCH 02/11] add tooltip --- models/actions/runner.go | 16 +++++++++++++--- templates/shared/actions/runner_edit.tmpl | 2 +- templates/shared/actions/runner_list.tmpl | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/models/actions/runner.go b/models/actions/runner.go index d4dc4de4bb0ff..3a373de1c0963 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -76,8 +76,8 @@ func (r *ActionRunner) Type() RunnerType { return RunnerTypeGlobal } -func (r RunnerType) String() string { - switch r { +func (rt RunnerType) String() string { + switch rt { case RunnerTypeGlobal: return "Global" case RunnerTypeOrganization: @@ -85,7 +85,17 @@ func (r RunnerType) String() string { case RunnerTypeRepository: return "Repository" } - return fmt.Sprintf("Unknown Type %d", r) + return fmt.Sprintf("Unknown Type %d", rt) +} + +func (r *ActionRunner) BelongsTo() string { + if r.RepoID != 0 { + return r.Repo.FullName() + } + if r.OwnerID != 0 { + return r.Owner.Name + } + return "" } func (r *ActionRunner) Status() runnerv1.RunnerStatus { diff --git a/templates/shared/actions/runner_edit.tmpl b/templates/shared/actions/runner_edit.tmpl index dceffd13dc366..e1d787428e51d 100644 --- a/templates/shared/actions/runner_edit.tmpl +++ b/templates/shared/actions/runner_edit.tmpl @@ -25,7 +25,7 @@
- {{.Runner.Type.String}} + {{.Runner.Type.String}}
diff --git a/templates/shared/actions/runner_list.tmpl b/templates/shared/actions/runner_list.tmpl index f24610118d095..8da48973e2f04 100644 --- a/templates/shared/actions/runner_list.tmpl +++ b/templates/shared/actions/runner_list.tmpl @@ -65,7 +65,7 @@ {{.ID}}

{{.Name}}

{{.Version}} - {{.Type.String}} + {{.Type.String}} {{range .AllLabels}}{{.}}{{end}} From 94da9793b8355b04232c41ababee4ba724e62eba Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 29 Apr 2023 14:09:37 +0200 Subject: [PATCH 03/11] Update models/actions/runner.go --- models/actions/runner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/actions/runner.go b/models/actions/runner.go index 3a373de1c0963..b1ad8ddbb29ff 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -53,7 +53,7 @@ type ActionRunner struct { } // RunnerType defines the runner type -type RunnerType int //revive:disable-line:exported +type RunnerType int //nolint:revive const ( // RunnerTypeGlobal defines a global runner From c231bf01c63e59425e49db618026c639215d69d5 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 1 May 2023 02:56:47 +0000 Subject: [PATCH 04/11] remove nolint --- models/actions/runner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/actions/runner.go b/models/actions/runner.go index b1ad8ddbb29ff..d9a68f49b9ab2 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -53,7 +53,7 @@ type ActionRunner struct { } // RunnerType defines the runner type -type RunnerType int //nolint:revive +type RunnerType int const ( // RunnerTypeGlobal defines a global runner From ef8ae9364cd49763aa9088dcfb70774d4a6f2fc0 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 2 May 2023 00:15:38 +0000 Subject: [PATCH 05/11] convert rt.string into rt.localestring --- models/actions/runner.go | 10 +++++----- options/locale/locale_en-US.ini | 4 ++++ templates/shared/actions/runner_edit.tmpl | 10 +++++----- templates/shared/actions/runner_list.tmpl | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/models/actions/runner.go b/models/actions/runner.go index d9a68f49b9ab2..792dbe83a17b5 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -76,16 +76,16 @@ func (r *ActionRunner) Type() RunnerType { return RunnerTypeGlobal } -func (rt RunnerType) String() string { +func (rt RunnerType) LocaleString(locale translation.Locale) string { switch rt { case RunnerTypeGlobal: - return "Global" + return locale.Tr("actions.runners.owner_type.global") case RunnerTypeOrganization: - return "Organization" + return locale.Tr("actions.runners.owner_type.organization") case RunnerTypeRepository: - return "Repository" + return locale.Tr("actions.runners.owner_type.repository") } - return fmt.Sprintf("Unknown Type %d", rt) + return locale.Tr("actions.runners.owner_type.unknown", rt) } func (r *ActionRunner) BelongsTo() string { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 3634121833923..c7fae99345f30 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3394,6 +3394,10 @@ 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.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 6f677f28e1850..ff12fbbcb4b2f 100644 --- a/templates/shared/actions/runner_edit.tmpl +++ b/templates/shared/actions/runner_edit.tmpl @@ -7,15 +7,15 @@ {{template "base/disable_form_autofill"}} {{.CsrfTokenHtml}}
-
+
{{.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"