Skip to content

Commit 63c503f

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Add user/organization code search (go-gitea#19977) Stop logging CheckPath returns error: context canceled (go-gitea#21064) Hook go-licenses into tidy again (go-gitea#21353) Fix missing left and right carets in TRANSLATORS (go-gitea#21397) Fix calls to i18n in templates (go-gitea#21394) Update JS dependencies and eslint config (go-gitea#21388) Allow creation of OAuth2 applications for orgs (go-gitea#18084) Fix typos in PullRequestMergeForm.vue header comment (go-gitea#21378) Use weighted algorithm for string matching when finding files in repo (go-gitea#21370) Bump playwright to 1.26.1 (go-gitea#21357) npm package registry support for `bin` (go-gitea#21372) Removed one extra whitespace in footer after "Template" (go-gitea#21364)
2 parents 9b78b24 + b59b0ca commit 63c503f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2370
-1987
lines changed

.drone.yml

+4-14
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
@@ -571,7 +561,7 @@ steps:
571561

572562
# TODO: We should probably build all dependencies into a test image
573563
- name: test-e2e
574-
image: mcr.microsoft.com/playwright:v1.24.0-focal
564+
image: mcr.microsoft.com/playwright:v1.27.0-focal
575565
commands:
576566
- curl -sLO https://go.dev/dl/go1.19.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.19.linux-amd64.tar.gz
577567
- groupadd --gid 1001 gitea && useradd -m --gid 1001 --uid 1001 gitea

.eslintrc.yaml

+6-3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ rules:
185185
linebreak-style: [2, unix]
186186
lines-around-comment: [0]
187187
lines-between-class-members: [0]
188+
logical-assignment-operators: [0]
188189
max-classes-per-file: [0]
189190
max-depth: [0]
190191
max-len: [0]
@@ -245,7 +246,7 @@ rules:
245246
no-floating-decimal: [0]
246247
no-func-assign: [2]
247248
no-global-assign: [2]
248-
no-implicit-coercion: [0]
249+
no-implicit-coercion: [2]
249250
no-implicit-globals: [0]
250251
no-implied-eval: [2]
251252
no-import-assign: [2]
@@ -322,7 +323,7 @@ rules:
322323
no-unused-private-class-members: [2]
323324
no-unused-vars: [2, {args: all, argsIgnorePattern: ^_, varsIgnorePattern: ^_, caughtErrorsIgnorePattern: ^_, destructuredArrayIgnorePattern: ^_, ignoreRestSiblings: false}]
324325
no-use-before-define: [2, {functions: false, classes: true, variables: true, allowNamedExports: true}]
325-
no-useless-backreference: [0]
326+
no-useless-backreference: [2]
326327
no-useless-call: [2]
327328
no-useless-catch: [2]
328329
no-useless-computed-key: [2]
@@ -353,7 +354,7 @@ rules:
353354
prefer-named-capture-group: [0]
354355
prefer-numeric-literals: [2]
355356
prefer-object-has-own: [0]
356-
prefer-object-spread: [0]
357+
prefer-object-spread: [2]
357358
prefer-promise-reject-errors: [2, {allowEmptyReject: false}]
358359
prefer-regex-literals: [2]
359360
prefer-rest-params: [2]
@@ -455,6 +456,7 @@ rules:
455456
unicorn/no-static-only-class: [2]
456457
unicorn/no-thenable: [2]
457458
unicorn/no-this-assignment: [2]
459+
unicorn/no-unnecessary-await: [2]
458460
unicorn/no-unreadable-array-destructuring: [0]
459461
unicorn/no-unreadable-iife: [2]
460462
unicorn/no-unsafe-regex: [0]
@@ -519,6 +521,7 @@ rules:
519521
unicorn/require-number-to-fixed-digits-argument: [2]
520522
unicorn/require-post-message-target-origin: [0]
521523
unicorn/string-content: [0]
524+
unicorn/switch-case-braces: [0]
522525
unicorn/template-indent: [2]
523526
unicorn/text-encoding-identifier-case: [0]
524527
unicorn/throw-new-error: [2]

.gitattributes

+1
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

+5-7
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ lint: lint-frontend lint-backend
341341

342342
.PHONY: lint-frontend
343343
lint-frontend: node_modules
344-
npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js docs/assets/js tests/e2e/*.test.e2e.js tests/e2e/utils_e2e.js
344+
npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js docs/assets/js tests/e2e
345345
npx stylelint --color --max-warnings=0 web_src/less
346346
npx spectral lint -q -F hint $(SWAGGER_SPEC)
347347
npx markdownlint docs *.md
@@ -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

assets/go-licenses.json

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jest.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// to run tests with ES6 module, node must run with "--experimental-vm-modules", or see Makefile's "test-frontend" for reference
12
export default {
23
rootDir: 'web_src',
34
setupFilesAfterEnv: ['jest-extended/all'],
@@ -7,6 +8,8 @@ export default {
78
transform: {
89
'\\.svg$': '<rootDir>/js/testUtils/jestRawLoader.js',
910
},
11+
setupFiles: [
12+
'./js/testUtils/jestSetup.js', // prepare global variables used by our code (eg: window.config)
13+
],
1014
verbose: false,
1115
};
12-

models/auth/oauth2.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ func updateOAuth2Application(ctx context.Context, app *OAuth2Application) error
225225

226226
func deleteOAuth2Application(ctx context.Context, id, userid int64) error {
227227
sess := db.GetEngine(ctx)
228-
if deleted, err := sess.Delete(&OAuth2Application{ID: id, UID: userid}); err != nil {
228+
// the userid could be 0 if the app is instance-wide
229+
if deleted, err := sess.Where(builder.Eq{"id": id, "uid": userid}).Delete(&OAuth2Application{}); err != nil {
229230
return err
230231
} else if deleted == 0 {
231232
return ErrOAuthApplicationNotFound{ID: id}
@@ -476,7 +477,7 @@ func GetOAuth2GrantsByUserID(ctx context.Context, uid int64) ([]*OAuth2Grant, er
476477

477478
// RevokeOAuth2Grant deletes the grant with grantID and userID
478479
func RevokeOAuth2Grant(ctx context.Context, grantID, userID int64) error {
479-
_, err := db.DeleteByBean(ctx, &OAuth2Grant{ID: grantID, UserID: userID})
480+
_, err := db.GetEngine(ctx).Where(builder.Eq{"id": grantID, "user_id": userID}).Delete(&OAuth2Grant{})
480481
return err
481482
}
482483

models/repo/repo_list.go

+20-10
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

+1
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

+2-2
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

modules/packages/npm/creator.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ type PackageMetadata struct {
6666
License string `json:"license,omitempty"`
6767
}
6868

69-
// PackageMetadataVersion https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#version
69+
// PackageMetadataVersion documentation: https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#version
70+
// PackageMetadataVersion response: https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md#abbreviated-version-object
7071
type PackageMetadataVersion struct {
7172
ID string `json:"_id"`
7273
Name string `json:"name"`
@@ -80,6 +81,7 @@ type PackageMetadataVersion struct {
8081
Dependencies map[string]string `json:"dependencies,omitempty"`
8182
DevDependencies map[string]string `json:"devDependencies,omitempty"`
8283
PeerDependencies map[string]string `json:"peerDependencies,omitempty"`
84+
Bin map[string]string `json:"bin,omitempty"`
8385
OptionalDependencies map[string]string `json:"optionalDependencies,omitempty"`
8486
Readme string `json:"readme,omitempty"`
8587
Dist PackageDistribution `json:"dist"`
@@ -220,6 +222,7 @@ func ParsePackage(r io.Reader) (*Package, error) {
220222
DevelopmentDependencies: meta.DevDependencies,
221223
PeerDependencies: meta.PeerDependencies,
222224
OptionalDependencies: meta.OptionalDependencies,
225+
Bin: meta.Bin,
223226
Readme: meta.Readme,
224227
},
225228
}

modules/packages/npm/creator_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestParsePackage(t *testing.T) {
2323
packageVersion := "1.0.1-pre"
2424
packageTag := "latest"
2525
packageAuthor := "KN4CK3R"
26+
packageBin := "gitea"
2627
packageDescription := "Test Description"
2728
data := "H4sIAAAAAAAA/ytITM5OTE/VL4DQelnF+XkMVAYGBgZmJiYK2MRBwNDcSIHB2NTMwNDQzMwAqA7IMDUxA9LUdgg2UFpcklgEdAql5kD8ogCnhwio5lJQUMpLzE1VslJQcihOzi9I1S9JLS7RhSYIJR2QgrLUouLM/DyQGkM9Az1D3YIiqExKanFyUWZBCVQ2BKhVwQVJDKwosbQkI78IJO/tZ+LsbRykxFXLNdA+HwWjYBSMgpENACgAbtAACAAA"
2829
integrity := "sha512-yA4FJsVhetynGfOC1jFf79BuS+jrHbm0fhh+aHzCQkOaOBXKf9oBnC4a6DnLLnEsHQDRLYd00cwj8sCXpC+wIg=="
@@ -236,6 +237,9 @@ func TestParsePackage(t *testing.T) {
236237
Dependencies: map[string]string{
237238
"package": "1.2.0",
238239
},
240+
Bin: map[string]string{
241+
"bin": packageBin,
242+
},
239243
Dist: PackageDistribution{
240244
Integrity: integrity,
241245
},
@@ -264,6 +268,7 @@ func TestParsePackage(t *testing.T) {
264268
assert.Equal(t, packageDescription, p.Metadata.Description)
265269
assert.Equal(t, packageDescription, p.Metadata.Readme)
266270
assert.Equal(t, packageAuthor, p.Metadata.Author)
271+
assert.Equal(t, packageBin, p.Metadata.Bin["bin"])
267272
assert.Equal(t, "MIT", p.Metadata.License)
268273
assert.Equal(t, "https://gitea.io/", p.Metadata.ProjectURL)
269274
assert.Contains(t, p.Metadata.Dependencies, "package")

modules/packages/npm/metadata.go

+1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ type Metadata struct {
2020
DevelopmentDependencies map[string]string `json:"development_dependencies,omitempty"`
2121
PeerDependencies map[string]string `json:"peer_dependencies,omitempty"`
2222
OptionalDependencies map[string]string `json:"optional_dependencies,omitempty"`
23+
Bin map[string]string `json:"bin,omitempty"`
2324
Readme string `json:"readme,omitempty"`
2425
}

options/locale/TRANSLATORS

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Thomas Fanninger <gogs DOT thomas AT fanninger DOT at>
7272
Tilmann Bach <tilmann AT outlook DOT com>
7373
Toni Villena Jiménez <tonivj5 AT gmail DOT com>
7474
Viktor Sperl <viktike32 AT gmail DOT com>
75-
Vladimir Jigulin mogaika AT yandex DOT ru
75+
Vladimir Jigulin <mogaika AT yandex DOT ru>
7676
Vladimir Vissoultchev <wqweto AT gmail DOT com>
7777
Yaşar Çiv <yasarciv67 AT gmail DOT com>
7878
YJSoft <yjsoft AT yjsoft DOT pe DOT kr>

options/locale/locale_en-US.ini

+8
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
@@ -1763,8 +1767,11 @@ activity.git_stats_deletion_n = %d deletions
17631767

17641768
search = Search
17651769
search.search_repo = Search repository
1770+
search.type.tooltip = Search type
17661771
search.fuzzy = Fuzzy
1772+
search.fuzzy.tooltip = Include results that also matches the search term closely
17671773
search.match = Match
1774+
search.match.tooltip = Include only results that matches the exact search term
17681775
search.results = Search results for "%s" in <a href="%s">%s</a>
17691776
search.code_no_results = No source code matching your search term found.
17701777
search.code_search_unavailable = Currently code search is not available. Please contact your site administrator.
@@ -2310,6 +2317,7 @@ create_org = Create Organization
23102317
repo_updated = Updated
23112318
people = People
23122319
teams = Teams
2320+
code = Code
23132321
lower_members = members
23142322
lower_repositories = repositories
23152323
create_new_team = New Team

0 commit comments

Comments
 (0)