diff options
author | 6543 <6543@obermui.de> | 2024-03-13 07:04:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-13 07:04:07 +0100 |
commit | 9a93b1816e0bc65101e7ad7ca66786fb38a8e628 (patch) | |
tree | bb2fec0860c38c2cb56236107621da2ab0308339 | |
parent | 857243bed7f9dccdc597c2941df41e821781cb0f (diff) | |
download | gitea-9a93b1816e0bc65101e7ad7ca66786fb38a8e628.tar.gz gitea-9a93b1816e0bc65101e7ad7ca66786fb38a8e628.zip |
Refactor label.IsArchived() (#29750)
just some missed nits
-rw-r--r-- | models/issues/label.go | 12 | ||||
-rw-r--r-- | modules/templates/util_render.go | 3 | ||||
-rw-r--r-- | routers/web/repo/issue_label.go | 12 |
3 files changed, 12 insertions, 15 deletions
diff --git a/models/issues/label.go b/models/issues/label.go index f6ecc68cd1..2397a29e35 100644 --- a/models/issues/label.go +++ b/models/issues/label.go @@ -116,12 +116,17 @@ func (l *Label) CalOpenIssues() { func (l *Label) SetArchived(isArchived bool) { if !isArchived { l.ArchivedUnix = timeutil.TimeStamp(0) - } else if isArchived && l.ArchivedUnix.IsZero() { + } else if isArchived && !l.IsArchived() { // Only change the date when it is newly archived. l.ArchivedUnix = timeutil.TimeStampNow() } } +// IsArchived returns true if label is an archived +func (l *Label) IsArchived() bool { + return !l.ArchivedUnix.IsZero() +} + // CalOpenOrgIssues calculates the open issues of a label for a specific repo func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) { counts, _ := CountIssuesByRepo(ctx, &IssuesOptions{ @@ -166,11 +171,6 @@ func (l *Label) BelongsToOrg() bool { return l.OrgID > 0 } -// IsArchived returns true if label is an archived -func (l *Label) IsArchived() bool { - return l.ArchivedUnix > 0 -} - // BelongsToRepo returns true if label is a repository label func (l *Label) BelongsToRepo() bool { return l.RepoID > 0 diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index ba9b050e02..7ed3a8b9b4 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -124,7 +124,6 @@ func RenderLabel(ctx context.Context, locale translation.Locale, label *issues_m var ( archivedCSSClass string textColor = "#111" - isArchived = !label.ArchivedUnix.IsZero() labelScope = label.ExclusiveScope() ) @@ -136,7 +135,7 @@ func RenderLabel(ctx context.Context, locale translation.Locale, label *issues_m description := emoji.ReplaceAliases(template.HTMLEscapeString(label.Description)) - if isArchived { + if label.IsArchived() { archivedCSSClass = "archived-label" description = fmt.Sprintf("(%s) %s", locale.TrString("archived"), description) } diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go index 9dedaefa4b..81bee4dbb5 100644 --- a/routers/web/repo/issue_label.go +++ b/routers/web/repo/issue_label.go @@ -13,7 +13,6 @@ import ( "code.gitea.io/gitea/modules/label" "code.gitea.io/gitea/modules/log" repo_module "code.gitea.io/gitea/modules/repository" - "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/forms" @@ -112,12 +111,11 @@ func NewLabel(ctx *context.Context) { } l := &issues_model.Label{ - RepoID: ctx.Repo.Repository.ID, - Name: form.Title, - Exclusive: form.Exclusive, - Description: form.Description, - Color: form.Color, - ArchivedUnix: timeutil.TimeStamp(0), + RepoID: ctx.Repo.Repository.ID, + Name: form.Title, + Exclusive: form.Exclusive, + Description: form.Description, + Color: form.Color, } if err := issues_model.NewLabel(ctx, l); err != nil { ctx.ServerError("NewLabel", err) |