Skip to content

Commit 54f04f4

Browse files
committed
Merge remote-tracking branch 'origin/master' into xorm-session-provider
2 parents 6c19eef + f3847c9 commit 54f04f4

File tree

217 files changed

+17099
-5158
lines changed

Some content is hidden

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

217 files changed

+17099
-5158
lines changed

custom/conf/app.example.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,14 +556,16 @@ 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.
562564
;If left empty or no valid values are specified, the default is off (no checking)
563565
;Classes include "lower,upper,digit,spec"
564566
PASSWORD_COMPLEXITY = off
565567
; Password Hash algorithm, either "argon2", "pbkdf2", "scrypt" or "bcrypt"
566-
PASSWORD_HASH_ALGO = argon2
568+
PASSWORD_HASH_ALGO = pbkdf2
567569
; Set false to allow JavaScript to read CSRF cookie
568570
CSRF_COOKIE_HTTP_ONLY = true
569571
; Validate against https://haveibeenpwned.com/Passwords to see if a password has been exposed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,12 @@ 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.
402403
- `INTERNAL_TOKEN_URI`: **<empty>**: Instead of defining internal token in the configuration, this configuration option can be used to give Gitea a path to a file that contains the internal token (example value: `file:/etc/gitea/internal_token`)
403-
- `PASSWORD_HASH_ALGO`: **argon2**: The hash algorithm to use \[argon2, pbkdf2, scrypt, bcrypt\].
404+
- `PASSWORD_HASH_ALGO`: **pbkdf2**: The hash algorithm to use \[argon2, pbkdf2, scrypt, bcrypt\], argon2 will spend more memory than others.
404405
- `CSRF_COOKIE_HTTP_ONLY`: **true**: Set false to allow JavaScript to read CSRF cookie.
405406
- `MIN_PASSWORD_LENGTH`: **6**: Minimum password length for new users.
406407
- `PASSWORD_COMPLEXITY`: **off**: Comma separated list of character classes required to pass minimum complexity. If left empty or no valid values are specified, checking is disabled (off):

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/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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ const (
9999
CommentTypeProject
100100
// 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ 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
292+
NewMigration("Add Sorting to ProjectBoard table", addSortingColToProjectBoard),
293+
// v172 -> v173
290294
NewMigration("Add sessions table for go-chi/session", addSessionTable),
291295
}
292296

models/migrations/v170.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 addDismissedReviewColumn(x *xorm.Engine) error {
14+
type Review struct {
15+
Dismissed bool `xorm:"NOT NULL DEFAULT false"`
16+
}
17+
18+
if err := x.Sync2(new(Review)); err != nil {
19+
return fmt.Errorf("Sync2: %v", err)
20+
}
21+
return nil
22+
}

models/migrations/v171.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 addSortingColToProjectBoard(x *xorm.Engine) error {
14+
type ProjectBoard struct {
15+
Sorting int8 `xorm:"NOT NULL DEFAULT 0"`
16+
}
17+
18+
if err := x.Sync2(new(ProjectBoard)); err != nil {
19+
return fmt.Errorf("Sync2: %v", err)
20+
}
21+
return nil
22+
}
File renamed without changes.

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:"NOT NULL 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
@@ -234,7 +234,7 @@ func (pr *PullRequest) GetApprovalCounts() ([]*ReviewCount, error) {
234234
func (pr *PullRequest) getApprovalCounts(e Engine) ([]*ReviewCount, error) {
235235
rCounts := make([]*ReviewCount, 0, 6)
236236
sess := e.Where("issue_id = ?", pr.IssueID)
237-
return rCounts, sess.Select("issue_id, type, count(id) as `count`").Where("official = ?", true).GroupBy("issue_id, type").Table("review").Find(&rCounts)
237+
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)
238238
}
239239

240240
// GetApprovers returns the approvers of the pull request

models/review.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ type Review struct {
6363
IssueID int64 `xorm:"index"`
6464
Content string `xorm:"TEXT"`
6565
// Official is a review made by an assigned approver (counts towards approval)
66-
Official bool `xorm:"NOT NULL DEFAULT false"`
67-
CommitID string `xorm:"VARCHAR(40)"`
68-
Stale bool `xorm:"NOT NULL DEFAULT false"`
66+
Official bool `xorm:"NOT NULL DEFAULT false"`
67+
CommitID string `xorm:"VARCHAR(40)"`
68+
Stale bool `xorm:"NOT NULL DEFAULT false"`
69+
Dismissed bool `xorm:"NOT NULL DEFAULT false"`
6970

7071
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
7172
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
@@ -466,8 +467,8 @@ func GetReviewersByIssueID(issueID int64) ([]*Review, error) {
466467
}
467468

468469
// Get latest review of each reviwer, sorted in order they were made
469-
if err := sess.SQL("SELECT * FROM review WHERE id IN (SELECT max(id) as id FROM review WHERE issue_id = ? AND reviewer_team_id = 0 AND type in (?, ?, ?) AND original_author_id = 0 GROUP BY issue_id, reviewer_id) ORDER BY review.updated_unix ASC",
470-
issueID, ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest).
470+
if err := sess.SQL("SELECT * FROM review WHERE id IN (SELECT max(id) as id FROM review WHERE issue_id = ? AND reviewer_team_id = 0 AND type in (?, ?, ?) AND dismissed = ? AND original_author_id = 0 GROUP BY issue_id, reviewer_id) ORDER BY review.updated_unix ASC",
471+
issueID, ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest, false).
471472
Find(&reviews); err != nil {
472473
return nil, err
473474
}
@@ -558,6 +559,19 @@ func MarkReviewsAsNotStale(issueID int64, commitID string) (err error) {
558559
return
559560
}
560561

562+
// DismissReview change the dismiss status of a review
563+
func DismissReview(review *Review, isDismiss bool) (err error) {
564+
if review.Dismissed == isDismiss || (review.Type != ReviewTypeApprove && review.Type != ReviewTypeReject) {
565+
return nil
566+
}
567+
568+
review.Dismissed = isDismiss
569+
570+
_, err = x.Cols("dismissed").Update(review)
571+
572+
return
573+
}
574+
561575
// InsertReviews inserts review and review comments
562576
func InsertReviews(reviews []*Review) error {
563577
sess := x.NewSession()

models/review_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,13 @@ func TestGetReviewersByIssueID(t *testing.T) {
142142
}
143143
}
144144
}
145+
146+
func TestDismissReview(t *testing.T) {
147+
review1 := AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
148+
review2 := AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
149+
assert.NoError(t, DismissReview(review1, true))
150+
assert.NoError(t, DismissReview(review2, true))
151+
assert.NoError(t, DismissReview(review2, true))
152+
assert.NoError(t, DismissReview(review2, false))
153+
assert.NoError(t, DismissReview(review2, false))
154+
}

0 commit comments

Comments
 (0)