Skip to content

Commit 9a93b18

Browse files
authored
Refactor label.IsArchived() (#29750)
just some missed nits
1 parent 857243b commit 9a93b18

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

models/issues/label.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,17 @@ func (l *Label) CalOpenIssues() {
116116
func (l *Label) SetArchived(isArchived bool) {
117117
if !isArchived {
118118
l.ArchivedUnix = timeutil.TimeStamp(0)
119-
} else if isArchived && l.ArchivedUnix.IsZero() {
119+
} else if isArchived && !l.IsArchived() {
120120
// Only change the date when it is newly archived.
121121
l.ArchivedUnix = timeutil.TimeStampNow()
122122
}
123123
}
124124

125+
// IsArchived returns true if label is an archived
126+
func (l *Label) IsArchived() bool {
127+
return !l.ArchivedUnix.IsZero()
128+
}
129+
125130
// CalOpenOrgIssues calculates the open issues of a label for a specific repo
126131
func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) {
127132
counts, _ := CountIssuesByRepo(ctx, &IssuesOptions{
@@ -166,11 +171,6 @@ func (l *Label) BelongsToOrg() bool {
166171
return l.OrgID > 0
167172
}
168173

169-
// IsArchived returns true if label is an archived
170-
func (l *Label) IsArchived() bool {
171-
return l.ArchivedUnix > 0
172-
}
173-
174174
// BelongsToRepo returns true if label is a repository label
175175
func (l *Label) BelongsToRepo() bool {
176176
return l.RepoID > 0

modules/templates/util_render.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ func RenderLabel(ctx context.Context, locale translation.Locale, label *issues_m
124124
var (
125125
archivedCSSClass string
126126
textColor = "#111"
127-
isArchived = !label.ArchivedUnix.IsZero()
128127
labelScope = label.ExclusiveScope()
129128
)
130129

@@ -136,7 +135,7 @@ func RenderLabel(ctx context.Context, locale translation.Locale, label *issues_m
136135

137136
description := emoji.ReplaceAliases(template.HTMLEscapeString(label.Description))
138137

139-
if isArchived {
138+
if label.IsArchived() {
140139
archivedCSSClass = "archived-label"
141140
description = fmt.Sprintf("(%s) %s", locale.TrString("archived"), description)
142141
}

routers/web/repo/issue_label.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"code.gitea.io/gitea/modules/label"
1414
"code.gitea.io/gitea/modules/log"
1515
repo_module "code.gitea.io/gitea/modules/repository"
16-
"code.gitea.io/gitea/modules/timeutil"
1716
"code.gitea.io/gitea/modules/web"
1817
"code.gitea.io/gitea/services/context"
1918
"code.gitea.io/gitea/services/forms"
@@ -112,12 +111,11 @@ func NewLabel(ctx *context.Context) {
112111
}
113112

114113
l := &issues_model.Label{
115-
RepoID: ctx.Repo.Repository.ID,
116-
Name: form.Title,
117-
Exclusive: form.Exclusive,
118-
Description: form.Description,
119-
Color: form.Color,
120-
ArchivedUnix: timeutil.TimeStamp(0),
114+
RepoID: ctx.Repo.Repository.ID,
115+
Name: form.Title,
116+
Exclusive: form.Exclusive,
117+
Description: form.Description,
118+
Color: form.Color,
121119
}
122120
if err := issues_model.NewLabel(ctx, l); err != nil {
123121
ctx.ServerError("NewLabel", err)

0 commit comments

Comments
 (0)