Skip to content

Commit f618ce0

Browse files
authored
Merge branch 'main' into viewed-files
2 parents e0f9dd6 + cab3a8b commit f618ce0

File tree

32 files changed

+413
-95
lines changed

32 files changed

+413
-95
lines changed

.drone.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ steps:
235235
image: docker:git
236236
pull: always
237237
commands:
238+
- git config --global --add safe.directory /drone/src
238239
- git fetch --tags --force
239240
when:
240241
event:
@@ -427,6 +428,7 @@ steps:
427428
image: docker:git
428429
pull: always
429430
commands:
431+
- git config --global --add safe.directory /drone/src
430432
- git fetch --tags --force
431433
when:
432434
event:
@@ -628,6 +630,7 @@ steps:
628630
image: docker:git
629631
pull: always
630632
commands:
633+
- git config --global --add safe.directory /drone/src
631634
- git fetch --tags --force
632635

633636
- name: deps-frontend
@@ -746,6 +749,7 @@ steps:
746749
image: docker:git
747750
pull: always
748751
commands:
752+
- git config --global --add safe.directory /drone/src
749753
- git fetch --tags --force
750754

751755
- name: deps-frontend
@@ -891,6 +895,7 @@ steps:
891895
image: docker:git
892896
pull: always
893897
commands:
898+
- git config --global --add safe.directory /drone/src
894899
- git fetch --tags --force
895900

896901
- name: publish
@@ -954,6 +959,7 @@ steps:
954959
image: docker:git
955960
pull: always
956961
commands:
962+
- git config --global --add safe.directory /drone/src
957963
- git fetch --tags --force
958964

959965
- name: publish
@@ -1016,6 +1022,7 @@ steps:
10161022
image: docker:git
10171023
pull: always
10181024
commands:
1025+
- git config --global --add safe.directory /drone/src
10191026
- git fetch --tags --force
10201027

10211028
- name: publish
@@ -1112,6 +1119,7 @@ steps:
11121119
image: docker:git
11131120
pull: always
11141121
commands:
1122+
- git config --global --add safe.directory /drone/src
11151123
- git fetch --tags --force
11161124

11171125
- name: publish
@@ -1175,6 +1183,7 @@ steps:
11751183
image: docker:git
11761184
pull: always
11771185
commands:
1186+
- git config --global --add safe.directory /drone/src
11781187
- git fetch --tags --force
11791188

11801189
- name: publish
@@ -1237,6 +1246,7 @@ steps:
12371246
image: docker:git
12381247
pull: always
12391248
commands:
1249+
- git config --global --add safe.directory /drone/src
12401250
- git fetch --tags --force
12411251

12421252
- name: publish

docs/content/doc/advanced/customizing-gitea.en-us.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,18 @@ copy javascript files from https://gitea.com/davidsvantesson/plantuml-code-highl
132132
`$GITEA_CUSTOM/public` folder. Then add the following to `custom/footer.tmpl`:
133133

134134
```html
135-
{{if .RequireHighlightJS}}
136-
<script src="https://your-server.com/deflate.js"></script>
137-
<script src="https://your-server.com/encode.js"></script>
138-
<script src="https://your-server.com/plantuml_codeblock_parse.js"></script>
139135
<script>
140-
<!-- Replace call with address to your plantuml server-->
141-
parsePlantumlCodeBlocks("http://www.plantuml.com/plantuml");
136+
$(async () => {
137+
if (!$('.language-plantuml').length) return;
138+
await Promise.all([
139+
$.getScript('https://your-server.com/deflate.js'),
140+
$.getScript('https://your-server.com/encode.js'),
141+
$.getScript('https://your-server.com/plantuml_codeblock_parse.js'),
142+
]);
143+
// Replace call with address to your plantuml server
144+
parsePlantumlCodeBlocks("https://www.plantuml.com/plantuml");
145+
});
142146
</script>
143-
{{end}}
144147
```
145148

146149
You can then add blocks like the following to your markdown:

models/action.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,14 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, error) {
340340
}
341341

342342
e := db.GetEngine(ctx)
343-
sess := e.Where(cond)
343+
sess := e.Where(cond).Join("INNER", "repository", "`repository`.id = `action`.repo_id")
344344

345345
opts.SetDefaultValues()
346346
sess = db.SetSessionPagination(sess, &opts)
347347

348348
actions := make([]*Action, 0, opts.PageSize)
349349

350-
if err := sess.Desc("created_unix").Find(&actions); err != nil {
350+
if err := sess.Desc("`action`.created_unix").Find(&actions); err != nil {
351351
return nil, fmt.Errorf("Find: %v", err)
352352
}
353353

@@ -417,7 +417,7 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
417417
}
418418

419419
if !opts.IncludePrivate {
420-
cond = cond.And(builder.Eq{"is_private": false})
420+
cond = cond.And(builder.Eq{"`action`.is_private": false})
421421
}
422422
if !opts.IncludeDeleted {
423423
cond = cond.And(builder.Eq{"is_deleted": false})
@@ -430,8 +430,8 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
430430
} else {
431431
dateHigh := dateLow.Add(86399000000000) // 23h59m59s
432432

433-
cond = cond.And(builder.Gte{"created_unix": dateLow.Unix()})
434-
cond = cond.And(builder.Lte{"created_unix": dateHigh.Unix()})
433+
cond = cond.And(builder.Gte{"`action`.created_unix": dateLow.Unix()})
434+
cond = cond.And(builder.Lte{"`action`.created_unix": dateHigh.Unix()})
435435
}
436436
}
437437

models/action_list.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ func (actions ActionList) loadRepoOwner(e db.Engine, userMap map[int64]*user_mod
8080
}
8181

8282
for _, action := range actions {
83+
if action.Repo == nil {
84+
continue
85+
}
8386
repoOwner, ok := userMap[action.Repo.OwnerID]
8487
if !ok {
8588
repoOwner, err = user_model.GetUserByID(action.Repo.OwnerID)

models/action_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,20 @@ func TestNotifyWatchers(t *testing.T) {
211211
OpType: action.OpType,
212212
})
213213
}
214+
215+
func TestGetFeedsCorrupted(t *testing.T) {
216+
assert.NoError(t, unittest.PrepareTestDatabase())
217+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
218+
unittest.AssertExistsAndLoadBean(t, &Action{
219+
ID: 8,
220+
RepoID: 1700,
221+
})
222+
223+
actions, err := GetFeeds(db.DefaultContext, GetFeedsOptions{
224+
RequestedUser: user,
225+
Actor: user,
226+
IncludePrivate: true,
227+
})
228+
assert.NoError(t, err)
229+
assert.Len(t, actions, 0)
230+
}

models/fixtures/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,11 @@
5656
repo_id: 8 # public
5757
is_private: false
5858
created_unix: 1603011540 # grouped with id:7
59+
60+
- id: 8
61+
user_id: 1
62+
op_type: 12 # close issue
63+
act_user_id: 1
64+
repo_id: 1700 # dangling intentional
65+
is_private: false
66+
created_unix: 1603011541

models/project/issue.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ type ProjectIssue struct { //revive:disable-line:exported
1919

2020
// If 0, then it has not been added to a specific board in the project
2121
ProjectBoardID int64 `xorm:"INDEX"`
22+
23+
// the sorting order on the board
24+
Sorting int64 `xorm:"NOT NULL DEFAULT 0"`
2225
}
2326

2427
func init() {

models/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func CheckRepoUnitUser(repo *repo_model.Repository, user *user_model.User, unitT
5454
}
5555

5656
func checkRepoUnitUser(ctx context.Context, repo *repo_model.Repository, user *user_model.User, unitType unit.Type) bool {
57-
if user.IsAdmin {
57+
if user != nil && user.IsAdmin {
5858
return true
5959
}
6060
perm, err := GetUserRepoPermission(ctx, repo, user)

models/unittest/consistency.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ func init() {
175175

176176
checkForActionConsistency := func(t assert.TestingT, bean interface{}) {
177177
action := reflectionWrap(bean)
178-
repoRow := AssertExistsAndLoadMap(t, "repository", builder.Eq{"id": action.int("RepoID")})
179-
assert.Equal(t, parseBool(repoRow["is_private"]), action.bool("IsPrivate"), "action: %+v", action)
178+
if action.int("RepoID") != 1700 { // dangling intentional
179+
repoRow := AssertExistsAndLoadMap(t, "repository", builder.Eq{"id": action.int("RepoID")})
180+
assert.Equal(t, parseBool(repoRow["is_private"]), action.bool("IsPrivate"), "action: %+v", action)
181+
}
180182
}
181183

182184
consistencyCheckMap["user"] = checkForUserConsistency

modules/analyze/vendor.go

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,10 @@
55
package analyze
66

77
import (
8-
"regexp"
9-
"sort"
10-
"strings"
11-
12-
"github.com/go-enry/go-enry/v2/data"
8+
"github.com/go-enry/go-enry/v2"
139
)
1410

15-
var isVendorRegExp *regexp.Regexp
16-
17-
func init() {
18-
matchers := data.VendorMatchers
19-
20-
caretStrings := make([]string, 0, 10)
21-
caretShareStrings := make([]string, 0, 10)
22-
23-
matcherStrings := make([]string, 0, len(matchers))
24-
for _, matcher := range matchers {
25-
str := matcher.String()
26-
if str[0] == '^' {
27-
caretStrings = append(caretStrings, str[1:])
28-
} else if str[0:5] == "(^|/)" {
29-
caretShareStrings = append(caretShareStrings, str[5:])
30-
} else {
31-
matcherStrings = append(matcherStrings, str)
32-
}
33-
}
34-
35-
sort.Strings(caretShareStrings)
36-
sort.Strings(caretStrings)
37-
sort.Strings(matcherStrings)
38-
39-
sb := &strings.Builder{}
40-
sb.WriteString("(?:^(?:")
41-
sb.WriteString(caretStrings[0])
42-
for _, matcher := range caretStrings[1:] {
43-
sb.WriteString(")|(?:")
44-
sb.WriteString(matcher)
45-
}
46-
sb.WriteString("))")
47-
sb.WriteString("|")
48-
sb.WriteString("(?:(?:^|/)(?:")
49-
sb.WriteString(caretShareStrings[0])
50-
for _, matcher := range caretShareStrings[1:] {
51-
sb.WriteString(")|(?:")
52-
sb.WriteString(matcher)
53-
}
54-
sb.WriteString("))")
55-
sb.WriteString("|")
56-
sb.WriteString("(?:")
57-
sb.WriteString(matcherStrings[0])
58-
for _, matcher := range matcherStrings[1:] {
59-
sb.WriteString(")|(?:")
60-
sb.WriteString(matcher)
61-
}
62-
sb.WriteString(")")
63-
combined := sb.String()
64-
isVendorRegExp = regexp.MustCompile(combined)
65-
}
66-
6711
// IsVendor returns whether or not path is a vendor path.
6812
func IsVendor(path string) bool {
69-
return isVendorRegExp.MatchString(path)
13+
return enry.IsVendor(path)
7014
}

modules/context/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ func APIContexter() func(http.Handler) http.Handler {
256256
},
257257
Org: &APIOrganization{},
258258
}
259+
defer ctx.Close()
259260

260261
ctx.Req = WithAPIContext(WithContext(req, ctx.Context), &ctx)
261262

modules/context/context.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ type Context struct {
7575
Package *Package
7676
}
7777

78+
// Close frees all resources hold by Context
79+
func (ctx *Context) Close() error {
80+
var err error
81+
if ctx.Req != nil && ctx.Req.MultipartForm != nil {
82+
err = ctx.Req.MultipartForm.RemoveAll() // remove the temp files buffered to tmp directory
83+
}
84+
// TODO: close opened repo, and more
85+
return err
86+
}
87+
7888
// TrHTMLEscapeArgs runs Tr but pre-escapes all arguments with html.EscapeString.
7989
// This is useful if the locale message is intended to only produce HTML content.
8090
func (ctx *Context) TrHTMLEscapeArgs(msg string, args ...string) string {
@@ -693,6 +703,8 @@ func Contexter() func(next http.Handler) http.Handler {
693703
"RunModeIsProd": setting.IsProd,
694704
},
695705
}
706+
defer ctx.Close()
707+
696708
// PageData is passed by reference, and it will be rendered to `window.config.pageData` in `head.tmpl` for JavaScript modules
697709
ctx.PageData = map[string]interface{}{}
698710
ctx.Data["PageData"] = ctx.PageData

modules/context/package.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func PackageContexter() func(next http.Handler) http.Handler {
100100
Resp: NewResponse(resp),
101101
Data: map[string]interface{}{},
102102
}
103+
defer ctx.Close()
103104

104105
ctx.Req = WithContext(req, &ctx)
105106

modules/context/private.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ func PrivateContexter() func(http.Handler) http.Handler {
6666
Data: map[string]interface{}{},
6767
},
6868
}
69+
defer ctx.Close()
70+
6971
ctx.Req = WithPrivateContext(req, ctx)
7072
ctx.Data["Context"] = ctx
7173
next.ServeHTTP(ctx.Resp, ctx.Req)

modules/test/context_tests.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func MockContext(t *testing.T, path string) *context.Context {
3838
Resp: context.NewResponse(resp),
3939
Locale: &mockLocale{},
4040
}
41+
defer ctx.Close()
4142

4243
requestURL, err := url.Parse(path)
4344
assert.NoError(t, err)

0 commit comments

Comments
 (0)