Skip to content

Commit 3d83b19

Browse files
committed
Merge branch 'main' of https://github.com/go-gitea/gitea into refactor-webhook
2 parents bcbd291 + fdf9ab1 commit 3d83b19

File tree

31 files changed

+456
-140
lines changed

31 files changed

+456
-140
lines changed

custom/conf/app.example.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,20 +1155,20 @@ PATH =
11551155
;STARTUP_TIMEOUT = 30s
11561156
;;
11571157
;; Issue indexer queue, currently support: channel, levelqueue or redis, default is levelqueue (deprecated - use [queue.issue_indexer])
1158-
;ISSUE_INDEXER_QUEUE_TYPE = levelqueue
1158+
;ISSUE_INDEXER_QUEUE_TYPE = levelqueue; **DEPRECATED** use settings in `[queue.issue_indexer]`.
11591159
;;
11601160
;; When ISSUE_INDEXER_QUEUE_TYPE is levelqueue, this will be the path where the queue will be saved.
11611161
;; This can be overridden by `ISSUE_INDEXER_QUEUE_CONN_STR`.
11621162
;; default is queues/common
1163-
;ISSUE_INDEXER_QUEUE_DIR = queues/common
1163+
;ISSUE_INDEXER_QUEUE_DIR = queues/common; **DEPRECATED** use settings in `[queue.issue_indexer]`.
11641164
;;
11651165
;; When `ISSUE_INDEXER_QUEUE_TYPE` is `redis`, this will store the redis connection string.
11661166
;; When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this is a directory or additional options of
11671167
;; the form `leveldb://path/to/db?option=value&....`, and overrides `ISSUE_INDEXER_QUEUE_DIR`.
1168-
;ISSUE_INDEXER_QUEUE_CONN_STR = "addrs=127.0.0.1:6379 db=0"
1168+
;ISSUE_INDEXER_QUEUE_CONN_STR = "addrs=127.0.0.1:6379 db=0"; **DEPRECATED** use settings in `[queue.issue_indexer]`.
11691169
;;
11701170
;; Batch queue number, default is 20
1171-
;ISSUE_INDEXER_QUEUE_BATCH_NUMBER = 20
1171+
;ISSUE_INDEXER_QUEUE_BATCH_NUMBER = 20; **DEPRECATED** use settings in `[queue.issue_indexer]`.
11721172

11731173
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11741174
;; Repository Indexer settings
@@ -1197,7 +1197,7 @@ PATH =
11971197
;REPO_INDEXER_EXCLUDE =
11981198
;;
11991199
;;
1200-
;UPDATE_BUFFER_LEN = 20
1200+
;UPDATE_BUFFER_LEN = 20; **DEPRECATED** use settings in `[queue.issue_indexer]`.
12011201
;MAX_FILE_SIZE = 1048576
12021202

12031203
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,10 @@ relation to port exhaustion.
356356
- `ISSUE_INDEXER_NAME`: **gitea_issues**: Issue indexer name, available when ISSUE_INDEXER_TYPE is elasticsearch
357357
- `ISSUE_INDEXER_PATH`: **indexers/issues.bleve**: Index file used for issue search; available when ISSUE_INDEXER_TYPE is bleve and elasticsearch.
358358
- The next 4 configuration values are deprecated and should be set in `queue.issue_indexer` however are kept for backwards compatibility:
359-
- `ISSUE_INDEXER_QUEUE_TYPE`: **levelqueue**: Issue indexer queue, currently supports:`channel`, `levelqueue`, `redis`.
360-
- `ISSUE_INDEXER_QUEUE_DIR`: **queues/common**: When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this will be the path where the queue will be saved. (Previously this was `indexers/issues.queue`.)
361-
- `ISSUE_INDEXER_QUEUE_CONN_STR`: **addrs=127.0.0.1:6379 db=0**: When `ISSUE_INDEXER_QUEUE_TYPE` is `redis`, this will store the redis connection string. When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this is a directory or additional options of the form `leveldb://path/to/db?option=value&....`, and overrides `ISSUE_INDEXER_QUEUE_DIR`.
362-
- `ISSUE_INDEXER_QUEUE_BATCH_NUMBER`: **20**: Batch queue number.
359+
- `ISSUE_INDEXER_QUEUE_TYPE`: **levelqueue**: Issue indexer queue, currently supports:`channel`, `levelqueue`, `redis`. **DEPRECATED** use settings in `[queue.issue_indexer]`.
360+
- `ISSUE_INDEXER_QUEUE_DIR`: **queues/common**: When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this will be the path where the queue will be saved. **DEPRECATED** use settings in `[queue.issue_indexer]`.
361+
- `ISSUE_INDEXER_QUEUE_CONN_STR`: **addrs=127.0.0.1:6379 db=0**: When `ISSUE_INDEXER_QUEUE_TYPE` is `redis`, this will store the redis connection string. When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this is a directory or additional options of the form `leveldb://path/to/db?option=value&....`, and overrides `ISSUE_INDEXER_QUEUE_DIR`. **DEPRECATED** use settings in `[queue.issue_indexer]`.
362+
- `ISSUE_INDEXER_QUEUE_BATCH_NUMBER`: **20**: Batch queue number. **DEPRECATED** use settings in `[queue.issue_indexer]`.
363363

364364
- `REPO_INDEXER_ENABLED`: **false**: Enables code search (uses a lot of disk space, about 6 times more than the repository size).
365365
- `REPO_INDEXER_TYPE`: **bleve**: Code search engine type, could be `bleve` or `elasticsearch`.
@@ -370,7 +370,7 @@ relation to port exhaustion.
370370
- `REPO_INDEXER_INCLUDE`: **empty**: A comma separated list of glob patterns (see https://github.com/gobwas/glob) to **include** in the index. Use `**.txt` to match any files with .txt extension. An empty list means include all files.
371371
- `REPO_INDEXER_EXCLUDE`: **empty**: A comma separated list of glob patterns (see https://github.com/gobwas/glob) to **exclude** from the index. Files that match this list will not be indexed, even if they match in `REPO_INDEXER_INCLUDE`.
372372
- `REPO_INDEXER_EXCLUDE_VENDORED`: **true**: Exclude vendored files from index.
373-
- `UPDATE_BUFFER_LEN`: **20**: Buffer length of index request.
373+
- `UPDATE_BUFFER_LEN`: **20**: Buffer length of index request. **DEPRECATED** use settings in `[queue.issue_indexer]`.
374374
- `MAX_FILE_SIZE`: **1048576**: Maximum size in bytes of files to be indexed.
375375
- `STARTUP_TIMEOUT`: **30s**: If the indexer takes longer than this timeout to start - fail. (This timeout will be added to the hammer time above for child processes - as bleve will not start until the previous parent is shutdown.) Set to zero to never timeout.
376376

integrations/api_issue_test.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ func TestAPIListIssues(t *testing.T) {
2525

2626
session := loginUser(t, owner.Name)
2727
token := getTokenForLoggedInUser(t, session)
28-
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues?state=all&token=%s",
29-
owner.Name, repo.Name, token)
30-
resp := session.MakeRequest(t, req, http.StatusOK)
28+
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner.Name, repo.Name))
29+
30+
link.RawQuery = url.Values{"token": {token}, "state": {"all"}}.Encode()
31+
resp := session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
3132
var apiIssues []*api.Issue
3233
DecodeJSON(t, resp, &apiIssues)
3334
assert.Len(t, apiIssues, models.GetCount(t, &models.Issue{RepoID: repo.ID}))
@@ -36,15 +37,34 @@ func TestAPIListIssues(t *testing.T) {
3637
}
3738

3839
// test milestone filter
39-
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues?state=all&type=all&milestones=ignore,milestone1,3,4&token=%s",
40-
owner.Name, repo.Name, token)
41-
resp = session.MakeRequest(t, req, http.StatusOK)
40+
link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "type": {"all"}, "milestones": {"ignore,milestone1,3,4"}}.Encode()
41+
resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
4242
DecodeJSON(t, resp, &apiIssues)
4343
if assert.Len(t, apiIssues, 2) {
4444
assert.EqualValues(t, 3, apiIssues[0].Milestone.ID)
4545
assert.EqualValues(t, 1, apiIssues[1].Milestone.ID)
4646
}
4747

48+
link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "created_by": {"user2"}}.Encode()
49+
resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
50+
DecodeJSON(t, resp, &apiIssues)
51+
if assert.Len(t, apiIssues, 1) {
52+
assert.EqualValues(t, 5, apiIssues[0].ID)
53+
}
54+
55+
link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "assigned_by": {"user1"}}.Encode()
56+
resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
57+
DecodeJSON(t, resp, &apiIssues)
58+
if assert.Len(t, apiIssues, 1) {
59+
assert.EqualValues(t, 1, apiIssues[0].ID)
60+
}
61+
62+
link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "mentioned_by": {"user4"}}.Encode()
63+
resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
64+
DecodeJSON(t, resp, &apiIssues)
65+
if assert.Len(t, apiIssues, 1) {
66+
assert.EqualValues(t, 1, apiIssues[0].ID)
67+
}
4868
}
4969

5070
func TestAPICreateIssue(t *testing.T) {

models/fixtures/issue_user.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
uid: 4
1818
issue_id: 1
1919
is_read: false
20-
is_mentioned: false
20+
is_mentioned: true

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ var migrations = []Migration{
318318
// v183 -> v184
319319
NewMigration("Create PushMirror table", createPushMirrorTable),
320320
// v184 -> v185
321+
NewMigration("Rename Task errors to message", renameTaskErrorsToMessage),
322+
// v185 -> v186
321323
NewMigration("Drop unneeded webhook related columns", dropWebhookColumns),
322324
}
323325

models/migrations/v184.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,43 @@
55
package migrations
66

77
import (
8+
"fmt"
9+
10+
"code.gitea.io/gitea/modules/setting"
11+
812
"xorm.io/xorm"
913
)
1014

11-
func dropWebhookColumns(x *xorm.Engine) error {
12-
// Make sure the columns exist before dropping them
13-
type Webhook struct {
14-
Signature string `xorm:"TEXT"`
15-
IsSSL bool `xorm:"is_ssl"`
16-
}
17-
if err := x.Sync2(new(Webhook)); err != nil {
18-
return err
19-
}
20-
21-
type HookTask struct {
22-
Typ string `xorm:"VARCHAR(16) index"`
23-
URL string `xorm:"TEXT"`
24-
Signature string `xorm:"TEXT"`
25-
HTTPMethod string `xorm:"http_method"`
26-
ContentType int
27-
IsSSL bool
28-
}
29-
if err := x.Sync2(new(HookTask)); err != nil {
30-
return err
15+
func renameTaskErrorsToMessage(x *xorm.Engine) error {
16+
type Task struct {
17+
Errors string `xorm:"TEXT"` // if task failed, saved the error reason
18+
Type int
19+
Status int `xorm:"index"`
3120
}
3221

3322
sess := x.NewSession()
3423
defer sess.Close()
3524
if err := sess.Begin(); err != nil {
3625
return err
3726
}
38-
if err := dropTableColumns(sess, "webhook", "signature", "is_ssl"); err != nil {
39-
return err
40-
}
41-
if err := dropTableColumns(sess, "hook_task", "typ", "url", "signature", "http_method", "content_type", "is_ssl"); err != nil {
42-
return err
27+
28+
if err := sess.Sync2(new(Task)); err != nil {
29+
return fmt.Errorf("error on Sync2: %v", err)
4330
}
4431

32+
switch {
33+
case setting.Database.UseMySQL:
34+
if _, err := sess.Exec("ALTER TABLE `task` CHANGE errors message text"); err != nil {
35+
return err
36+
}
37+
case setting.Database.UseMSSQL:
38+
if _, err := sess.Exec("sp_rename 'task.errors', 'message', 'COLUMN'"); err != nil {
39+
return err
40+
}
41+
default:
42+
if _, err := sess.Exec("ALTER TABLE `task` RENAME COLUMN errors TO message"); err != nil {
43+
return err
44+
}
45+
}
4546
return sess.Commit()
4647
}

models/migrations/v185.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
"xorm.io/xorm"
9+
)
10+
11+
func dropWebhookColumns(x *xorm.Engine) error {
12+
// Make sure the columns exist before dropping them
13+
type Webhook struct {
14+
Signature string `xorm:"TEXT"`
15+
IsSSL bool `xorm:"is_ssl"`
16+
}
17+
if err := x.Sync2(new(Webhook)); err != nil {
18+
return err
19+
}
20+
21+
type HookTask struct {
22+
Typ string `xorm:"VARCHAR(16) index"`
23+
URL string `xorm:"TEXT"`
24+
Signature string `xorm:"TEXT"`
25+
HTTPMethod string `xorm:"http_method"`
26+
ContentType int
27+
IsSSL bool
28+
}
29+
if err := x.Sync2(new(HookTask)); err != nil {
30+
return err
31+
}
32+
33+
sess := x.NewSession()
34+
defer sess.Close()
35+
if err := sess.Begin(); err != nil {
36+
return err
37+
}
38+
if err := dropTableColumns(sess, "webhook", "signature", "is_ssl"); err != nil {
39+
return err
40+
}
41+
if err := dropTableColumns(sess, "hook_task", "typ", "url", "signature", "http_method", "content_type", "is_ssl"); err != nil {
42+
return err
43+
}
44+
45+
return sess.Commit()
46+
}

models/notification.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type FindNotificationOptions struct {
7474
RepoID int64
7575
IssueID int64
7676
Status []NotificationStatus
77+
Source []NotificationSource
7778
UpdatedAfterUnix int64
7879
UpdatedBeforeUnix int64
7980
}
@@ -93,6 +94,9 @@ func (opts *FindNotificationOptions) ToCond() builder.Cond {
9394
if len(opts.Status) > 0 {
9495
cond = cond.And(builder.In("notification.status", opts.Status))
9596
}
97+
if len(opts.Source) > 0 {
98+
cond = cond.And(builder.In("notification.source", opts.Source))
99+
}
96100
if opts.UpdatedAfterUnix != 0 {
97101
cond = cond.And(builder.Gte{"notification.updated_unix": opts.UpdatedAfterUnix})
98102
}
@@ -111,13 +115,13 @@ func (opts *FindNotificationOptions) ToSession(e Engine) *xorm.Session {
111115
return sess
112116
}
113117

114-
func getNotifications(e Engine, options FindNotificationOptions) (nl NotificationList, err error) {
118+
func getNotifications(e Engine, options *FindNotificationOptions) (nl NotificationList, err error) {
115119
err = options.ToSession(e).OrderBy("notification.updated_unix DESC").Find(&nl)
116120
return
117121
}
118122

119123
// GetNotifications returns all notifications that fit to the given options.
120-
func GetNotifications(opts FindNotificationOptions) (NotificationList, error) {
124+
func GetNotifications(opts *FindNotificationOptions) (NotificationList, error) {
121125
return getNotifications(x, opts)
122126
}
123127

models/task.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ type Task struct {
3232
StartTime timeutil.TimeStamp
3333
EndTime timeutil.TimeStamp
3434
PayloadContent string `xorm:"TEXT"`
35-
Errors string `xorm:"TEXT"` // if task failed, saved the error reason
35+
Message string `xorm:"TEXT"` // if task failed, saved the error reason
3636
Created timeutil.TimeStamp `xorm:"created"`
3737
}
3838

39+
// TranslatableMessage represents JSON struct that can be translated with a Locale
40+
type TranslatableMessage struct {
41+
Format string
42+
Args []interface{} `json:"omitempty"`
43+
}
44+
3945
// LoadRepo loads repository of the task
4046
func (task *Task) LoadRepo() error {
4147
return task.loadRepo(x)

modules/git/repo_language_stats_nogogit.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
2525
defer cancel()
2626

2727
writeID := func(id string) error {
28-
_, err := batchStdinWriter.Write([]byte(id))
29-
if err != nil {
30-
return err
31-
}
32-
_, err = batchStdinWriter.Write([]byte{'\n'})
28+
_, err := batchStdinWriter.Write([]byte(id + "\n"))
3329
return err
3430
}
3531

@@ -85,10 +81,10 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
8581
}
8682

8783
sizeToRead := size
88-
discard := int64(0)
84+
discard := int64(1)
8985
if size > fileSizeLimit {
9086
sizeToRead = fileSizeLimit
91-
discard = size - fileSizeLimit
87+
discard = size - fileSizeLimit + 1
9288
}
9389

9490
_, err = contentBuf.ReadFrom(io.LimitReader(batchReader, sizeToRead))

modules/migrations/base/messenger.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 base
6+
7+
// Messenger is a formatting function similar to i18n.Tr
8+
type Messenger func(key string, args ...interface{})
9+
10+
// NilMessenger represents an empty formatting function
11+
func NilMessenger(string, ...interface{}) {}

modules/migrations/dump.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ func DumpRepository(ctx context.Context, baseDir, ownerName string, opts base.Mi
555555
return err
556556
}
557557

558-
if err := migrateRepository(downloader, uploader, opts); err != nil {
558+
if err := migrateRepository(downloader, uploader, opts, nil); err != nil {
559559
if err1 := uploader.Rollback(); err1 != nil {
560560
log.Error("rollback failed: %v", err1)
561561
}
@@ -620,7 +620,7 @@ func RestoreRepository(ctx context.Context, baseDir string, ownerName, repoName
620620
}
621621
updateOptionsUnits(&migrateOpts, units)
622622

623-
if err = migrateRepository(downloader, uploader, migrateOpts); err != nil {
623+
if err = migrateRepository(downloader, uploader, migrateOpts, nil); err != nil {
624624
if err1 := uploader.Rollback(); err1 != nil {
625625
log.Error("rollback failed: %v", err1)
626626
}

modules/migrations/gitea_uploader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestGiteaUploadRepo(t *testing.T) {
4747
PullRequests: true,
4848
Private: true,
4949
Mirror: false,
50-
})
50+
}, nil)
5151
assert.NoError(t, err)
5252

5353
repo := models.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID, Name: repoName}).(*models.Repository)

0 commit comments

Comments
 (0)