Skip to content

Commit 442ec40

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin Updates to the API for archived repos (go-gitea#27149) Fix release URL in webhooks (go-gitea#27182) Fix dropdown icon position (go-gitea#27175) Fix repo sub menu (go-gitea#27169) Fix review request number and add more tests (go-gitea#27104) Fix the variable regexp pattern on web page (go-gitea#27161) Fix organization field being null in POST /orgs/{orgid}/teams (go-gitea#27150) Add index to `issue_user.issue_id` (go-gitea#27154) [skip ci] Updated translations via Crowdin Start development on Gitea 1.22 (go-gitea#27155) Fix successful return value for `SyncAndGetUserSpecificDiff` (go-gitea#27152)
2 parents add8afe + 383edf2 commit 442ec40

Some content is hidden

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

68 files changed

+461
-109
lines changed

models/fixtures/issue.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,20 @@
321321
created_unix: 946684830
322322
updated_unix: 978307200
323323
is_locked: false
324+
325+
-
326+
id: 20
327+
repo_id: 23
328+
index: 1
329+
poster_id: 2
330+
original_author_id: 0
331+
name: issue for pr
332+
content: content
333+
milestone_id: 0
334+
priority: 0
335+
is_closed: false
336+
is_pull: true
337+
num_comments: 0
338+
created_unix: 978307210
339+
updated_unix: 978307210
340+
is_locked: false

models/fixtures/pull_request.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,12 @@
8989
base_branch: main
9090
merge_base: cbff181af4c9c7fee3cf6c106699e07d9a3f54e6
9191
has_merged: false
92+
93+
-
94+
id: 8
95+
type: 0 # gitea pull request
96+
status: 2 # mergable
97+
issue_id: 20
98+
index: 1
99+
head_repo_id: 23
100+
base_repo_id: 23

models/fixtures/repository.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@
679679
num_forks: 0
680680
num_issues: 0
681681
num_closed_issues: 0
682-
num_pulls: 0
682+
num_pulls: 1
683683
num_closed_pulls: 0
684684
num_milestones: 0
685685
num_closed_milestones: 0

models/fixtures/review.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,41 @@
132132
content: "singular review from org6 and final review for this pr"
133133
updated_unix: 946684831
134134
created_unix: 946684831
135+
136+
-
137+
id: 16
138+
type: 4
139+
reviewer_id: 20
140+
issue_id: 20
141+
content: "review request for user20"
142+
updated_unix: 946684832
143+
created_unix: 946684832
144+
145+
-
146+
id: 17
147+
type: 1
148+
reviewer_id: 20
149+
issue_id: 20
150+
content: "review approved by user20"
151+
updated_unix: 946684833
152+
created_unix: 946684833
153+
-
154+
id: 18
155+
type: 4
156+
reviewer_id: 0
157+
reviewer_team_id: 5
158+
issue_id: 20
159+
content: "review request for team5"
160+
updated_unix: 946684834
161+
created_unix: 946684834
162+
163+
-
164+
id: 19
165+
type: 4
166+
reviewer_id: 15
167+
reviewer_team_id: 0
168+
issue_id: 20
169+
content: "review request for user15"
170+
updated_unix: 946684835
171+
created_unix: 946684835
172+

models/fixtures/team.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
name: review_team
9494
authorize: 1 # read
9595
num_repos: 1
96-
num_members: 2
96+
num_members: 3
9797
includes_all_repositories: false
9898
can_create_org_repo: false
9999

models/fixtures/team_user.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,9 @@
123123
org_id: 36
124124
team_id: 20
125125
uid: 5
126+
127+
-
128+
id: 22
129+
org_id: 17
130+
team_id: 9
131+
uid: 15

models/git/protected_branch.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ type WhitelistOptions struct {
315315
// This function also performs check if whitelist user and team's IDs have been changed
316316
// to avoid unnecessary whitelist delete and regenerate.
317317
func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) {
318+
err = repo.MustNotBeArchived()
319+
if err != nil {
320+
return err
321+
}
322+
318323
if err = repo.LoadOwner(ctx); err != nil {
319324
return fmt.Errorf("LoadOwner: %v", err)
320325
}
@@ -445,9 +450,14 @@ func updateTeamWhitelist(ctx context.Context, repo *repo_model.Repository, curre
445450
}
446451

447452
// DeleteProtectedBranch removes ProtectedBranch relation between the user and repository.
448-
func DeleteProtectedBranch(ctx context.Context, repoID, id int64) (err error) {
453+
func DeleteProtectedBranch(ctx context.Context, repo *repo_model.Repository, id int64) (err error) {
454+
err = repo.MustNotBeArchived()
455+
if err != nil {
456+
return err
457+
}
458+
449459
protectedBranch := &ProtectedBranch{
450-
RepoID: repoID,
460+
RepoID: repo.ID,
451461
ID: id,
452462
}
453463

models/issues/issue_search.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,21 @@ func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64)
362362
From("team_user").
363363
Where(builder.Eq{"team_user.uid": reviewRequestedID})
364364

365+
// if the review is approved or rejected, it should not be shown in the review requested list
366+
maxReview := builder.Select("MAX(r.id)").
367+
From("review as r").
368+
Where(builder.In("r.type", []ReviewType{ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest})).
369+
GroupBy("r.issue_id, r.reviewer_id, r.reviewer_team_id")
370+
365371
subQuery := builder.Select("review.issue_id").
366372
From("review").
367373
Where(builder.And(
368-
builder.In("review.type", []ReviewType{ReviewTypeRequest, ReviewTypeReject, ReviewTypeApprove}),
374+
builder.Eq{"review.type": ReviewTypeRequest},
369375
builder.Or(
370376
builder.Eq{"review.reviewer_id": reviewRequestedID},
371377
builder.In("review.reviewer_team_id", existInTeamQuery),
372378
),
379+
builder.In("review.id", maxReview),
373380
))
374381
return sess.Where("issue.poster_id <> ?", reviewRequestedID).
375382
And(builder.In("issue.id", subQuery))

models/issues/issue_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func TestCountIssues(t *testing.T) {
403403
assert.NoError(t, unittest.PrepareTestDatabase())
404404
count, err := issues_model.CountIssues(db.DefaultContext, &issues_model.IssuesOptions{})
405405
assert.NoError(t, err)
406-
assert.EqualValues(t, 19, count)
406+
assert.EqualValues(t, 20, count)
407407
}
408408

409409
func TestIssueLoadAttributes(t *testing.T) {

models/issues/issue_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
type IssueUser struct {
1616
ID int64 `xorm:"pk autoincr"`
1717
UID int64 `xorm:"INDEX"` // User ID.
18-
IssueID int64
18+
IssueID int64 `xorm:"INDEX"`
1919
IsRead bool
2020
IsMentioned bool
2121
}

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ var migrations = []Migration{
534534
NewMigration("Add ScheduleID for ActionRun", v1_21.AddScheduleIDForActionRun),
535535
// v276 -> v277
536536
NewMigration("Add RemoteAddress to mirrors", v1_21.AddRemoteAddressToMirrors),
537+
// v277 -> v278
538+
NewMigration("Add Index to issue_user.issue_id", v1_21.AddIndexToIssueUserIssueID),
537539
}
538540

539541
// GetCurrentDBVersion returns the current db version

models/migrations/v1_21/v277.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_21 //nolint
5+
6+
import (
7+
"xorm.io/xorm"
8+
)
9+
10+
func AddIndexToIssueUserIssueID(x *xorm.Engine) error {
11+
type IssueUser struct {
12+
IssueID int64 `xorm:"INDEX"`
13+
}
14+
15+
return x.Sync(new(IssueUser))
16+
}

models/repo/repo.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ func (err ErrUserDoesNotHaveAccessToRepo) Unwrap() error {
4747
return util.ErrPermissionDenied
4848
}
4949

50+
type ErrRepoIsArchived struct {
51+
Repo *Repository
52+
}
53+
54+
func (err ErrRepoIsArchived) Error() string {
55+
return fmt.Sprintf("%s is archived", err.Repo.LogString())
56+
}
57+
5058
var (
5159
reservedRepoNames = []string{".", "..", "-"}
5260
reservedRepoPatterns = []string{"*.git", "*.wiki", "*.rss", "*.atom"}
@@ -654,6 +662,14 @@ func (repo *Repository) GetTrustModel() TrustModelType {
654662
return trustModel
655663
}
656664

665+
// MustNotBeArchived returns ErrRepoIsArchived if the repo is archived
666+
func (repo *Repository) MustNotBeArchived() error {
667+
if repo.IsArchived {
668+
return ErrRepoIsArchived{Repo: repo}
669+
}
670+
return nil
671+
}
672+
657673
// __________ .__ __
658674
// \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
659675
// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |

modules/context/api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ type APIRedirect struct{}
101101
// swagger:response string
102102
type APIString string
103103

104+
// APIRepoArchivedError is an error that is raised when an archived repo should be modified
105+
// swagger:response repoArchivedError
106+
type APIRepoArchivedError struct {
107+
APIError
108+
}
109+
104110
// ServerError responds with error message, status is 500
105111
func (ctx *APIContext) ServerError(title string, err error) {
106112
ctx.Error(http.StatusInternalServerError, title, err)

modules/indexer/issues/indexer_test.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ func searchIssueByID(t *testing.T) {
180180
},
181181
[]int64{11, 6, 5, 3, 2, 1},
182182
},
183+
{
184+
// issue 20 request user 15 and team 5 which user 15 belongs to
185+
// the review request number of issue 20 should be 1
186+
SearchOptions{
187+
ReviewRequestedID: int64Pointer(15),
188+
},
189+
[]int64{12, 20},
190+
},
191+
{
192+
// user 20 approved the issue 20, so return nothing
193+
SearchOptions{
194+
ReviewRequestedID: int64Pointer(20),
195+
},
196+
[]int64{},
197+
},
183198
}
184199

185200
for _, test := range tests {
@@ -206,7 +221,7 @@ func searchIssueIsPull(t *testing.T) {
206221
SearchOptions{
207222
IsPull: util.OptionalBoolTrue,
208223
},
209-
[]int64{12, 11, 19, 9, 8, 3, 2},
224+
[]int64{12, 11, 20, 19, 9, 8, 3, 2},
210225
},
211226
}
212227
for _, test := range tests {
@@ -227,7 +242,7 @@ func searchIssueIsClosed(t *testing.T) {
227242
SearchOptions{
228243
IsClosed: util.OptionalBoolFalse,
229244
},
230-
[]int64{17, 16, 15, 14, 13, 12, 11, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1},
245+
[]int64{17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1},
231246
},
232247
{
233248
SearchOptions{
@@ -293,7 +308,7 @@ func searchIssueByLabelID(t *testing.T) {
293308
SearchOptions{
294309
ExcludedLabelIDs: []int64{1},
295310
},
296-
[]int64{17, 16, 15, 14, 13, 12, 11, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3},
311+
[]int64{17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3},
297312
},
298313
}
299314
for _, test := range tests {
@@ -317,7 +332,7 @@ func searchIssueByTime(t *testing.T) {
317332
SearchOptions{
318333
UpdatedAfterUnix: int64Pointer(0),
319334
},
320-
[]int64{17, 16, 15, 14, 13, 12, 11, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1},
335+
[]int64{17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1},
321336
},
322337
}
323338
for _, test := range tests {
@@ -338,7 +353,7 @@ func searchIssueWithOrder(t *testing.T) {
338353
SearchOptions{
339354
SortBy: internal.SortByCreatedAsc,
340355
},
341-
[]int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 11, 12, 13, 14, 15, 16, 17},
356+
[]int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17},
342357
},
343358
}
344359
for _, test := range tests {
@@ -393,7 +408,7 @@ func searchIssueWithPaginator(t *testing.T) {
393408
},
394409
},
395410
[]int64{17, 16, 15, 14, 13},
396-
19,
411+
20,
397412
},
398413
}
399414
for _, test := range tests {

0 commit comments

Comments
 (0)