Skip to content

Commit 9eeaf3d

Browse files
committed
Merge branch 'master' into git_simple_pr
2 parents f68899a + 51fb046 commit 9eeaf3d

File tree

216 files changed

+17165
-5175
lines changed

Some content is hidden

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

216 files changed

+17165
-5175
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,8 @@ IMPORT_LOCAL_PATHS = false
556556
; It also enables them to access other resources available to the user on the operating system that is running the Gitea instance and perform arbitrary actions in the name of the Gitea OS user.
557557
; WARNING: This maybe harmful to you website or your operating system.
558558
DISABLE_GIT_HOOKS = true
559+
; Set to true to disable webhooks feature.
560+
DISABLE_WEBHOOKS = false
559561
; Set to false to allow pushes to gitea repositories despite having an incomplete environment - NOT RECOMMENDED
560562
ONLY_ALLOW_PUSH_IF_GITEA_ENVIRONMENT_SET = true
561563
;Comma separated list of character classes required to pass minimum complexity.

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ relation to port exhaustion.
396396
It also enables them to access other resources available to the user on the operating system that is running the
397397
Gitea instance and perform arbitrary actions in the name of the Gitea OS user.
398398
This maybe harmful to you website or your operating system.
399+
- `DISABLE_WEBHOOKS`: **false**: Set to `true` to disable webhooks feature.
399400
- `ONLY_ALLOW_PUSH_IF_GITEA_ENVIRONMENT_SET`: **true**: Set to `false` to allow local users to push to gitea-repositories without setting up the Gitea environment. This is not recommended and if you want local users to push to gitea repositories you should set the environment appropriately.
400401
- `IMPORT_LOCAL_PATHS`: **false**: Set to `false` to prevent all users (including admin) from importing local path on server.
401402
- `INTERNAL_TOKEN`: **\<random at every install if no uri set\>**: Secret used to validate communication within Gitea binary.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ require (
3535
github.com/go-git/go-billy/v5 v5.0.0
3636
github.com/go-git/go-git/v5 v5.2.0
3737
github.com/go-ldap/ldap/v3 v3.2.4
38-
github.com/go-redis/redis/v7 v7.4.0
38+
github.com/go-redis/redis/v8 v8.5.0
3939
github.com/go-sql-driver/mysql v1.5.0
4040
github.com/go-swagger/go-swagger v0.26.0
4141
github.com/go-testfixtures/testfixtures/v3 v3.4.1

go.sum

Lines changed: 13 additions & 33 deletions
Large diffs are not rendered by default.

integrations/api_pull_review_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ func TestAPIPullReview(t *testing.T) {
111111
assert.EqualValues(t, "APPROVED", review.State)
112112
assert.EqualValues(t, 3, review.CodeCommentsCount)
113113

114+
// test dismiss review
115+
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews/%d/dismissals?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, review.ID, token), &api.DismissPullReviewOptions{
116+
Message: "test",
117+
})
118+
resp = session.MakeRequest(t, req, http.StatusOK)
119+
DecodeJSON(t, resp, &review)
120+
assert.EqualValues(t, 6, review.ID)
121+
assert.EqualValues(t, true, review.Dismissed)
122+
123+
// test dismiss review
124+
req = NewRequest(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews/%d/undismissals?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, review.ID, token))
125+
resp = session.MakeRequest(t, req, http.StatusOK)
126+
DecodeJSON(t, resp, &review)
127+
assert.EqualValues(t, 6, review.ID)
128+
assert.EqualValues(t, false, review.Dismissed)
129+
114130
// test DeletePullReview
115131
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.CreatePullReviewOptions{
116132
Body: "just a comment",

models/action.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,31 @@ type ActionType int
2626

2727
// Possible action types.
2828
const (
29-
ActionCreateRepo ActionType = iota + 1 // 1
30-
ActionRenameRepo // 2
31-
ActionStarRepo // 3
32-
ActionWatchRepo // 4
33-
ActionCommitRepo // 5
34-
ActionCreateIssue // 6
35-
ActionCreatePullRequest // 7
36-
ActionTransferRepo // 8
37-
ActionPushTag // 9
38-
ActionCommentIssue // 10
39-
ActionMergePullRequest // 11
40-
ActionCloseIssue // 12
41-
ActionReopenIssue // 13
42-
ActionClosePullRequest // 14
43-
ActionReopenPullRequest // 15
44-
ActionDeleteTag // 16
45-
ActionDeleteBranch // 17
46-
ActionMirrorSyncPush // 18
47-
ActionMirrorSyncCreate // 19
48-
ActionMirrorSyncDelete // 20
49-
ActionApprovePullRequest // 21
50-
ActionRejectPullRequest // 22
51-
ActionCommentPull // 23
52-
ActionPublishRelease // 24
29+
ActionCreateRepo ActionType = iota + 1 // 1
30+
ActionRenameRepo // 2
31+
ActionStarRepo // 3
32+
ActionWatchRepo // 4
33+
ActionCommitRepo // 5
34+
ActionCreateIssue // 6
35+
ActionCreatePullRequest // 7
36+
ActionTransferRepo // 8
37+
ActionPushTag // 9
38+
ActionCommentIssue // 10
39+
ActionMergePullRequest // 11
40+
ActionCloseIssue // 12
41+
ActionReopenIssue // 13
42+
ActionClosePullRequest // 14
43+
ActionReopenPullRequest // 15
44+
ActionDeleteTag // 16
45+
ActionDeleteBranch // 17
46+
ActionMirrorSyncPush // 18
47+
ActionMirrorSyncCreate // 19
48+
ActionMirrorSyncDelete // 20
49+
ActionApprovePullRequest // 21
50+
ActionRejectPullRequest // 22
51+
ActionCommentPull // 23
52+
ActionPublishRelease // 24
53+
ActionPullReviewDismissed // 25
5354
)
5455

5556
// Action represents user operation type and other information to
@@ -259,7 +260,7 @@ func (a *Action) GetCreate() time.Time {
259260
// GetIssueInfos returns a list of issues associated with
260261
// the action.
261262
func (a *Action) GetIssueInfos() []string {
262-
return strings.SplitN(a.Content, "|", 2)
263+
return strings.SplitN(a.Content, "|", 3)
263264
}
264265

265266
// GetIssueTitle returns the title of first issue associated

models/branches.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ func (protectBranch *ProtectedBranch) HasEnoughApprovals(pr *PullRequest) bool {
157157
func (protectBranch *ProtectedBranch) GetGrantedApprovalsCount(pr *PullRequest) int64 {
158158
sess := x.Where("issue_id = ?", pr.IssueID).
159159
And("type = ?", ReviewTypeApprove).
160-
And("official = ?", true)
160+
And("official = ?", true).
161+
And("dismissed = ?", false)
161162
if protectBranch.DismissStaleApprovals {
162163
sess = sess.And("stale = ?", false)
163164
}
@@ -178,6 +179,7 @@ func (protectBranch *ProtectedBranch) MergeBlockedByRejectedReview(pr *PullReque
178179
rejectExist, err := x.Where("issue_id = ?", pr.IssueID).
179180
And("type = ?", ReviewTypeReject).
180181
And("official = ?", true).
182+
And("dismissed = ?", false).
181183
Exist(new(Review))
182184
if err != nil {
183185
log.Error("MergeBlockedByRejectedReview: %v", err)

models/consistency.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,13 @@ func CountWrongUserType() (int64, error) {
305305
func FixWrongUserType() (int64, error) {
306306
return x.Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Cols("type").NoAutoTime().Update(&User{Type: 1})
307307
}
308+
309+
// CountCommentTypeLabelWithEmptyLabel count label comments with empty label
310+
func CountCommentTypeLabelWithEmptyLabel() (int64, error) {
311+
return x.Where(builder.Eq{"type": CommentTypeLabel, "label_id": 0}).Count(new(Comment))
312+
}
313+
314+
// FixCommentTypeLabelWithEmptyLabel count label comments with empty label
315+
func FixCommentTypeLabelWithEmptyLabel() (int64, error) {
316+
return x.Where(builder.Eq{"type": CommentTypeLabel, "label_id": 0}).Delete(new(Comment))
317+
}

models/fixtures/review.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@
104104
issue_id: 12
105105
official: true
106106
updated_unix: 1603196749
107-
created_unix: 1603196749
107+
created_unix: 1603196749

models/issue_comment.go

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,69 +36,71 @@ const (
3636

3737
// Enumerate all the comment types
3838
const (
39-
// Plain comment, can be associated with a commit (CommitID > 0) and a line (LineNum > 0)
39+
// 0 Plain comment, can be associated with a commit (CommitID > 0) and a line (LineNum > 0)
4040
CommentTypeComment CommentType = iota
41-
CommentTypeReopen
42-
CommentTypeClose
41+
CommentTypeReopen // 1
42+
CommentTypeClose // 2
4343

44-
// References.
44+
// 3 References.
4545
CommentTypeIssueRef
46-
// Reference from a commit (not part of a pull request)
46+
// 4 Reference from a commit (not part of a pull request)
4747
CommentTypeCommitRef
48-
// Reference from a comment
48+
// 5 Reference from a comment
4949
CommentTypeCommentRef
50-
// Reference from a pull request
50+
// 6 Reference from a pull request
5151
CommentTypePullRef
52-
// Labels changed
52+
// 7 Labels changed
5353
CommentTypeLabel
54-
// Milestone changed
54+
// 8 Milestone changed
5555
CommentTypeMilestone
56-
// Assignees changed
56+
// 9 Assignees changed
5757
CommentTypeAssignees
58-
// Change Title
58+
// 10 Change Title
5959
CommentTypeChangeTitle
60-
// Delete Branch
60+
// 11 Delete Branch
6161
CommentTypeDeleteBranch
62-
// Start a stopwatch for time tracking
62+
// 12 Start a stopwatch for time tracking
6363
CommentTypeStartTracking
64-
// Stop a stopwatch for time tracking
64+
// 13 Stop a stopwatch for time tracking
6565
CommentTypeStopTracking
66-
// Add time manual for time tracking
66+
// 14 Add time manual for time tracking
6767
CommentTypeAddTimeManual
68-
// Cancel a stopwatch for time tracking
68+
// 15 Cancel a stopwatch for time tracking
6969
CommentTypeCancelTracking
70-
// Added a due date
70+
// 16 Added a due date
7171
CommentTypeAddedDeadline
72-
// Modified the due date
72+
// 17 Modified the due date
7373
CommentTypeModifiedDeadline
74-
// Removed a due date
74+
// 18 Removed a due date
7575
CommentTypeRemovedDeadline
76-
// Dependency added
76+
// 19 Dependency added
7777
CommentTypeAddDependency
78-
//Dependency removed
78+
// 20 Dependency removed
7979
CommentTypeRemoveDependency
80-
// Comment a line of code
80+
// 21 Comment a line of code
8181
CommentTypeCode
82-
// Reviews a pull request by giving general feedback
82+
// 22 Reviews a pull request by giving general feedback
8383
CommentTypeReview
84-
// Lock an issue, giving only collaborators access
84+
// 23 Lock an issue, giving only collaborators access
8585
CommentTypeLock
86-
// Unlocks a previously locked issue
86+
// 24 Unlocks a previously locked issue
8787
CommentTypeUnlock
88-
// Change pull request's target branch
88+
// 25 Change pull request's target branch
8989
CommentTypeChangeTargetBranch
90-
// Delete time manual for time tracking
90+
// 26 Delete time manual for time tracking
9191
CommentTypeDeleteTimeManual
92-
// add or remove Request from one
92+
// 27 add or remove Request from one
9393
CommentTypeReviewRequest
94-
// merge pull request
94+
// 28 merge pull request
9595
CommentTypeMergePull
96-
// push to PR head branch
96+
// 29 push to PR head branch
9797
CommentTypePullPush
98-
// Project changed
98+
// 30 Project changed
9999
CommentTypeProject
100-
// Project board changed
100+
// 31 Project board changed
101101
CommentTypeProjectBoard
102+
// Dismiss Review
103+
CommentTypeDismissReview
102104
)
103105

104106
// CommentTag defines comment tag type

models/issue_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ func (issues IssueList) getApprovalCounts(e Engine) (map[int64][]*ReviewCount, e
530530
}
531531
sess := e.In("issue_id", ids)
532532
err := sess.Select("issue_id, type, count(id) as `count`").
533-
Where("official = ?", true).
533+
Where("official = ? AND dismissed = ?", true, false).
534534
GroupBy("issue_id, type").
535535
OrderBy("issue_id").
536536
Table("review").

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ var migrations = []Migration{
287287
// v169 -> v170
288288
NewMigration("Update DeleteBranch comments to set the old_ref to the commit_sha", commentTypeDeleteBranchUseOldRef),
289289
// v170 -> v171
290+
NewMigration("Add Dismissed to Review table", addDismissedReviewColumn),
291+
// v171 -> v172
290292
NewMigration("Add agit style pull request support", addAgitStylePullRequest),
291293
}
292294

models/migrations/v170.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ import (
1010
"xorm.io/xorm"
1111
)
1212

13-
func addAgitStylePullRequest(x *xorm.Engine) error {
14-
type PullRequestStyle int
15-
16-
type PullRequest struct {
17-
Style PullRequestStyle
13+
func addDismissedReviewColumn(x *xorm.Engine) error {
14+
type Review struct {
15+
Dismissed bool `xorm:"NOT NULL DEFAULT false"`
1816
}
1917

20-
if err := x.Sync2(new(PullRequest)); err != nil {
18+
if err := x.Sync2(new(Review)); err != nil {
2119
return fmt.Errorf("Sync2: %v", err)
2220
}
2321
return nil

models/migrations/v171.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"fmt"
9+
10+
"xorm.io/xorm"
11+
)
12+
13+
func addAgitStylePullRequest(x *xorm.Engine) error {
14+
type PullRequestStyle int
15+
16+
type PullRequest struct {
17+
Style PullRequestStyle
18+
}
19+
20+
if err := x.Sync2(new(PullRequest)); err != nil {
21+
return fmt.Errorf("Sync2: %v", err)
22+
}
23+
return nil
24+
}

models/project_board.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type ProjectBoard struct {
3636
ID int64 `xorm:"pk autoincr"`
3737
Title string
3838
Default bool `xorm:"NOT NULL DEFAULT false"` // issues not assigned to a specific board will be assigned to this board
39+
Sorting int8 `xorm:"DEFAULT 0"`
3940

4041
ProjectID int64 `xorm:"INDEX NOT NULL"`
4142
CreatorID int64 `xorm:"NOT NULL"`
@@ -157,15 +158,24 @@ func getProjectBoard(e Engine, boardID int64) (*ProjectBoard, error) {
157158
return board, nil
158159
}
159160

160-
// UpdateProjectBoard updates the title of a project board
161+
// UpdateProjectBoard updates a project board
161162
func UpdateProjectBoard(board *ProjectBoard) error {
162163
return updateProjectBoard(x, board)
163164
}
164165

165166
func updateProjectBoard(e Engine, board *ProjectBoard) error {
166-
_, err := e.ID(board.ID).Cols(
167-
"title",
168-
).Update(board)
167+
var fieldToUpdate []string
168+
169+
if board.Sorting != 0 {
170+
fieldToUpdate = append(fieldToUpdate, "sorting")
171+
}
172+
173+
if board.Title != "" {
174+
fieldToUpdate = append(fieldToUpdate, "title")
175+
}
176+
177+
_, err := e.ID(board.ID).Cols(fieldToUpdate...).Update(board)
178+
169179
return err
170180
}
171181

@@ -178,7 +188,7 @@ func GetProjectBoards(projectID int64) (ProjectBoardList, error) {
178188
func getProjectBoards(e Engine, projectID int64) ([]*ProjectBoard, error) {
179189
var boards = make([]*ProjectBoard, 0, 5)
180190

181-
if err := e.Where("project_id=? AND `default`=?", projectID, false).Find(&boards); err != nil {
191+
if err := e.Where("project_id=? AND `default`=?", projectID, false).OrderBy("Sorting").Find(&boards); err != nil {
182192
return nil, err
183193
}
184194

@@ -277,3 +287,17 @@ func (bs ProjectBoardList) LoadIssues() (IssueList, error) {
277287
}
278288
return issues, nil
279289
}
290+
291+
// UpdateProjectBoardSorting update project board sorting
292+
func UpdateProjectBoardSorting(bs ProjectBoardList) error {
293+
for i := range bs {
294+
_, err := x.ID(bs[i].ID).Cols(
295+
"sorting",
296+
).Update(bs[i])
297+
298+
if err != nil {
299+
return err
300+
}
301+
}
302+
return nil
303+
}

models/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (pr *PullRequest) GetApprovalCounts() ([]*ReviewCount, error) {
249249
func (pr *PullRequest) getApprovalCounts(e Engine) ([]*ReviewCount, error) {
250250
rCounts := make([]*ReviewCount, 0, 6)
251251
sess := e.Where("issue_id = ?", pr.IssueID)
252-
return rCounts, sess.Select("issue_id, type, count(id) as `count`").Where("official = ?", true).GroupBy("issue_id, type").Table("review").Find(&rCounts)
252+
return rCounts, sess.Select("issue_id, type, count(id) as `count`").Where("official = ? AND dismissed = ?", true, false).GroupBy("issue_id, type").Table("review").Find(&rCounts)
253253
}
254254

255255
// GetApprovers returns the approvers of the pull request

0 commit comments

Comments
 (0)