Skip to content

Commit c410478

Browse files
committed
Merge branch 'master' into stopwatch-notif
2 parents a1bfb1d + e6155ff commit c410478

Some content is hidden

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

57 files changed

+444
-345
lines changed

cmd/serv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func setup(logPath string, debug bool) {
5858
}
5959
setting.NewContext()
6060
if debug {
61-
setting.ProdMode = false
61+
setting.RunMode = "dev"
6262
}
6363
}
6464

@@ -76,7 +76,7 @@ func fail(userMessage, logMessage string, args ...interface{}) {
7676
fmt.Fprintln(os.Stderr, "Gitea:", userMessage)
7777

7878
if len(logMessage) > 0 {
79-
if !setting.ProdMode {
79+
if !setting.IsProd() {
8080
fmt.Fprintf(os.Stderr, logMessage+"\n", args...)
8181
}
8282
}

custom/conf/app.example.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ MACARON = file
867867
ROUTER_LOG_LEVEL = Info
868868
ROUTER = console
869869
ENABLE_ACCESS_LOG = false
870-
ACCESS_LOG_TEMPLATE = {{.Ctx.RemoteAddr}} - {{.Identity}} {{.Start.Format "[02/Jan/2006:15:04:05 -0700]" }} "{{.Ctx.Req.Method}} {{.Ctx.Req.RequestURI}} {{.Ctx.Req.Proto}}" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} "{{.Ctx.Req.Referer}}\" \"{{.Ctx.Req.UserAgent}}"
870+
ACCESS_LOG_TEMPLATE = {{.Ctx.RemoteAddr}} - {{.Identity}} {{.Start.Format "[02/Jan/2006:15:04:05 -0700]" }} "{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} "{{.Ctx.Req.Referer}}\" \"{{.Ctx.Req.UserAgent}}"
871871
ACCESS = file
872872
; Either "Trace", "Debug", "Info", "Warn", "Error", "Critical", default is "Trace"
873873
LEVEL = Info

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/models.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ func NewTestEngine() (err error) {
175175
}
176176

177177
x.SetMapper(names.GonicMapper{})
178-
x.SetLogger(NewXORMLogger(!setting.ProdMode))
179-
x.ShowSQL(!setting.ProdMode)
178+
x.SetLogger(NewXORMLogger(!setting.IsProd()))
179+
x.ShowSQL(!setting.IsProd())
180180
return x.StoreEngine("InnoDB").Sync2(tables...)
181181
}
182182

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/auth/sso/sspi_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (s *SSPI) Init() error {
5656
Funcs: templates.NewFuncMap(),
5757
Asset: templates.GetAsset,
5858
AssetNames: templates.GetAssetNames,
59-
IsDevelopment: setting.RunMode != "prod",
59+
IsDevelopment: !setting.IsProd(),
6060
})
6161
return nil
6262
}
@@ -95,7 +95,7 @@ func (s *SSPI) VerifyAuthData(req *http.Request, w http.ResponseWriter, store Da
9595
// to login with another authentication method if SSPI authentication
9696
// fails
9797
store.GetData()["Flash"] = map[string]string{
98-
"ErrMsg": err.Error(),
98+
"ErrorMsg": err.Error(),
9999
}
100100
store.GetData()["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
101101
store.GetData()["EnableSSPI"] = true

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/httpcache/httpcache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
// GetCacheControl returns a suitable "Cache-Control" header value
1919
func GetCacheControl() string {
20-
if setting.RunMode == "dev" {
20+
if !setting.IsProd() {
2121
return "no-store"
2222
}
2323
return "private, max-age=" + strconv.FormatInt(int64(setting.StaticCacheTime.Seconds()), 10)

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)

modules/setting/setting.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ var (
376376
CustomConf string
377377
PIDFile = "/run/gitea.pid"
378378
WritePIDFile bool
379-
ProdMode bool
380379
RunMode string
381380
RunUser string
382381
IsWindows bool
@@ -388,6 +387,11 @@ var (
388387
UILocation = time.Local
389388
)
390389

390+
// IsProd if it's a production mode
391+
func IsProd() bool {
392+
return strings.EqualFold(RunMode, "prod")
393+
}
394+
391395
func getAppPath() (string, error) {
392396
var appPath string
393397
var err error

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

0 commit comments

Comments
 (0)