diff --git a/models/action.go b/models/action.go index 5177616497514..efbe243bed3b9 100644 --- a/models/action.go +++ b/models/action.go @@ -340,14 +340,14 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, error) { } e := db.GetEngine(ctx) - sess := e.Where(cond) + sess := e.Where(cond).Join("INNER", "repository", "`repository`.id = `action`.repo_id") opts.SetDefaultValues() sess = db.SetSessionPagination(sess, &opts) actions := make([]*Action, 0, opts.PageSize) - if err := sess.Desc("created_unix").Find(&actions); err != nil { + if err := sess.Desc("`action`.created_unix").Find(&actions); err != nil { return nil, fmt.Errorf("Find: %v", err) } @@ -417,7 +417,7 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) { } if !opts.IncludePrivate { - cond = cond.And(builder.Eq{"is_private": false}) + cond = cond.And(builder.Eq{"`action`.is_private": false}) } if !opts.IncludeDeleted { cond = cond.And(builder.Eq{"is_deleted": false}) @@ -430,8 +430,8 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) { } else { dateHigh := dateLow.Add(86399000000000) // 23h59m59s - cond = cond.And(builder.Gte{"created_unix": dateLow.Unix()}) - cond = cond.And(builder.Lte{"created_unix": dateHigh.Unix()}) + cond = cond.And(builder.Gte{"`action`.created_unix": dateLow.Unix()}) + cond = cond.And(builder.Lte{"`action`.created_unix": dateHigh.Unix()}) } } diff --git a/models/action_list.go b/models/action_list.go index c180a82552c51..5f7b17b9de1ef 100644 --- a/models/action_list.go +++ b/models/action_list.go @@ -80,6 +80,9 @@ func (actions ActionList) loadRepoOwner(e db.Engine, userMap map[int64]*user_mod } for _, action := range actions { + if action.Repo == nil { + continue + } repoOwner, ok := userMap[action.Repo.OwnerID] if !ok { repoOwner, err = user_model.GetUserByID(action.Repo.OwnerID) diff --git a/models/action_test.go b/models/action_test.go index e247a5ec29c80..fb8a6c2686f12 100644 --- a/models/action_test.go +++ b/models/action_test.go @@ -211,3 +211,20 @@ func TestNotifyWatchers(t *testing.T) { OpType: action.OpType, }) } + +func TestGetFeedsCorrupted(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User) + unittest.AssertExistsAndLoadBean(t, &Action{ + ID: 8, + RepoID: 1700, + }) + + actions, err := GetFeeds(db.DefaultContext, GetFeedsOptions{ + RequestedUser: user, + Actor: user, + IncludePrivate: true, + }) + assert.NoError(t, err) + assert.Len(t, actions, 0) +} diff --git a/models/fixtures/action.yml b/models/fixtures/action.yml index e283b01db29fc..a75092feb0ecc 100644 --- a/models/fixtures/action.yml +++ b/models/fixtures/action.yml @@ -56,3 +56,11 @@ repo_id: 8 # public is_private: false created_unix: 1603011540 # grouped with id:7 + +- id: 8 + user_id: 1 + op_type: 12 # close issue + act_user_id: 1 + repo_id: 1700 # dangling intentional + is_private: false + created_unix: 1603011541 diff --git a/models/repo.go b/models/repo.go index e934b24fb3856..fbc766850d954 100644 --- a/models/repo.go +++ b/models/repo.go @@ -54,7 +54,7 @@ func CheckRepoUnitUser(repo *repo_model.Repository, user *user_model.User, unitT } func checkRepoUnitUser(ctx context.Context, repo *repo_model.Repository, user *user_model.User, unitType unit.Type) bool { - if user.IsAdmin { + if user != nil && user.IsAdmin { return true } perm, err := GetUserRepoPermission(ctx, repo, user) diff --git a/models/unittest/consistency.go b/models/unittest/consistency.go index 2645084d3ede3..af05348868339 100644 --- a/models/unittest/consistency.go +++ b/models/unittest/consistency.go @@ -175,8 +175,10 @@ func init() { checkForActionConsistency := func(t assert.TestingT, bean interface{}) { action := reflectionWrap(bean) - repoRow := AssertExistsAndLoadMap(t, "repository", builder.Eq{"id": action.int("RepoID")}) - assert.Equal(t, parseBool(repoRow["is_private"]), action.bool("IsPrivate"), "action: %+v", action) + if action.int("RepoID") != 1700 { // dangling intentional + repoRow := AssertExistsAndLoadMap(t, "repository", builder.Eq{"id": action.int("RepoID")}) + assert.Equal(t, parseBool(repoRow["is_private"]), action.bool("IsPrivate"), "action: %+v", action) + } } consistencyCheckMap["user"] = checkForUserConsistency diff --git a/modules/analyze/vendor.go b/modules/analyze/vendor.go index 12ae8dbd8075c..976a6ddc7bf21 100644 --- a/modules/analyze/vendor.go +++ b/modules/analyze/vendor.go @@ -5,66 +5,10 @@ package analyze import ( - "regexp" - "sort" - "strings" - - "github.com/go-enry/go-enry/v2/data" + "github.com/go-enry/go-enry/v2" ) -var isVendorRegExp *regexp.Regexp - -func init() { - matchers := data.VendorMatchers - - caretStrings := make([]string, 0, 10) - caretShareStrings := make([]string, 0, 10) - - matcherStrings := make([]string, 0, len(matchers)) - for _, matcher := range matchers { - str := matcher.String() - if str[0] == '^' { - caretStrings = append(caretStrings, str[1:]) - } else if str[0:5] == "(^|/)" { - caretShareStrings = append(caretShareStrings, str[5:]) - } else { - matcherStrings = append(matcherStrings, str) - } - } - - sort.Strings(caretShareStrings) - sort.Strings(caretStrings) - sort.Strings(matcherStrings) - - sb := &strings.Builder{} - sb.WriteString("(?:^(?:") - sb.WriteString(caretStrings[0]) - for _, matcher := range caretStrings[1:] { - sb.WriteString(")|(?:") - sb.WriteString(matcher) - } - sb.WriteString("))") - sb.WriteString("|") - sb.WriteString("(?:(?:^|/)(?:") - sb.WriteString(caretShareStrings[0]) - for _, matcher := range caretShareStrings[1:] { - sb.WriteString(")|(?:") - sb.WriteString(matcher) - } - sb.WriteString("))") - sb.WriteString("|") - sb.WriteString("(?:") - sb.WriteString(matcherStrings[0]) - for _, matcher := range matcherStrings[1:] { - sb.WriteString(")|(?:") - sb.WriteString(matcher) - } - sb.WriteString(")") - combined := sb.String() - isVendorRegExp = regexp.MustCompile(combined) -} - // IsVendor returns whether or not path is a vendor path. func IsVendor(path string) bool { - return isVendorRegExp.MatchString(path) + return enry.IsVendor(path) } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 0175c8bfc8b00..c040386ca70c4 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1480,6 +1480,7 @@ issues.content_history.created = created issues.content_history.delete_from_history = Delete from history issues.content_history.delete_from_history_confirm = Delete from history? issues.content_history.options = Options +issues.reference_link = Reference: %s compare.compare_base = base compare.compare_head = compare diff --git a/routers/api/packages/container/manifest.go b/routers/api/packages/container/manifest.go index b327538e6f2c2..d899ac8ee2f6a 100644 --- a/routers/api/packages/container/manifest.go +++ b/routers/api/packages/container/manifest.go @@ -355,6 +355,10 @@ func createFileFromBlobReference(ctx context.Context, pv, uploadVersion *package } var err error if pf, err = packages_model.TryInsertFile(ctx, pf); err != nil { + if err == packages_model.ErrDuplicatePackageFile { + // Skip this blob because the manifest contains the same filesystem layer multiple times. + return nil + } log.Error("Error inserting package file: %v", err) return err } diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index d03264a50c7a7..cb8e3f01ae607 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -568,6 +568,15 @@ {{end}} {{end}} +
+