Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
zjjhot committed May 6, 2022
2 parents eef822a + 3ece9d5 commit c756727
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 66 deletions.
10 changes: 5 additions & 5 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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})
Expand All @@ -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()})
}
}

Expand Down
3 changes: 3 additions & 0 deletions models/action_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions models/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 8 additions & 0 deletions models/fixtures/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions models/unittest/consistency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 2 additions & 58 deletions modules/analyze/vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions routers/api/packages/container/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions templates/repo/issue/view_content/sidebar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,15 @@
{{end}}
{{end}}

<div class="ui divider"></div>
<div class="ui equal width compact grid">
<div class="row ac">
{{$issueReferenceLink := printf "%s#%d" .Issue.Repo.FullName .Issue.Index}}
<span class="text column truncate">{{.i18n.Tr "repo.issues.reference_link" $issueReferenceLink}}</span>
<button class="ui two wide button column p-3" data-clipboard-text="{{$issueReferenceLink}}">{{svg "octicon-copy" 14}}</button>
</div>
</div>

{{if and .IsRepoAdmin (not .Repository.IsArchived)}}
<div class="ui divider"></div>
<div class="ui watching">
Expand Down

0 comments on commit c756727

Please sign in to comment.