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

options/locale/locale_de-DE.ini

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,8 +1990,6 @@ dashboard=Dashboard
19901990
users=Benutzerkonten
19911991
organizations=Organisationen
19921992
repositories=Repositories
1993-
hooks=Standard-Webhooks
1994-
systemhooks=System-Webhooks
19951993
authentication=Authentifizierungsquellen
19961994
emails=Benutzer E-Mails
19971995
config=Konfiguration
@@ -2141,11 +2139,8 @@ repos.forks=Forks
21412139
repos.issues=Issues
21422140
repos.size=Größe
21432141

2144-
hooks.desc=Webhooks stellen automatisch HTTP POST-Anfragen an einen Server, wenn bestimmte Gitea-Ereignisse ausgelöst werden. Die hier definierten Webhooks sind Standardwerte und werden in alle neuen Repositories kopiert. Mehr Infos findest du in der <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">Webhooks-Anleitung</a>.
2145-
hooks.add_webhook=Standard-Webhook hinzufügen
2146-
hooks.update_webhook=Standard-Webhook aktualisieren
21472142

2148-
systemhooks.desc=Webhooks senden automatisch POST-HTTP-Anfragen an einen anderen Server, wenn ein bestimmtes Gitea-Event ausgelöst wird. Webhook-Events können von allen Repositories ausgelöst werden, beachte daher mögliche Leistungs-Implikationen. Mehr Informationen sind in der <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">Webhook-Anleitung in der Dokumentation</a> zu finden.
2143+
systemhooks=System-Webhooks
21492144
systemhooks.add_webhook=System-Webhook hinzufügen
21502145
systemhooks.update_webhook=System-Webhook aktualisieren
21512146

options/locale/locale_en-US.ini

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,8 @@ projects.board.edit_title = "New Board Name"
945945
projects.board.new_title = "New Board Name"
946946
projects.board.new_submit = "Submit"
947947
projects.board.new = "New Board"
948+
projects.board.set_default = "Set Default"
949+
projects.board.set_default_desc = "Set this board as default for uncategorized issues and pulls"
948950
projects.board.delete = "Delete Board"
949951
projects.board.deletion_desc = "Deleting a project board moves all related issues to 'Uncategorized'. Continue?"
950952
projects.open = Open
@@ -2001,8 +2003,7 @@ dashboard = Dashboard
20012003
users = User Accounts
20022004
organizations = Organizations
20032005
repositories = Repositories
2004-
hooks = Default Webhooks
2005-
systemhooks = System Webhooks
2006+
hooks = Webhooks
20062007
authentication = Authentication Sources
20072008
emails = User Emails
20082009
config = Configuration
@@ -2152,11 +2153,13 @@ repos.forks = Forks
21522153
repos.issues = Issues
21532154
repos.size = Size
21542155

2155-
hooks.desc = Webhooks automatically make HTTP POST requests to a server when certain Gitea events trigger. Webhooks defined here are defaults and will be copied into all new repositories. Read more in the <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">webhooks guide</a>.
2156-
hooks.add_webhook = Add Default Webhook
2157-
hooks.update_webhook = Update Default Webhook
2156+
defaulthooks = Default Webhooks
2157+
defaulthooks.desc = Webhooks automatically make HTTP POST requests to a server when certain Gitea events trigger. Webhooks defined here are defaults and will be copied into all new repositories. Read more in the <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">webhooks guide</a>.
2158+
defaulthooks.add_webhook = Add Default Webhook
2159+
defaulthooks.update_webhook = Update Default Webhook
21582160

2159-
systemhooks.desc = Webhooks automatically make HTTP POST requests to a server when certain Gitea events trigger. Webhooks defined will act on all repositories on the system, so please consider any performance implications this may have. Read more in the <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">webhooks guide</a>.
2161+
systemhooks = System Webhooks
2162+
systemhooks.desc = Webhooks automatically make HTTP POST requests to a server when certain Gitea events trigger. Webhooks defined here will act on all repositories on the system, so please consider any performance implications this may have. Read more in the <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">webhooks guide</a>.
21602163
systemhooks.add_webhook = Add System Webhook
21612164
systemhooks.update_webhook = Update System Webhook
21622165

options/locale/locale_es-ES.ini

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,8 +1986,6 @@ dashboard=Panel de control
19861986
users=Cuenta de Usuario
19871987
organizations=Organizaciones
19881988
repositories=Repositorios
1989-
hooks=Webhooks por defecto
1990-
systemhooks=Webhooks del sistema
19911989
authentication=Orígenes de autenticación
19921990
emails=Correos de usuario
19931991
config=Configuración
@@ -2136,11 +2134,8 @@ repos.forks=Forks
21362134
repos.issues=Incidencias
21372135
repos.size=Tamaño
21382136

2139-
hooks.desc=Los Webhooks automáticamente hacen peticiones HTTP POST a un servidor cuando ciertos eventos de Gitea se activan. Los ganchos definidos aquí son predeterminados y serán copiados en todos los nuevos repositorios. Leer más en la guía <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">webhooks</a>.
2140-
hooks.add_webhook=Añadir Webhook por defecto
2141-
hooks.update_webhook=Actualizar Webhook por defecto
21422137

2143-
systemhooks.desc=Los webhooks automáticamente hacen peticiones HTTP POST a un servidor cuando ciertos eventos de Gitea se activan. Los webhooks definidos actuarán en todos los repositorios del sistema, así que por favor considere las implicaciones de rendimiento que esto pueda tener. Lea más en la guía de <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">webhooks</a>.
2138+
systemhooks=Webhooks del sistema
21442139
systemhooks.add_webhook=Añadir Webhook del Sistema
21452140
systemhooks.update_webhook=Actualizar Webhook del Sistema
21462141

options/locale/locale_fa-IR.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,6 @@ dashboard=پیشخوان
17791779
users=حساب کاربران
17801780
organizations=تشکیلات
17811781
repositories=مخازن
1782-
hooks=افزودن هوک‌های تحت وب پیش فرض
17831782
authentication=منابع احراز هویت
17841783
config=پیکربندی
17851784
notices=هشدارهای سامانه
@@ -1883,9 +1882,6 @@ repos.forks=انشعاب‌ها
18831882
repos.issues=مسائل
18841883
repos.size=اندازه
18851884

1886-
hooks.desc=هوک تحت وب به صورت خودکار درخواست POST HTTP را به سمت سرور روانه می‌کند زمانی که ماشه رخداد Gitea کشیده شود. هوک تحت وب اینجا به صورت پیش فرض اینجا تعریف شده و برای تمامی مخزن جدید کپی خواهد شد. برای اطلاعات بیشتر به e <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/"> راهنمای هوک تحت وب </a> مراجعه کنید.
1887-
hooks.add_webhook=افزودن هوک تحت وب پیش فرض
1888-
hooks.update_webhook=به روز رسانی هوک تحت وب پیش فرض
18891885

18901886

18911887
auths.auth_manage_panel=مدیریت منابع احراز هویت

options/locale/locale_fr-FR.ini

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,8 +1794,6 @@ dashboard=Tableau de bord
17941794
users=Comptes utilisateurs
17951795
organizations=Organisations
17961796
repositories=Dépôts
1797-
hooks=Webhooks par défaut
1798-
systemhooks=Rappels système
17991797
authentication=Sources d'authentification
18001798
emails=Courriels de l'utilisateur
18011799
config=Configuration
@@ -1917,11 +1915,8 @@ repos.forks=Bifurcations
19171915
repos.issues=Tickets
19181916
repos.size=Taille
19191917

1920-
hooks.desc=Les Webhooks font automatiquement une requête HTTP POST à un serveur quand certains événements Gitea sont déclenchés. Les Webhooks définis ici sont ceux par défaut et seront copiés dans tous les nouveaux dépôts. Lire la suite dans le <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">guide sur les Webhooks</a>.
1921-
hooks.add_webhook=Ajouter un Webhook par défaut
1922-
hooks.update_webhook=Modifier un Webhook par défaut
19231918

1924-
systemhooks.desc=Les Webhooks font automatiquement une requête HTTP POST à un serveur quand certains événements Gitea sont déclenchés. Les Webhooks définis ici sont ceux par défaut et seront copiés dans tous les nouveaux dépôts. pour plus d'information voir le <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">guide sur les Webhooks</a>.
1919+
systemhooks=Rappels système
19251920
systemhooks.add_webhook=Ajouter un rappel système
19261921
systemhooks.update_webhook=Mettre à jour un rappel système
19271922

0 commit comments

Comments
 (0)