Skip to content

Commit c6ab812

Browse files
committed
Merge branch 'main' into lunny/commit_status_webhook
2 parents d6d7042 + 383edf2 commit c6ab812

Some content is hidden

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

67 files changed

+452
-108
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
}

0 commit comments

Comments
 (0)