Skip to content

Allow to archive labels #26478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c4b1cd1
Adding in ui archive labels
puni9869 Aug 2, 2023
3a87634
Merge branch 'main' into punit/Archive-labels
puni9869 Aug 2, 2023
f6684fc
Merge branch 'go-gitea:main' into punit/Archive-labels
puni9869 Aug 4, 2023
1cb8b30
Merge branch 'go-gitea:main' into punit/Archive-labels
puni9869 Aug 4, 2023
9cf9b5d
Merge branch 'go-gitea:main' into punit/Archive-labels
puni9869 Aug 4, 2023
99fadb9
init label archive
puni9869 Aug 4, 2023
197a603
Adding archive unix in api and repo and org level labels
puni9869 Aug 4, 2023
c5447e5
Linting files
puni9869 Aug 4, 2023
f0752e0
Adding to fixtures
puni9869 Aug 4, 2023
44d24ac
Adding archived check in templates
puni9869 Aug 4, 2023
903a794
Fixing fixture for labels
puni9869 Aug 4, 2023
fe05e02
Merge branch 'go-gitea:main' into punit/Archive-labels
puni9869 Aug 6, 2023
b2cc90c
Merge branch 'go-gitea:main' into punit/Archive-labels
puni9869 Aug 9, 2023
ce44b9a
Merge branch 'go-gitea:main' into punit/Archive-labels
puni9869 Aug 12, 2023
5a78bd9
Updating migrations
puni9869 Aug 13, 2023
2008377
Wrapping the archived function
puni9869 Aug 13, 2023
1957b88
Merge branch 'go-gitea:main' into punit/Archive-labels
puni9869 Aug 13, 2023
39b135b
Fixing migration
puni9869 Aug 13, 2023
0786a6f
Suggestions addressed
puni9869 Aug 13, 2023
24fb5c8
Linting the migration file
puni9869 Aug 13, 2023
1418372
Merge branch 'main' into punit/Archive-labels
puni9869 Aug 13, 2023
fe2c4da
Merge branch 'main' into punit/Archive-labels
puni9869 Aug 13, 2023
7fa50dd
Merge branch 'main' into punit/Archive-labels
puni9869 Aug 14, 2023
9502271
Update templates/repo/issue/labels/edit_delete_label.tmpl
puni9869 Aug 14, 2023
c9e2b53
Reverting original size of svg info
puni9869 Aug 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions models/fixtures/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
exclusive: false
num_issues: 2
num_closed_issues: 0
archived_unix: 0

-
id: 2
Expand All @@ -17,6 +18,7 @@
exclusive: false
num_issues: 1
num_closed_issues: 1
archived_unix: 0

-
id: 3
Expand All @@ -27,6 +29,7 @@
exclusive: false
num_issues: 0
num_closed_issues: 0
archived_unix: 0

-
id: 4
Expand All @@ -37,6 +40,7 @@
exclusive: false
num_issues: 1
num_closed_issues: 0
archived_unix: 0

-
id: 5
Expand All @@ -47,6 +51,7 @@
exclusive: false
num_issues: 0
num_closed_issues: 0
archived_unix: 0

-
id: 6
Expand All @@ -57,6 +62,7 @@
exclusive: false
num_issues: 0
num_closed_issues: 0
archived_unix: 0

-
id: 7
Expand All @@ -67,6 +73,7 @@
exclusive: true
num_issues: 0
num_closed_issues: 0
archived_unix: 0

-
id: 8
Expand All @@ -77,6 +84,7 @@
exclusive: true
num_issues: 0
num_closed_issues: 0
archived_unix: 0

-
id: 9
Expand All @@ -87,3 +95,4 @@
exclusive: true
num_issues: 0
num_closed_issues: 0
archived_unix: 0
18 changes: 17 additions & 1 deletion models/issues/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ type Label struct {
QueryString string `xorm:"-"`
IsSelected bool `xorm:"-"`
IsExcluded bool `xorm:"-"`

ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT NULL"`
}

func init() {
Expand All @@ -109,6 +111,15 @@ func (l *Label) CalOpenIssues() {
l.NumOpenIssues = l.NumIssues - l.NumClosedIssues
}

// SetArchived set the label as archived
func (l *Label) SetArchived(isArchived bool) {
if isArchived && l.ArchivedUnix.IsZero() {
l.ArchivedUnix = timeutil.TimeStampNow()
} else {
l.ArchivedUnix = timeutil.TimeStamp(0)
}
}

// 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{
Expand Down Expand Up @@ -153,6 +164,11 @@ 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
Expand Down Expand Up @@ -211,7 +227,7 @@ func UpdateLabel(l *Label) error {
}
l.Color = color

return updateLabelCols(db.DefaultContext, l, "name", "description", "color", "exclusive")
return updateLabelCols(db.DefaultContext, l, "name", "description", "color", "exclusive", "archived_unix")
}

// DeleteLabel delete a label
Expand Down
13 changes: 8 additions & 5 deletions models/issues/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/timeutil"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -259,11 +260,12 @@ func TestUpdateLabel(t *testing.T) {
label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1})
// make sure update wont overwrite it
update := &issues_model.Label{
ID: label.ID,
Color: "#ffff00",
Name: "newLabelName",
Description: label.Description,
Exclusive: false,
ID: label.ID,
Color: "#ffff00",
Name: "newLabelName",
Description: label.Description,
Exclusive: false,
ArchivedUnix: timeutil.TimeStamp(0),
}
label.Color = update.Color
label.Name = update.Name
Expand All @@ -273,6 +275,7 @@ func TestUpdateLabel(t *testing.T) {
assert.EqualValues(t, label.Color, newLabel.Color)
assert.EqualValues(t, label.Name, newLabel.Name)
assert.EqualValues(t, label.Description, newLabel.Description)
assert.EqualValues(t, newLabel.ArchivedUnix, 0)
unittest.CheckConsistencyFor(t, &issues_model.Label{}, &repo_model.Repository{})
}

Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ var migrations = []Migration{
NewMigration("Drop deleted branch table", v1_21.DropDeletedBranchTable),
// v270 -> v271
NewMigration("Fix PackageProperty typo", v1_21.FixPackagePropertyTypo),
// v271 -> v272
NewMigration("Allow archiving labels", v1_21.AddArchivedUnixColumInLabelTable),
}

// GetCurrentDBVersion returns the current db version
Expand Down
16 changes: 16 additions & 0 deletions models/migrations/v1_21/v271.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_21 //nolint
import (
"code.gitea.io/gitea/modules/timeutil"

"xorm.io/xorm"
)

func AddArchivedUnixColumInLabelTable(x *xorm.Engine) error {
type Label struct {
ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT NULL"`
}
return x.Sync(new(Label))
}
6 changes: 6 additions & 0 deletions modules/structs/issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type Label struct {
Name string `json:"name"`
// example: false
Exclusive bool `json:"exclusive"`
// example: false
IsArchived bool `json:"is_archived"`
// example: 00aabb
Color string `json:"color"`
Description string `json:"description"`
Expand All @@ -27,6 +29,8 @@ type CreateLabelOption struct {
// example: #00aabb
Color string `json:"color" binding:"Required"`
Description string `json:"description"`
// example: false
IsArchived bool `json:"is_archived"`
}

// EditLabelOption options for editing a label
Expand All @@ -37,6 +41,8 @@ type EditLabelOption struct {
// example: #00aabb
Color *string `json:"color"`
Description *string `json:"description"`
// example: false
IsArchived *bool `json:"is_archived"`
}

// IssueLabelsOption a collection of labels
Expand Down
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,8 @@ issues.label_title = Name
issues.label_description = Description
issues.label_color = Color
issues.label_exclusive = Exclusive
issues.label_archive = Archive Label
issues.label_archive_tooltip= Archived labels are excluded from the label search when applying labels to an issue. Existing labels on issues remain unaffected, allowing you to retire obsolete labels without losing information.
issues.label_exclusive_desc = Name the label <code>scope/item</code> to make it mutually exclusive with other <code>scope/</code> labels.
issues.label_exclusive_warning = Any conflicting scoped labels will be removed when editing the labels of an issue or pull request.
issues.label_count = %d labels
Expand Down
1 change: 1 addition & 0 deletions routers/api/v1/org/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func EditLabel(ctx *context.APIContext) {
if form.Description != nil {
l.Description = *form.Description
}
l.SetArchived(form.IsArchived != nil && *form.IsArchived)
if err := issues_model.UpdateLabel(l); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateLabel", err)
return
Expand Down
3 changes: 2 additions & 1 deletion routers/api/v1/repo/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ func CreateLabel(ctx *context.APIContext) {
return
}
form.Color = color

l := &issues_model.Label{
Name: form.Name,
Exclusive: form.Exclusive,
Color: form.Color,
RepoID: ctx.Repo.Repository.ID,
Description: form.Description,
}
l.SetArchived(form.IsArchived)
if err := issues_model.NewLabel(ctx, l); err != nil {
ctx.Error(http.StatusInternalServerError, "NewLabel", err)
return
Expand Down Expand Up @@ -231,6 +231,7 @@ func EditLabel(ctx *context.APIContext) {
if form.Description != nil {
l.Description = *form.Description
}
l.SetArchived(form.IsArchived != nil && *form.IsArchived)
if err := issues_model.UpdateLabel(l); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateLabel", err)
return
Expand Down
1 change: 1 addition & 0 deletions routers/web/org/org_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func UpdateLabel(ctx *context.Context) {
l.Exclusive = form.Exclusive
l.Description = form.Description
l.Color = form.Color
l.SetArchived(form.IsArchived)
if err := issues_model.UpdateLabel(l); err != nil {
ctx.ServerError("UpdateLabel", err)
return
Expand Down
15 changes: 9 additions & 6 deletions routers/web/repo/issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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/forms"
issue_service "code.gitea.io/gitea/services/issue"
Expand Down Expand Up @@ -111,11 +112,12 @@ 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,
RepoID: ctx.Repo.Repository.ID,
Name: form.Title,
Exclusive: form.Exclusive,
Description: form.Description,
Color: form.Color,
ArchivedUnix: timeutil.TimeStamp(0),
}
if err := issues_model.NewLabel(ctx, l); err != nil {
ctx.ServerError("NewLabel", err)
Expand All @@ -137,11 +139,12 @@ func UpdateLabel(ctx *context.Context) {
}
return
}

l.Name = form.Title
l.Exclusive = form.Exclusive
l.Description = form.Description
l.Color = form.Color

l.SetArchived(form.IsArchived)
if err := issues_model.UpdateLabel(l); err != nil {
ctx.ServerError("UpdateLabel", err)
return
Expand Down
7 changes: 4 additions & 3 deletions routers/web/repo/issue_label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ func TestUpdateLabel(t *testing.T) {
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
web.SetForm(ctx, &forms.CreateLabelForm{
ID: 2,
Title: "newnameforlabel",
Color: "#abcdef",
ID: 2,
Title: "newnameforlabel",
Color: "#abcdef",
IsArchived: true,
})
UpdateLabel(ctx)
assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
Expand Down
1 change: 1 addition & 0 deletions services/convert/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func ToLabel(label *issues_model.Label, repo *repo_model.Repository, org *user_m
Exclusive: label.Exclusive,
Color: strings.TrimLeft(label.Color, "#"),
Description: label.Description,
IsArchived: label.IsArchived(),
}

// calculate URL
Expand Down
1 change: 1 addition & 0 deletions services/forms/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ type CreateLabelForm struct {
ID int64
Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
Exclusive bool `form:"exclusive"`
IsArchived bool `form:"is_archived"`
Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
Color string `binding:"Required;MaxSize(7)" locale:"repo.issues.label_color"`
}
Expand Down
10 changes: 10 additions & 0 deletions templates/repo/issue/labels/edit_delete_label.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
<div class="desc gt-ml-2 gt-mt-3 gt-hidden label-exclusive-warning">
{{svg "octicon-alert"}} {{.locale.Tr "repo.issues.label_exclusive_warning" | Safe}}
</div>
<br>
</div>
<div class="field label-is-archived-input-field">
<div class="ui checkbox">
<input class="label-is-archived-input" name="is_archived" type="checkbox">
<label>{{.locale.Tr "repo.issues.label_archive"}}</label>
</div>
<i class="gt-ml-2" data-tooltip-content={{.locale.Tr "repo.issues.label_archive_tooltip"}}>
{{svg "octicon-info"}}
</i>
</div>
<div class="field">
<label for="description">{{.locale.Tr "repo.issues.label_description"}}</label>
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/issue/labels/label_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
</div>
<div class="label-operation">
{{if and (not $.PageIsOrgSettingsLabels) (not $.Repository.IsArchived) (or $.CanWriteIssues $.CanWritePulls)}}
<a class="edit-label-button" href="#" data-id="{{.ID}}" data-title="{{.Name}}" {{if .Exclusive}}data-exclusive{{end}} data-num-issues="{{.NumIssues}}" data-description="{{.Description}}" data-color={{.Color}}>{{svg "octicon-pencil"}} {{$.locale.Tr "repo.issues.label_edit"}}</a>
<a class="edit-label-button" href="#" data-id="{{.ID}}" data-title="{{.Name}}" {{if .Exclusive}}data-exclusive{{end}} {{if gt .ArchivedUnix 0}}data-is-archived{{end}} data-num-issues="{{.NumIssues}}" data-description="{{.Description}}" data-color={{.Color}}>{{svg "octicon-pencil"}} {{$.locale.Tr "repo.issues.label_edit"}}</a>
<a class="delete-button" href="#" data-url="{{$.Link}}/delete" data-id="{{.ID}}">{{svg "octicon-trash"}} {{$.locale.Tr "repo.issues.label_delete"}}</a>
{{else if $.PageIsOrgSettingsLabels}}
<a class="edit-label-button" href="#" data-id="{{.ID}}" data-title="{{.Name}}" {{if .Exclusive}}data-exclusive{{end}} data-num-issues="{{.NumIssues}}" data-description="{{.Description}}" data-color={{.Color}}>{{svg "octicon-pencil"}} {{$.locale.Tr "repo.issues.label_edit"}}</a>
<a class="edit-label-button" href="#" data-id="{{.ID}}" data-title="{{.Name}}" {{if .Exclusive}}data-exclusive{{end}} {{if gt .ArchivedUnix 0}}data-is-archived{{end}} data-num-issues="{{.NumIssues}}" data-description="{{.Description}}" data-color={{.Color}}>{{svg "octicon-pencil"}} {{$.locale.Tr "repo.issues.label_edit"}}</a>
<a class="delete-button" href="#" data-url="{{$.Link}}/delete" data-id="{{.ID}}">{{svg "octicon-trash"}} {{$.locale.Tr "repo.issues.label_delete"}}</a>
{{end}}
</div>
Expand Down
15 changes: 15 additions & 0 deletions templates/swagger/v1_json.tmpl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading