Skip to content

Commit 7c511f4

Browse files
authored
Merge branch 'master' into feat/review_comments
2 parents ef98881 + 872d308 commit 7c511f4

Some content is hidden

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

48 files changed

+427
-318
lines changed

models/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ func SearchIssueIDsByKeyword(kw string, repoIDs []int64, limit, start int) (int6
16821682
)
16831683

16841684
var ids = make([]int64, 0, limit)
1685-
err := x.Distinct("id").Table("issue").Where(cond).Limit(limit, start).Find(&ids)
1685+
err := x.Distinct("id").Table("issue").Where(cond).OrderBy("`updated_unix` DESC").Limit(limit, start).Find(&ids)
16861686
if err != nil {
16871687
return 0, nil, err
16881688
}

models/issue_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func TestIssue_SearchIssueIDsByKeyword(t *testing.T) {
299299
total, ids, err = SearchIssueIDsByKeyword("for", []int64{1}, 10, 0)
300300
assert.NoError(t, err)
301301
assert.EqualValues(t, 5, total)
302-
assert.EqualValues(t, []int64{1, 2, 3, 5, 11}, ids)
302+
assert.ElementsMatch(t, []int64{1, 2, 3, 5, 11}, ids)
303303

304304
// issue1's comment id 2
305305
total, ids, err = SearchIssueIDsByKeyword("good", []int64{1}, 10, 0)

models/project_board.go

Lines changed: 75 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"code.gitea.io/gitea/modules/setting"
99
"code.gitea.io/gitea/modules/timeutil"
1010

11+
"xorm.io/builder"
1112
"xorm.io/xorm"
1213
)
1314

@@ -164,45 +165,99 @@ func UpdateProjectBoard(board *ProjectBoard) error {
164165
func updateProjectBoard(e Engine, board *ProjectBoard) error {
165166
_, err := e.ID(board.ID).Cols(
166167
"title",
167-
"default",
168168
).Update(board)
169169
return err
170170
}
171171

172172
// GetProjectBoards fetches all boards related to a project
173-
func GetProjectBoards(projectID int64) ([]*ProjectBoard, error) {
173+
// if no default board set, first board is a temporary "Uncategorized" board
174+
func GetProjectBoards(projectID int64) (ProjectBoardList, error) {
175+
return getProjectBoards(x, projectID)
176+
}
174177

178+
func getProjectBoards(e Engine, projectID int64) ([]*ProjectBoard, error) {
175179
var boards = make([]*ProjectBoard, 0, 5)
176180

177-
sess := x.Where("project_id=?", projectID)
178-
return boards, sess.Find(&boards)
181+
if err := e.Where("project_id=? AND `default`=?", projectID, false).Find(&boards); err != nil {
182+
return nil, err
183+
}
184+
185+
defaultB, err := getDefaultBoard(e, projectID)
186+
if err != nil {
187+
return nil, err
188+
}
189+
190+
return append([]*ProjectBoard{defaultB}, boards...), nil
179191
}
180192

181-
// GetUncategorizedBoard represents a board for issues not assigned to one
182-
func GetUncategorizedBoard(projectID int64) (*ProjectBoard, error) {
193+
// getDefaultBoard return default board and create a dummy if none exist
194+
func getDefaultBoard(e Engine, projectID int64) (*ProjectBoard, error) {
195+
var board ProjectBoard
196+
exist, err := e.Where("project_id=? AND `default`=?", projectID, true).Get(&board)
197+
if err != nil {
198+
return nil, err
199+
}
200+
if exist {
201+
return &board, nil
202+
}
203+
204+
// represents a board for issues not assigned to one
183205
return &ProjectBoard{
184206
ProjectID: projectID,
185207
Title: "Uncategorized",
186208
Default: true,
187209
}, nil
188210
}
189211

212+
// SetDefaultBoard represents a board for issues not assigned to one
213+
// if boardID is 0 unset default
214+
func SetDefaultBoard(projectID, boardID int64) error {
215+
sess := x
216+
217+
_, err := sess.Where(builder.Eq{
218+
"project_id": projectID,
219+
"`default`": true,
220+
}).Cols("`default`").Update(&ProjectBoard{Default: false})
221+
if err != nil {
222+
return err
223+
}
224+
225+
if boardID > 0 {
226+
_, err = sess.ID(boardID).Where(builder.Eq{"project_id": projectID}).
227+
Cols("`default`").Update(&ProjectBoard{Default: true})
228+
}
229+
230+
return err
231+
}
232+
190233
// LoadIssues load issues assigned to this board
191234
func (b *ProjectBoard) LoadIssues() (IssueList, error) {
192-
var boardID int64
193-
if !b.Default {
194-
boardID = b.ID
195-
196-
} else {
197-
// Issues without ProjectBoardID
198-
boardID = -1
199-
}
200-
issues, err := Issues(&IssuesOptions{
201-
ProjectBoardID: boardID,
202-
ProjectID: b.ProjectID,
203-
})
204-
b.Issues = issues
205-
return issues, err
235+
issueList := make([]*Issue, 0, 10)
236+
237+
if b.ID != 0 {
238+
issues, err := Issues(&IssuesOptions{
239+
ProjectBoardID: b.ID,
240+
ProjectID: b.ProjectID,
241+
})
242+
if err != nil {
243+
return nil, err
244+
}
245+
issueList = issues
246+
}
247+
248+
if b.Default {
249+
issues, err := Issues(&IssuesOptions{
250+
ProjectBoardID: -1, // Issues without ProjectBoardID
251+
ProjectID: b.ProjectID,
252+
})
253+
if err != nil {
254+
return nil, err
255+
}
256+
issueList = append(issueList, issues...)
257+
}
258+
259+
b.Issues = issueList
260+
return issueList, nil
206261
}
207262

208263
// LoadIssues load issues assigned to the boards

models/webhook.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -400,20 +400,6 @@ func GetWebhooksByOrgID(orgID int64, listOptions ListOptions) ([]*Webhook, error
400400
return ws, sess.Find(&ws, &Webhook{OrgID: orgID})
401401
}
402402

403-
// GetDefaultWebhook returns admin-default webhook by given ID.
404-
func GetDefaultWebhook(id int64) (*Webhook, error) {
405-
webhook := &Webhook{ID: id}
406-
has, err := x.
407-
Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, false).
408-
Get(webhook)
409-
if err != nil {
410-
return nil, err
411-
} else if !has {
412-
return nil, ErrWebhookNotExist{id}
413-
}
414-
return webhook, nil
415-
}
416-
417403
// GetDefaultWebhooks returns all admin-default webhooks.
418404
func GetDefaultWebhooks() ([]*Webhook, error) {
419405
return getDefaultWebhooks(x)
@@ -426,11 +412,11 @@ func getDefaultWebhooks(e Engine) ([]*Webhook, error) {
426412
Find(&webhooks)
427413
}
428414

429-
// GetSystemWebhook returns admin system webhook by given ID.
430-
func GetSystemWebhook(id int64) (*Webhook, error) {
415+
// GetSystemOrDefaultWebhook returns admin system or default webhook by given ID.
416+
func GetSystemOrDefaultWebhook(id int64) (*Webhook, error) {
431417
webhook := &Webhook{ID: id}
432418
has, err := x.
433-
Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, true).
419+
Where("repo_id=? AND org_id=?", 0, 0).
434420
Get(webhook)
435421
if err != nil {
436422
return nil, err

modules/base/tool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const sniffLen = 512
3535
// SVGMimeType MIME type of SVG images.
3636
const SVGMimeType = "image/svg+xml"
3737

38-
var svgTagRegex = regexp.MustCompile(`(?s)\A\s*(?:<!--.*?-->\s*)*<svg\b`)
39-
var svgTagInXMLRegex = regexp.MustCompile(`(?s)\A<\?xml\b.*?\?>\s*(?:<!--.*?-->\s*)*<svg\b`)
38+
var svgTagRegex = regexp.MustCompile(`(?si)\A\s*(?:(<!--.*?-->|<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg[\s>\/]`)
39+
var svgTagInXMLRegex = regexp.MustCompile(`(?si)\A<\?xml\b.*?\?>\s*(?:(<!--.*?-->|<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg[\s>\/]`)
4040

4141
// EncodeMD5 encodes string to md5 hex value.
4242
func EncodeMD5(str string) string {

modules/base/tool_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ func TestIsSVGImageFile(t *testing.T) {
216216
assert.True(t, IsSVGImageFile([]byte(`<!-- Multiline
217217
Comment -->
218218
<svg></svg>`)))
219+
assert.True(t, IsSVGImageFile([]byte(`<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN"
220+
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">
221+
<svg></svg>`)))
219222
assert.True(t, IsSVGImageFile([]byte(`<?xml version="1.0" encoding="UTF-8"?>
220223
<!-- Comment -->
221224
<svg></svg>`)))
@@ -227,6 +230,11 @@ func TestIsSVGImageFile(t *testing.T) {
227230
<!-- Multline
228231
Comment -->
229232
<svg></svg>`)))
233+
assert.True(t, IsSVGImageFile([]byte(`<?xml version="1.0" encoding="UTF-8"?>
234+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
235+
<!-- Multline
236+
Comment -->
237+
<svg></svg>`)))
230238
assert.False(t, IsSVGImageFile([]byte{}))
231239
assert.False(t, IsSVGImageFile([]byte("svg")))
232240
assert.False(t, IsSVGImageFile([]byte("<svgfoo></svgfoo>")))

modules/indexer/issues/bleve.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ func (b *BleveIndexer) Search(keyword string, repoIDs []int64, limit, start int)
247247
newMatchPhraseQuery(keyword, "Comments", issueIndexerAnalyzer),
248248
))
249249
search := bleve.NewSearchRequestOptions(indexerQuery, limit, start, false)
250+
search.SortBy([]string{"-_score"})
250251

251252
result, err := b.indexer.Search(search)
252253
if err != nil {

modules/indexer/issues/elastic_search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (b *ElasticSearchIndexer) Search(keyword string, repoIDs []int64, limit, st
205205
searchResult, err := b.client.Search().
206206
Index(b.indexerName).
207207
Query(query).
208-
Sort("id", true).
208+
Sort("_score", false).
209209
From(start).Size(limit).
210210
Do(context.Background())
211211
if err != nil {

modules/indexer/issues/indexer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestBleveSearchIssues(t *testing.T) {
6565

6666
ids, err = SearchIssuesByKeyword([]int64{1}, "for")
6767
assert.NoError(t, err)
68-
assert.EqualValues(t, []int64{1, 2, 3, 5, 11}, ids)
68+
assert.ElementsMatch(t, []int64{1, 2, 3, 5, 11}, ids)
6969

7070
ids, err = SearchIssuesByKeyword([]int64{1}, "good")
7171
assert.NoError(t, err)
@@ -89,7 +89,7 @@ func TestDBSearchIssues(t *testing.T) {
8989

9090
ids, err = SearchIssuesByKeyword([]int64{1}, "for")
9191
assert.NoError(t, err)
92-
assert.EqualValues(t, []int64{1, 2, 3, 5, 11}, ids)
92+
assert.ElementsMatch(t, []int64{1, 2, 3, 5, 11}, ids)
9393

9494
ids, err = SearchIssuesByKeyword([]int64{1}, "good")
9595
assert.NoError(t, err)

options/locale/locale_cs-CZ.ini

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,8 +1997,6 @@ dashboard=Přehled
19971997
users=Uživatelské účty
19981998
organizations=Organizace
19991999
repositories=Repozitáře
2000-
hooks=Výchozí webové háčky
2001-
systemhooks=Systémové webové háčky
20022000
authentication=Zdroje ověření
20032001
emails=Uživatelské e-maily
20042002
config=Nastavení
@@ -2148,11 +2146,8 @@ repos.forks=Rozštěpení
21482146
repos.issues=Úkoly
21492147
repos.size=Velikost
21502148

2151-
hooks.desc=Webové háčky automaticky vytvářejí HTTP POST dotazy na server při určitých Gitea událostech. Webové háčky definované zde jsou výchozí a budou zkopírovány do všech nových repozitářů. Přečtěte si více v <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">průvodci webovými háčky</a>.
2152-
hooks.add_webhook=Přidat výchozí webový háček
2153-
hooks.update_webhook=Aktualizovat výchozí webový háček
21542149

2155-
systemhooks.desc=Webové háčky automaticky vytvářejí HTTP POST dotazy na server při určitých Gitea událostech. Webové háčky definované zde budou vykonány na všech repozitářích systému, proto prosím zvažte jakékoli důsledky, které to může mít na výkon. Přečtěte si více v <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">průvodci webovými háčky</a>.
2150+
systemhooks=Systémové webové háčky
21562151
systemhooks.add_webhook=Přidat systémový webový háček
21572152
systemhooks.update_webhook=Aktualizovat systémový webový háček
21582153

0 commit comments

Comments
 (0)