Skip to content

Commit 4a2875c

Browse files
authored
Merge branch 'main' into fix-before_commit_three_dot
2 parents 42887c2 + 6221a6f commit 4a2875c

File tree

103 files changed

+859
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+859
-346
lines changed

docs/content/page/index.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ You can try it out using [the online demo](https://try.gitea.io/).
106106
- Permission to create organizations
107107
- Permission to import repositories
108108
- Organization management
109-
- People
109+
- Members
110110
- Teams
111111
- Avatar
112112
- Hooks

models/activities/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ func NotifyWatchers(ctx context.Context, actions ...*Action) error {
534534
repo = act.Repo
535535

536536
// check repo owner exist.
537-
if err := act.Repo.GetOwner(ctx); err != nil {
537+
if err := act.Repo.LoadOwner(ctx); err != nil {
538538
return fmt.Errorf("can't get repo owner: %w", err)
539539
}
540540
} else if act.Repo == nil {

models/fixtures/issue.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,20 @@
287287
created_unix: 1602935696
288288
updated_unix: 1602935696
289289
is_locked: false
290+
291+
-
292+
id: 18
293+
repo_id: 55
294+
index: 1
295+
poster_id: 2
296+
original_author_id: 0
297+
name: issue for scoped labels
298+
content: content
299+
milestone_id: 0
300+
priority: 0
301+
is_closed: false
302+
is_pull: false
303+
num_comments: 0
304+
created_unix: 946684830
305+
updated_unix: 978307200
306+
is_locked: false

models/fixtures/label.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
org_id: 0
55
name: label1
66
color: '#abcdef'
7+
exclusive: false
78
num_issues: 2
89
num_closed_issues: 0
910

@@ -13,6 +14,7 @@
1314
org_id: 0
1415
name: label2
1516
color: '#000000'
17+
exclusive: false
1618
num_issues: 1
1719
num_closed_issues: 1
1820

@@ -22,6 +24,7 @@
2224
org_id: 3
2325
name: orglabel3
2426
color: '#abcdef'
27+
exclusive: false
2528
num_issues: 0
2629
num_closed_issues: 0
2730

@@ -31,6 +34,7 @@
3134
org_id: 3
3235
name: orglabel4
3336
color: '#000000'
37+
exclusive: false
3438
num_issues: 1
3539
num_closed_issues: 0
3640

@@ -40,5 +44,46 @@
4044
org_id: 0
4145
name: pull-test-label
4246
color: '#000000'
47+
exclusive: false
48+
num_issues: 0
49+
num_closed_issues: 0
50+
51+
-
52+
id: 6
53+
repo_id: 55
54+
org_id: 0
55+
name: unscoped_label
56+
color: '#000000'
57+
exclusive: false
58+
num_issues: 0
59+
num_closed_issues: 0
60+
61+
-
62+
id: 7
63+
repo_id: 55
64+
org_id: 0
65+
name: scope/label1
66+
color: '#000000'
67+
exclusive: true
68+
num_issues: 0
69+
num_closed_issues: 0
70+
71+
-
72+
id: 8
73+
repo_id: 55
74+
org_id: 0
75+
name: scope/label2
76+
color: '#000000'
77+
exclusive: true
78+
num_issues: 0
79+
num_closed_issues: 0
80+
81+
-
82+
id: 9
83+
repo_id: 55
84+
org_id: 0
85+
name: scope/subscope/label2
86+
color: '#000000'
87+
exclusive: true
4388
num_issues: 0
4489
num_closed_issues: 0

models/fixtures/repository.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,3 +1622,15 @@
16221622
is_archived: false
16231623
is_private: true
16241624
status: 0
1625+
1626+
-
1627+
id: 55
1628+
owner_id: 2
1629+
owner_name: user2
1630+
lower_name: scoped_label
1631+
name: scoped_label
1632+
is_empty: false
1633+
is_archived: false
1634+
is_private: true
1635+
num_issues: 1
1636+
status: 0

models/fixtures/user.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
num_followers: 2
6767
num_following: 1
6868
num_stars: 2
69-
num_repos: 10
69+
num_repos: 11
7070
num_teams: 0
7171
num_members: 0
7272
visibility: 0

models/git/protected_branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ type WhitelistOptions struct {
314314
// This function also performs check if whitelist user and team's IDs have been changed
315315
// to avoid unnecessary whitelist delete and regenerate.
316316
func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) {
317-
if err = repo.GetOwner(ctx); err != nil {
318-
return fmt.Errorf("GetOwner: %v", err)
317+
if err = repo.LoadOwner(ctx); err != nil {
318+
return fmt.Errorf("LoadOwner: %v", err)
319319
}
320320

321321
whitelist, err := updateUserWhitelist(ctx, repo, protectBranch.WhitelistUserIDs, opts.UserIDs)

models/issues/comment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ func (c *Comment) LoadAssigneeUserAndTeam() error {
620620
return err
621621
}
622622

623-
if err = c.Issue.Repo.GetOwner(db.DefaultContext); err != nil {
623+
if err = c.Issue.Repo.LoadOwner(db.DefaultContext); err != nil {
624624
return err
625625
}
626626

@@ -824,7 +824,7 @@ func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment,
824824
return nil, err
825825
}
826826

827-
if err = opts.Repo.GetOwner(ctx); err != nil {
827+
if err = opts.Repo.LoadOwner(ctx); err != nil {
828828
return nil, err
829829
}
830830

models/issues/issue.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,31 @@ func (ts labelSorter) Swap(i, j int) {
538538
[]*Label(ts)[i], []*Label(ts)[j] = []*Label(ts)[j], []*Label(ts)[i]
539539
}
540540

541+
// Ensure only one label of a given scope exists, with labels at the end of the
542+
// array getting preference over earlier ones.
543+
func RemoveDuplicateExclusiveLabels(labels []*Label) []*Label {
544+
validLabels := make([]*Label, 0, len(labels))
545+
546+
for i, label := range labels {
547+
scope := label.ExclusiveScope()
548+
if scope != "" {
549+
foundOther := false
550+
for _, otherLabel := range labels[i+1:] {
551+
if otherLabel.ExclusiveScope() == scope {
552+
foundOther = true
553+
break
554+
}
555+
}
556+
if foundOther {
557+
continue
558+
}
559+
}
560+
validLabels = append(validLabels, label)
561+
}
562+
563+
return validLabels
564+
}
565+
541566
// ReplaceIssueLabels removes all current labels and add new labels to the issue.
542567
// Triggers appropriate WebHooks, if any.
543568
func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (err error) {
@@ -555,6 +580,8 @@ func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (e
555580
return err
556581
}
557582

583+
labels = RemoveDuplicateExclusiveLabels(labels)
584+
558585
sort.Sort(labelSorter(labels))
559586
sort.Sort(labelSorter(issue.Labels))
560587

@@ -2099,7 +2126,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
20992126
resolved := make(map[string]bool, 10)
21002127
var mentionTeams []string
21012128

2102-
if err := issue.Repo.GetOwner(ctx); err != nil {
2129+
if err := issue.Repo.LoadOwner(ctx); err != nil {
21032130
return nil, err
21042131
}
21052132

models/issues/issue_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
func TestIssue_ReplaceLabels(t *testing.T) {
2626
assert.NoError(t, unittest.PrepareTestDatabase())
2727

28-
testSuccess := func(issueID int64, labelIDs []int64) {
28+
testSuccess := func(issueID int64, labelIDs, expectedLabelIDs []int64) {
2929
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: issueID})
3030
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
3131
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
@@ -35,15 +35,20 @@ func TestIssue_ReplaceLabels(t *testing.T) {
3535
labels[i] = unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: labelID, RepoID: repo.ID})
3636
}
3737
assert.NoError(t, issues_model.ReplaceIssueLabels(issue, labels, doer))
38-
unittest.AssertCount(t, &issues_model.IssueLabel{IssueID: issueID}, len(labelIDs))
39-
for _, labelID := range labelIDs {
38+
unittest.AssertCount(t, &issues_model.IssueLabel{IssueID: issueID}, len(expectedLabelIDs))
39+
for _, labelID := range expectedLabelIDs {
4040
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issueID, LabelID: labelID})
4141
}
4242
}
4343

44-
testSuccess(1, []int64{2})
45-
testSuccess(1, []int64{1, 2})
46-
testSuccess(1, []int64{})
44+
testSuccess(1, []int64{2}, []int64{2})
45+
testSuccess(1, []int64{1, 2}, []int64{1, 2})
46+
testSuccess(1, []int64{}, []int64{})
47+
48+
// mutually exclusive scoped labels 7 and 8
49+
testSuccess(18, []int64{6, 7}, []int64{6, 7})
50+
testSuccess(18, []int64{7, 8}, []int64{8})
51+
testSuccess(18, []int64{6, 8, 7}, []int64{6, 7})
4752
}
4853

4954
func Test_GetIssueIDsByRepoID(t *testing.T) {
@@ -523,5 +528,5 @@ func TestCountIssues(t *testing.T) {
523528
assert.NoError(t, unittest.PrepareTestDatabase())
524529
count, err := issues_model.CountIssues(db.DefaultContext, &issues_model.IssuesOptions{})
525530
assert.NoError(t, err)
526-
assert.EqualValues(t, 17, count)
531+
assert.EqualValues(t, 18, count)
527532
}

0 commit comments

Comments
 (0)