diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-06-18 08:51:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-18 00:51:13 +0000 |
commit | 37a4b233a0a4ca516b90e0c8e15d8dafb8d13358 (patch) | |
tree | 906fc88c06e46d164157707886833332aebcf5c8 /models/unit/unit.go | |
parent | d32648b204395fe3590ca2de5f38f0f97da510aa (diff) | |
download | gitea-37a4b233a0a4ca516b90e0c8e15d8dafb8d13358.tar.gz gitea-37a4b233a0a4ca516b90e0c8e15d8dafb8d13358.zip |
Refactor repo unit "disabled" check (#31389)
1. There are already global "unit consts", no need to use context data, which is fragile
2. Remove the "String()" method from "unit", it would only cause rendering problems in templates
---------
Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'models/unit/unit.go')
-rw-r--r-- | models/unit/unit.go | 37 |
1 files changed, 8 insertions, 29 deletions
diff --git a/models/unit/unit.go b/models/unit/unit.go index 8eedcbd347..3b62e5f982 100644 --- a/models/unit/unit.go +++ b/models/unit/unit.go @@ -33,39 +33,18 @@ const ( TypeActions // 10 Actions ) -// Value returns integer value for unit type +// Value returns integer value for unit type (used by template) func (u Type) Value() int { return int(u) } -func (u Type) String() string { - switch u { - case TypeCode: - return "TypeCode" - case TypeIssues: - return "TypeIssues" - case TypePullRequests: - return "TypePullRequests" - case TypeReleases: - return "TypeReleases" - case TypeWiki: - return "TypeWiki" - case TypeExternalWiki: - return "TypeExternalWiki" - case TypeExternalTracker: - return "TypeExternalTracker" - case TypeProjects: - return "TypeProjects" - case TypePackages: - return "TypePackages" - case TypeActions: - return "TypeActions" - } - return fmt.Sprintf("Unknown Type %d", u) -} - func (u Type) LogString() string { - return fmt.Sprintf("<UnitType:%d:%s>", u, u.String()) + unit, ok := Units[u] + unitName := "unknown" + if ok { + unitName = unit.NameKey + } + return fmt.Sprintf("<UnitType:%d:%s>", u, unitName) } var ( @@ -133,7 +112,7 @@ func validateDefaultRepoUnits(defaultUnits, settingDefaultUnits []Type) []Type { units = make([]Type, 0, len(settingDefaultUnits)) for _, settingUnit := range settingDefaultUnits { if !settingUnit.CanBeDefault() { - log.Warn("Not allowed as default unit: %s", settingUnit.String()) + log.Warn("Not allowed as default unit: %s", settingUnit.LogString()) continue } units = append(units, settingUnit) |