Skip to content

Commit c756727

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Simplify `IsVendor` (go-gitea#19626) Prevent NPE when checking repo units if the user is nil (go-gitea#19625) Skip duplicated layers. (go-gitea#19624) Add "Reference" section to Issue view sidebar (go-gitea#19609) GetFeeds must always discard actions with dangling repo_id (go-gitea#19598)
2 parents eef822a + 3ece9d5 commit c756727

File tree

10 files changed

+54
-66
lines changed

10 files changed

+54
-66
lines changed

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/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
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,7 @@ issues.content_history.created = created
14801480
issues.content_history.delete_from_history = Delete from history
14811481
issues.content_history.delete_from_history_confirm = Delete from history?
14821482
issues.content_history.options = Options
1483+
issues.reference_link = Reference: %s
14831484

14841485
compare.compare_base = base
14851486
compare.compare_head = compare

routers/api/packages/container/manifest.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ func createFileFromBlobReference(ctx context.Context, pv, uploadVersion *package
355355
}
356356
var err error
357357
if pf, err = packages_model.TryInsertFile(ctx, pf); err != nil {
358+
if err == packages_model.ErrDuplicatePackageFile {
359+
// Skip this blob because the manifest contains the same filesystem layer multiple times.
360+
return nil
361+
}
358362
log.Error("Error inserting package file: %v", err)
359363
return err
360364
}

templates/repo/issue/view_content/sidebar.tmpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,15 @@
568568
{{end}}
569569
{{end}}
570570

571+
<div class="ui divider"></div>
572+
<div class="ui equal width compact grid">
573+
<div class="row ac">
574+
{{$issueReferenceLink := printf "%s#%d" .Issue.Repo.FullName .Issue.Index}}
575+
<span class="text column truncate">{{.i18n.Tr "repo.issues.reference_link" $issueReferenceLink}}</span>
576+
<button class="ui two wide button column p-3" data-clipboard-text="{{$issueReferenceLink}}">{{svg "octicon-copy" 14}}</button>
577+
</div>
578+
</div>
579+
571580
{{if and .IsRepoAdmin (not .Repository.IsArchived)}}
572581
<div class="ui divider"></div>
573582
<div class="ui watching">

0 commit comments

Comments
 (0)