Skip to content

Commit a869d7b

Browse files
committed
Merge branch 'main' of https://github.com/go-gitea/gitea into oauth-client-type
2 parents 5e9529d + b59b0ca commit a869d7b

File tree

24 files changed

+351
-168
lines changed

24 files changed

+351
-168
lines changed

.drone.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ steps:
100100
- name: checks-backend
101101
image: golang:1.19
102102
commands:
103-
- make checks-backend
103+
- make --always-make checks-backend # ensure the 'go-licenses' make target runs
104104
depends_on: [deps-backend]
105105
volumes:
106106
- name: deps
@@ -112,16 +112,11 @@ steps:
112112
- make test-frontend
113113
depends_on: [lint-frontend]
114114

115-
- name: generate-frontend
116-
image: golang:1.19
117-
commands:
118-
- make generate-frontend
119-
120115
- name: build-frontend
121116
image: node:18
122117
commands:
123118
- make frontend
124-
depends_on: [deps-frontend, generate-frontend]
119+
depends_on: [deps-frontend]
125120

126121
- name: build-backend-no-gcc
127122
image: golang:1.18 # this step is kept as the lowest version of golang that we support
@@ -549,16 +544,11 @@ steps:
549544
commands:
550545
- make deps-frontend
551546

552-
- name: generate-frontend
553-
image: golang:1.18
554-
commands:
555-
- make generate-frontend
556-
557547
- name: build-frontend
558548
image: node:18
559549
commands:
560550
- make frontend
561-
depends_on: [deps-frontend, generate-frontend]
551+
depends_on: [deps-frontend]
562552

563553
- name: deps-backend
564554
image: golang:1.18

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
* text=auto eol=lf
22
*.tmpl linguist-language=Handlebars
3+
/assets/*.json linguist-generated
34
/public/vendor/** -text -eol linguist-vendored
45
/vendor/** -text -eol linguist-vendored
56
/web_src/fomantic/build/** linguist-generated

Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,15 @@ unit-test-coverage:
406406
tidy:
407407
$(eval MIN_GO_VERSION := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
408408
$(GO) mod tidy -compat=$(MIN_GO_VERSION)
409+
@$(MAKE) --no-print-directory $(GO_LICENSE_FILE)
409410

410411
vendor: go.mod go.sum
411412
$(GO) mod vendor
412413
@touch vendor
413414

414415
.PHONY: tidy-check
415416
tidy-check: tidy
416-
@diff=$$(git diff go.mod go.sum); \
417+
@diff=$$(git diff go.mod go.sum $(GO_LICENSE_FILE)); \
417418
if [ -n "$$diff" ]; then \
418419
echo "Please run 'make tidy' and commit the result:"; \
419420
echo "$${diff}"; \
@@ -709,17 +710,14 @@ install: $(wildcard *.go)
709710
build: frontend backend
710711

711712
.PHONY: frontend
712-
frontend: generate-frontend $(WEBPACK_DEST)
713+
frontend: $(WEBPACK_DEST)
713714

714715
.PHONY: backend
715716
backend: go-check generate-backend $(EXECUTABLE)
716717

717718
# We generate the backend before the frontend in case we in future we want to generate things in the frontend from generated files in backend
718719
.PHONY: generate
719-
generate: generate-backend generate-frontend
720-
721-
.PHONY: generate-frontend
722-
generate-frontend: $(GO_LICENSE_FILE)
720+
generate: generate-backend
723721

724722
.PHONY: generate-backend
725723
generate-backend: $(TAGS_PREREQ) generate-go

models/repo/repo_list.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,16 @@ func searchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, c
593593
return sess, count, nil
594594
}
595595

596+
// SearchRepositoryIDsByCondition search repository IDs by given condition.
597+
func SearchRepositoryIDsByCondition(ctx context.Context, cond builder.Cond) ([]int64, error) {
598+
repoIDs := make([]int64, 0, 10)
599+
return repoIDs, db.GetEngine(ctx).
600+
Table("repository").
601+
Cols("id").
602+
Where(cond).
603+
Find(&repoIDs)
604+
}
605+
596606
// AccessibleRepositoryCondition takes a user a returns a condition for checking if a repository is accessible
597607
func AccessibleRepositoryCondition(user *user_model.User, unitType unit.Type) builder.Cond {
598608
cond := builder.NewCond()
@@ -680,16 +690,16 @@ func AccessibleRepoIDsQuery(user *user_model.User) *builder.Builder {
680690
}
681691

682692
// FindUserCodeAccessibleRepoIDs finds all at Code level accessible repositories' ID by the user's id
683-
func FindUserCodeAccessibleRepoIDs(user *user_model.User) ([]int64, error) {
684-
repoIDs := make([]int64, 0, 10)
685-
if err := db.GetEngine(db.DefaultContext).
686-
Table("repository").
687-
Cols("id").
688-
Where(AccessibleRepositoryCondition(user, unit.TypeCode)).
689-
Find(&repoIDs); err != nil {
690-
return nil, fmt.Errorf("FindUserCodeAccesibleRepoIDs: %v", err)
691-
}
692-
return repoIDs, nil
693+
func FindUserCodeAccessibleRepoIDs(ctx context.Context, user *user_model.User) ([]int64, error) {
694+
return SearchRepositoryIDsByCondition(ctx, AccessibleRepositoryCondition(user, unit.TypeCode))
695+
}
696+
697+
// FindUserCodeAccessibleOwnerRepoIDs finds all repository IDs for the given owner whose code the user can see.
698+
func FindUserCodeAccessibleOwnerRepoIDs(ctx context.Context, ownerID int64, user *user_model.User) ([]int64, error) {
699+
return SearchRepositoryIDsByCondition(ctx, builder.NewCond().And(
700+
builder.Eq{"owner_id": ownerID},
701+
AccessibleRepositoryCondition(user, unit.TypeCode),
702+
))
693703
}
694704

695705
// GetUserRepositories returns a list of repositories of given user.

modules/context/org.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
130130
ctx.Data["IsOrganizationOwner"] = ctx.Org.IsOwner
131131
ctx.Data["IsOrganizationMember"] = ctx.Org.IsMember
132132
ctx.Data["IsPackageEnabled"] = setting.Packages.Enabled
133+
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
133134
ctx.Data["IsPublicMember"] = func(uid int64) bool {
134135
is, _ := organization.IsPublicMembership(ctx.Org.Organization.ID, uid)
135136
return is

modules/git/repo_attribute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ func (c *CheckAttributeReader) Run() error {
191191
// CheckPath check attr for given path
192192
func (c *CheckAttributeReader) CheckPath(path string) (rs map[string]string, err error) {
193193
defer func() {
194-
if err != nil {
195-
log.Error("CheckPath returns error: %v", err)
194+
if err != nil && err != c.ctx.Err() {
195+
log.Error("Unexpected error when checking path %s in %s. Error: %v", path, c.Repo.Path, err)
196196
}
197197
}()
198198

options/locale/locale_en-US.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,11 @@ users = Users
268268
organizations = Organizations
269269
search = Search
270270
code = Code
271+
search.type.tooltip = Search type
271272
search.fuzzy = Fuzzy
273+
search.fuzzy.tooltip = Include results that also matches the search term closely
272274
search.match = Match
275+
search.match.tooltip = Include only results that matches the exact search term
273276
code_search_unavailable = Currently code search is not available. Please contact your site administrator.
274277
repo_no_results = No matching repositories found.
275278
user_no_results = No matching users found.
@@ -507,6 +510,7 @@ activity = Public Activity
507510
followers = Followers
508511
starred = Starred Repositories
509512
watched = Watched Repositories
513+
code = Code
510514
projects = Projects
511515
following = Following
512516
follow = Follow
@@ -1761,8 +1765,11 @@ activity.git_stats_deletion_n = %d deletions
17611765

17621766
search = Search
17631767
search.search_repo = Search repository
1768+
search.type.tooltip = Search type
17641769
search.fuzzy = Fuzzy
1770+
search.fuzzy.tooltip = Include results that also matches the search term closely
17651771
search.match = Match
1772+
search.match.tooltip = Include only results that matches the exact search term
17661773
search.results = Search results for "%s" in <a href="%s">%s</a>
17671774
search.code_no_results = No source code matching your search term found.
17681775
search.code_search_unavailable = Currently code search is not available. Please contact your site administrator.
@@ -2308,6 +2315,7 @@ create_org = Create Organization
23082315
repo_updated = Updated
23092316
people = People
23102317
teams = Teams
2318+
code = Code
23112319
lower_members = members
23122320
lower_repositories = repositories
23132321
create_new_team = New Team

routers/web/explore/code.go

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -34,86 +34,91 @@ func Code(ctx *context.Context) {
3434

3535
language := ctx.FormTrim("l")
3636
keyword := ctx.FormTrim("q")
37+
38+
queryType := ctx.FormTrim("t")
39+
isMatch := queryType == "match"
40+
41+
ctx.Data["Keyword"] = keyword
42+
ctx.Data["Language"] = language
43+
ctx.Data["queryType"] = queryType
44+
ctx.Data["PageIsViewCode"] = true
45+
46+
if keyword == "" {
47+
ctx.HTML(http.StatusOK, tplExploreCode)
48+
return
49+
}
50+
3751
page := ctx.FormInt("page")
3852
if page <= 0 {
3953
page = 1
4054
}
4155

42-
queryType := ctx.FormTrim("t")
43-
isMatch := queryType == "match"
56+
var (
57+
repoIDs []int64
58+
err error
59+
isAdmin bool
60+
)
61+
if ctx.Doer != nil {
62+
isAdmin = ctx.Doer.IsAdmin
63+
}
4464

45-
if keyword != "" {
46-
var (
47-
repoIDs []int64
48-
err error
49-
isAdmin bool
50-
)
51-
if ctx.Doer != nil {
52-
isAdmin = ctx.Doer.IsAdmin
65+
// guest user or non-admin user
66+
if ctx.Doer == nil || !isAdmin {
67+
repoIDs, err = repo_model.FindUserCodeAccessibleRepoIDs(ctx, ctx.Doer)
68+
if err != nil {
69+
ctx.ServerError("FindUserCodeAccessibleRepoIDs", err)
70+
return
5371
}
72+
}
5473

55-
// guest user or non-admin user
56-
if ctx.Doer == nil || !isAdmin {
57-
repoIDs, err = repo_model.FindUserCodeAccessibleRepoIDs(ctx.Doer)
58-
if err != nil {
74+
var (
75+
total int
76+
searchResults []*code_indexer.Result
77+
searchResultLanguages []*code_indexer.SearchResultLanguages
78+
)
79+
80+
if (len(repoIDs) > 0) || isAdmin {
81+
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, repoIDs, language, keyword, page, setting.UI.RepoSearchPagingNum, isMatch)
82+
if err != nil {
83+
if code_indexer.IsAvailable() {
5984
ctx.ServerError("SearchResults", err)
6085
return
6186
}
87+
ctx.Data["CodeIndexerUnavailable"] = true
88+
} else {
89+
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable()
6290
}
6391

64-
var (
65-
total int
66-
searchResults []*code_indexer.Result
67-
searchResultLanguages []*code_indexer.SearchResultLanguages
68-
)
69-
70-
if (len(repoIDs) > 0) || isAdmin {
71-
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, repoIDs, language, keyword, page, setting.UI.RepoSearchPagingNum, isMatch)
72-
if err != nil {
73-
if code_indexer.IsAvailable() {
74-
ctx.ServerError("SearchResults", err)
75-
return
92+
loadRepoIDs := make([]int64, 0, len(searchResults))
93+
for _, result := range searchResults {
94+
var find bool
95+
for _, id := range loadRepoIDs {
96+
if id == result.RepoID {
97+
find = true
98+
break
7699
}
77-
ctx.Data["CodeIndexerUnavailable"] = true
78-
} else {
79-
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable()
80100
}
81-
82-
loadRepoIDs := make([]int64, 0, len(searchResults))
83-
for _, result := range searchResults {
84-
var find bool
85-
for _, id := range loadRepoIDs {
86-
if id == result.RepoID {
87-
find = true
88-
break
89-
}
90-
}
91-
if !find {
92-
loadRepoIDs = append(loadRepoIDs, result.RepoID)
93-
}
94-
}
95-
96-
repoMaps, err := repo_model.GetRepositoriesMapByIDs(loadRepoIDs)
97-
if err != nil {
98-
ctx.ServerError("SearchResults", err)
99-
return
101+
if !find {
102+
loadRepoIDs = append(loadRepoIDs, result.RepoID)
100103
}
104+
}
101105

102-
ctx.Data["RepoMaps"] = repoMaps
106+
repoMaps, err := repo_model.GetRepositoriesMapByIDs(loadRepoIDs)
107+
if err != nil {
108+
ctx.ServerError("GetRepositoriesMapByIDs", err)
109+
return
103110
}
104111

105-
ctx.Data["Keyword"] = keyword
106-
ctx.Data["Language"] = language
107-
ctx.Data["queryType"] = queryType
108-
ctx.Data["SearchResults"] = searchResults
109-
ctx.Data["SearchResultLanguages"] = searchResultLanguages
110-
ctx.Data["PageIsViewCode"] = true
111-
112-
pager := context.NewPagination(total, setting.UI.RepoSearchPagingNum, page, 5)
113-
pager.SetDefaultParams(ctx)
114-
pager.AddParam(ctx, "l", "Language")
115-
ctx.Data["Page"] = pager
112+
ctx.Data["RepoMaps"] = repoMaps
116113
}
117114

115+
ctx.Data["SearchResults"] = searchResults
116+
ctx.Data["SearchResultLanguages"] = searchResultLanguages
117+
118+
pager := context.NewPagination(total, setting.UI.RepoSearchPagingNum, page, 5)
119+
pager.SetDefaultParams(ctx)
120+
pager.AddParam(ctx, "l", "Language")
121+
ctx.Data["Page"] = pager
122+
118123
ctx.HTML(http.StatusOK, tplExploreCode)
119124
}

routers/web/repo/search.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,27 @@ func Search(ctx *context.Context) {
2121
ctx.Redirect(ctx.Repo.RepoLink)
2222
return
2323
}
24+
2425
language := ctx.FormTrim("l")
2526
keyword := ctx.FormTrim("q")
27+
28+
queryType := ctx.FormTrim("t")
29+
isMatch := queryType == "match"
30+
31+
ctx.Data["Keyword"] = keyword
32+
ctx.Data["Language"] = language
33+
ctx.Data["queryType"] = queryType
34+
ctx.Data["PageIsViewCode"] = true
35+
36+
if keyword == "" {
37+
ctx.HTML(http.StatusOK, tplSearch)
38+
return
39+
}
40+
2641
page := ctx.FormInt("page")
2742
if page <= 0 {
2843
page = 1
2944
}
30-
queryType := ctx.FormTrim("t")
31-
isMatch := queryType == "match"
3245

3346
total, searchResults, searchResultLanguages, err := code_indexer.PerformSearch(ctx, []int64{ctx.Repo.Repository.ID},
3447
language, keyword, page, setting.UI.RepoSearchPagingNum, isMatch)
@@ -41,13 +54,10 @@ func Search(ctx *context.Context) {
4154
} else {
4255
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable()
4356
}
44-
ctx.Data["Keyword"] = keyword
45-
ctx.Data["Language"] = language
46-
ctx.Data["queryType"] = queryType
57+
4758
ctx.Data["SourcePath"] = ctx.Repo.Repository.HTMLURL()
4859
ctx.Data["SearchResults"] = searchResults
4960
ctx.Data["SearchResultLanguages"] = searchResultLanguages
50-
ctx.Data["PageIsViewCode"] = true
5161

5262
pager := context.NewPagination(total, setting.UI.RepoSearchPagingNum, page, 5)
5363
pager.SetDefaultParams(ctx)

0 commit comments

Comments
 (0)