Skip to content

Commit 4980813

Browse files
yp05327silverwindGiteaBotwxiaoguanglunny
authored
Display owner of a runner as a tooltip instead of static text (#24377)
Before: ![image](https://user-images.githubusercontent.com/18380374/234779250-8bbd325c-190e-4a30-ac3e-766498d17df5.png) After: ![image](https://user-images.githubusercontent.com/18380374/234779094-e232ecba-d9f4-4d62-a702-6d5e4a522782.png) ![image](https://user-images.githubusercontent.com/18380374/234779120-0293af17-a566-4b69-b454-af4e95844e3b.png) --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
1 parent 4aec1f8 commit 4980813

File tree

5 files changed

+57
-11
lines changed

5 files changed

+57
-11
lines changed

models/actions/runner.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"code.gitea.io/gitea/models/db"
1313
repo_model "code.gitea.io/gitea/models/repo"
14+
"code.gitea.io/gitea/models/shared/types"
1415
user_model "code.gitea.io/gitea/models/user"
1516
"code.gitea.io/gitea/modules/timeutil"
1617
"code.gitea.io/gitea/modules/translation"
@@ -28,7 +29,7 @@ type ActionRunner struct {
2829
Version string `xorm:"VARCHAR(64)"`
2930
OwnerID int64 `xorm:"index"` // org level runner, 0 means system
3031
Owner *user_model.User `xorm:"-"`
31-
RepoID int64 `xorm:"index"` // repo level runner, if orgid also is zero, then it's a global
32+
RepoID int64 `xorm:"index"` // repo level runner, if OwnerID also is zero, then it's a global
3233
Repo *repo_model.Repository `xorm:"-"`
3334
Description string `xorm:"TEXT"`
3435
Base int // 0 native 1 docker 2 virtual machine
@@ -52,14 +53,25 @@ type ActionRunner struct {
5253
Deleted timeutil.TimeStamp `xorm:"deleted"`
5354
}
5455

55-
func (r *ActionRunner) OwnType() string {
56+
// BelongsToOwnerName before calling, should guarantee that all attributes are loaded
57+
func (r *ActionRunner) BelongsToOwnerName() string {
5658
if r.RepoID != 0 {
57-
return fmt.Sprintf("Repo(%s)", r.Repo.FullName())
59+
return r.Repo.FullName()
5860
}
5961
if r.OwnerID != 0 {
60-
return fmt.Sprintf("Org(%s)", r.Owner.Name)
62+
return r.Owner.Name
6163
}
62-
return "Global"
64+
return ""
65+
}
66+
67+
func (r *ActionRunner) BelongsToOwnerType() types.OwnerType {
68+
if r.RepoID != 0 {
69+
return types.OwnerTypeRepository
70+
}
71+
if r.OwnerID != 0 {
72+
return types.OwnerTypeOrganization
73+
}
74+
return types.OwnerTypeSystemGlobal
6375
}
6476

6577
func (r *ActionRunner) Status() runnerv1.RunnerStatus {

models/shared/types/ownertype.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package types
5+
6+
import "code.gitea.io/gitea/modules/translation"
7+
8+
type OwnerType string
9+
10+
const (
11+
OwnerTypeSystemGlobal = "system-global"
12+
OwnerTypeIndividual = "individual"
13+
OwnerTypeRepository = "repository"
14+
OwnerTypeOrganization = "organization"
15+
)
16+
17+
func (o OwnerType) LocaleString(locale translation.Locale) string {
18+
switch o {
19+
case OwnerTypeSystemGlobal:
20+
return locale.Tr("concept_system_global")
21+
case OwnerTypeIndividual:
22+
return locale.Tr("concept_user_individual")
23+
case OwnerTypeRepository:
24+
return locale.Tr("concept_code_repository")
25+
case OwnerTypeOrganization:
26+
return locale.Tr("concept_user_organization")
27+
}
28+
return locale.Tr("unknown")
29+
}

options/locale/locale_en-US.ini

+5
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ unknown = Unknown
114114

115115
rss_feed = RSS Feed
116116

117+
concept_system_global = Global
118+
concept_user_individual = Individual
119+
concept_code_repository = Repository
120+
concept_user_organization = Organization
121+
117122
[aria]
118123
navbar = Navigation Bar
119124
footer = Footer

templates/shared/actions/runner_edit.tmpl

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
{{template "base/disable_form_autofill"}}
88
{{.CsrfTokenHtml}}
99
<div class="runner-basic-info">
10-
<div class="field gt-dib gt-mr-4 disabled">
10+
<div class="field gt-dib gt-mr-4">
1111
<label>{{.locale.Tr "actions.runners.status"}}</label>
1212
<span class="runner-status-{{if .Runner.IsOnline}}online{{else}}offline{{end}}">{{.Runner.StatusLocaleName $.locale}}</span>
1313
</div>
14-
<div class="field gt-dib gt-mr-4 disabled">
14+
<div class="field gt-dib gt-mr-4">
1515
<label>{{.locale.Tr "actions.runners.last_online"}}</label>
1616
<span>{{if .LastOnline}}{{TimeSinceUnix .LastOnline $.locale}}{{else}}{{$.locale.Tr "never"}}{{end}}</span>
1717
</div>
18-
<div class="field gt-dib gt-mr-4 disabled">
18+
<div class="field gt-dib gt-mr-4">
1919
<label>{{.locale.Tr "actions.runners.agent_labels"}}</label>
2020
<span>
2121
{{range .Runner.AgentLabels}}
2222
<span>{{.}}</span>
2323
{{end}}
2424
</span>
2525
</div>
26-
<div class="field gt-dib gt-mr-4 disabled">
26+
<div class="field gt-dib gt-mr-4">
2727
<label>{{.locale.Tr "actions.runners.owner_type"}}</label>
28-
<span>{{.Runner.OwnType}}</span>
28+
<span data-tooltip-content="{{.Runner.BelongsToOwnerName}}">{{.Runner.BelongsToOwnerType.LocaleString $.locale}}</span>
2929
</div>
3030
</div>
3131

templates/shared/actions/runner_list.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<td>{{.ID}}</td>
6666
<td><p data-tooltip-content="{{.Description}}">{{.Name}}</p></td>
6767
<td>{{if .Version}}{{.Version}}{{else}}{{$.locale.Tr "unknown"}}{{end}}</td>
68-
<td>{{.OwnType}}</td>
68+
<td><span data-tooltip-content="{{.BelongsToOwnerName}}">{{.BelongsToOwnerType.LocaleString $.locale}}<span></td>
6969
<td class="runner-tags">
7070
{{range .AllLabels}}<span class="ui label">{{.}}</span>{{end}}
7171
</td>

0 commit comments

Comments
 (0)