mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-04-26 06:04:46 +00:00
Merge branch 'forgejo' into forgejo
This commit is contained in:
commit
44b238e0da
28 changed files with 191 additions and 143 deletions
|
@ -26,3 +26,8 @@ insert_final_newline = false
|
||||||
|
|
||||||
[options/locale/locale_*.ini]
|
[options/locale/locale_*.ini]
|
||||||
insert_final_newline = false
|
insert_final_newline = false
|
||||||
|
|
||||||
|
# Weblate JSON output defaults to four spaces
|
||||||
|
[options/locale_next/locale_*.json]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
|
|
@ -28,7 +28,7 @@ jobs:
|
||||||
|
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: data.forgejo.org/renovate/renovate:39.185.0
|
image: data.forgejo.org/renovate/renovate:39.195.1
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Load renovate repo cache
|
- name: Load renovate repo cache
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -49,7 +49,7 @@ GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1 # renovate: datasour
|
||||||
DEADCODE_PACKAGE ?= golang.org/x/tools/cmd/deadcode@v0.31.0 # renovate: datasource=go
|
DEADCODE_PACKAGE ?= golang.org/x/tools/cmd/deadcode@v0.31.0 # renovate: datasource=go
|
||||||
GOMOCK_PACKAGE ?= go.uber.org/mock/mockgen@v0.4.0 # renovate: datasource=go
|
GOMOCK_PACKAGE ?= go.uber.org/mock/mockgen@v0.4.0 # renovate: datasource=go
|
||||||
GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.18.1 # renovate: datasource=go
|
GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.18.1 # renovate: datasource=go
|
||||||
RENOVATE_NPM_PACKAGE ?= renovate@39.185.0 # renovate: datasource=docker packageName=data.forgejo.org/renovate/renovate
|
RENOVATE_NPM_PACKAGE ?= renovate@39.195.1 # renovate: datasource=docker packageName=data.forgejo.org/renovate/renovate
|
||||||
|
|
||||||
# https://github.com/disposable-email-domains/disposable-email-domains/commits/main/
|
# https://github.com/disposable-email-domains/disposable-email-domains/commits/main/
|
||||||
DISPOSABLE_EMAILS_SHA ?= 0c27e671231d27cf66370034d7f6818037416989 # renovate: ...
|
DISPOSABLE_EMAILS_SHA ?= 0c27e671231d27cf66370034d7f6818037416989 # renovate: ...
|
||||||
|
|
5
assets/go-licenses.json
generated
5
assets/go-licenses.json
generated
File diff suppressed because one or more lines are too long
11
go.mod
11
go.mod
|
@ -49,7 +49,7 @@ require (
|
||||||
github.com/go-openapi/spec v0.20.14
|
github.com/go-openapi/spec v0.20.14
|
||||||
github.com/go-sql-driver/mysql v1.8.1
|
github.com/go-sql-driver/mysql v1.8.1
|
||||||
github.com/go-testfixtures/testfixtures/v3 v3.14.0
|
github.com/go-testfixtures/testfixtures/v3 v3.14.0
|
||||||
github.com/go-webauthn/webauthn v0.11.2
|
github.com/go-webauthn/webauthn v0.12.2
|
||||||
github.com/gobwas/glob v0.2.3
|
github.com/gobwas/glob v0.2.3
|
||||||
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f
|
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f
|
||||||
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
|
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
|
||||||
|
@ -76,7 +76,7 @@ require (
|
||||||
github.com/meilisearch/meilisearch-go v0.31.0
|
github.com/meilisearch/meilisearch-go v0.31.0
|
||||||
github.com/mholt/archiver/v3 v3.5.1
|
github.com/mholt/archiver/v3 v3.5.1
|
||||||
github.com/microcosm-cc/bluemonday v1.0.27
|
github.com/microcosm-cc/bluemonday v1.0.27
|
||||||
github.com/minio/minio-go/v7 v7.0.85
|
github.com/minio/minio-go/v7 v7.0.88
|
||||||
github.com/msteinert/pam/v2 v2.0.0
|
github.com/msteinert/pam/v2 v2.0.0
|
||||||
github.com/nektos/act v0.2.52
|
github.com/nektos/act v0.2.52
|
||||||
github.com/niklasfasching/go-org v1.7.0
|
github.com/niklasfasching/go-org v1.7.0
|
||||||
|
@ -191,8 +191,8 @@ require (
|
||||||
github.com/go-openapi/jsonpointer v0.20.2 // indirect
|
github.com/go-openapi/jsonpointer v0.20.2 // indirect
|
||||||
github.com/go-openapi/jsonreference v0.20.4 // indirect
|
github.com/go-openapi/jsonreference v0.20.4 // indirect
|
||||||
github.com/go-openapi/swag v0.22.7 // indirect
|
github.com/go-openapi/swag v0.22.7 // indirect
|
||||||
github.com/go-webauthn/x v0.1.14 // indirect
|
github.com/go-webauthn/x v0.1.19 // indirect
|
||||||
github.com/goccy/go-json v0.10.4 // indirect
|
github.com/goccy/go-json v0.10.5 // indirect
|
||||||
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
|
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
|
||||||
github.com/golang/geo v0.0.0-20230421003525-6adc56603217 // indirect
|
github.com/golang/geo v0.0.0-20230421003525-6adc56603217 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
|
@ -201,7 +201,7 @@ require (
|
||||||
github.com/google/btree v1.1.2 // indirect
|
github.com/google/btree v1.1.2 // indirect
|
||||||
github.com/google/go-cmp v0.7.0 // indirect
|
github.com/google/go-cmp v0.7.0 // indirect
|
||||||
github.com/google/go-querystring v1.1.0 // indirect
|
github.com/google/go-querystring v1.1.0 // indirect
|
||||||
github.com/google/go-tpm v0.9.1 // indirect
|
github.com/google/go-tpm v0.9.3 // indirect
|
||||||
github.com/google/s2a-go v0.1.8 // indirect
|
github.com/google/s2a-go v0.1.8 // indirect
|
||||||
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
|
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
|
||||||
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
|
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
|
||||||
|
@ -222,6 +222,7 @@ require (
|
||||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||||
github.com/mholt/acmez/v3 v3.1.0 // indirect
|
github.com/mholt/acmez/v3 v3.1.0 // indirect
|
||||||
github.com/miekg/dns v1.1.63 // indirect
|
github.com/miekg/dns v1.1.63 // indirect
|
||||||
|
github.com/minio/crc64nvme v1.0.1 // indirect
|
||||||
github.com/minio/md5-simd v1.1.2 // indirect
|
github.com/minio/md5-simd v1.1.2 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
|
22
go.sum
22
go.sum
|
@ -967,18 +967,18 @@ github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
|
||||||
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
|
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
|
||||||
github.com/go-testfixtures/testfixtures/v3 v3.14.0 h1:aRt5qyH2XjzFgCC5NizNs6QrzjO7rC4pQZ1oJpPIdo8=
|
github.com/go-testfixtures/testfixtures/v3 v3.14.0 h1:aRt5qyH2XjzFgCC5NizNs6QrzjO7rC4pQZ1oJpPIdo8=
|
||||||
github.com/go-testfixtures/testfixtures/v3 v3.14.0/go.mod h1:HHb6Yd8spzm6aFZU6jwBj9qFvVUNNkx5nGbjG4UHeOE=
|
github.com/go-testfixtures/testfixtures/v3 v3.14.0/go.mod h1:HHb6Yd8spzm6aFZU6jwBj9qFvVUNNkx5nGbjG4UHeOE=
|
||||||
github.com/go-webauthn/webauthn v0.11.2 h1:Fgx0/wlmkClTKlnOsdOQ+K5HcHDsDcYIvtYmfhEOSUc=
|
github.com/go-webauthn/webauthn v0.12.2 h1:yLaNPgBUEXDQtWnOjhsGhMMCEWbXwjg/aNkC8riJQI8=
|
||||||
github.com/go-webauthn/webauthn v0.11.2/go.mod h1:aOtudaF94pM71g3jRwTYYwQTG1KyTILTcZqN1srkmD0=
|
github.com/go-webauthn/webauthn v0.12.2/go.mod h1:Q8SZPPj4sZ469fNTcQXxRpzJOdb30jQrn/36FX8jilA=
|
||||||
github.com/go-webauthn/x v0.1.14 h1:1wrB8jzXAofojJPAaRxnZhRgagvLGnLjhCAwg3kTpT0=
|
github.com/go-webauthn/x v0.1.19 h1:IUfdHiBRoTdujpBA/14qbrMXQ3LGzYe/PRGWdZcmudg=
|
||||||
github.com/go-webauthn/x v0.1.14/go.mod h1:UuVvFZ8/NbOnkDz3y1NaxtUN87pmtpC1PQ+/5BBQRdc=
|
github.com/go-webauthn/x v0.1.19/go.mod h1:C5arLuTQ3pVHKPw89v7CDGnqAZSZJj+4Jnr40dsn7tk=
|
||||||
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
|
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
|
||||||
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
||||||
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
|
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
|
||||||
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||||
github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY=
|
github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY=
|
||||||
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||||
github.com/goccy/go-json v0.10.4 h1:JSwxQzIqKfmFX1swYPpUThQZp/Ka4wzJdK0LWVytLPM=
|
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
||||||
github.com/goccy/go-json v0.10.4/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||||
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f h1:3BSP1Tbs2djlpprl7wCLuiqMaUh5SJkkzI2gDs+FgLs=
|
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f h1:3BSP1Tbs2djlpprl7wCLuiqMaUh5SJkkzI2gDs+FgLs=
|
||||||
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f/go.mod h1:Pcatq5tYkCW2Q6yrR2VRHlbHpZ/R4/7qyL1TCF7vl14=
|
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f/go.mod h1:Pcatq5tYkCW2Q6yrR2VRHlbHpZ/R4/7qyL1TCF7vl14=
|
||||||
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85 h1:UjoPNDAQ5JPCjlxoJd6K8ALZqSDDhk2ymieAZOVaDg0=
|
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85 h1:UjoPNDAQ5JPCjlxoJd6K8ALZqSDDhk2ymieAZOVaDg0=
|
||||||
|
@ -1065,8 +1065,8 @@ github.com/google/go-github/v64 v64.0.0 h1:4G61sozmY3eiPAjjoOHponXDBONm+utovTKby
|
||||||
github.com/google/go-github/v64 v64.0.0/go.mod h1:xB3vqMQNdHzilXBiO2I+M7iEFtHf+DP/omBOv6tQzVo=
|
github.com/google/go-github/v64 v64.0.0/go.mod h1:xB3vqMQNdHzilXBiO2I+M7iEFtHf+DP/omBOv6tQzVo=
|
||||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||||
github.com/google/go-tpm v0.9.1 h1:0pGc4X//bAlmZzMKf8iz6IsDo1nYTbYJ6FZN/rg4zdM=
|
github.com/google/go-tpm v0.9.3 h1:+yx0/anQuGzi+ssRqeD6WpXjW2L/V0dItUayO0i9sRc=
|
||||||
github.com/google/go-tpm v0.9.1/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
github.com/google/go-tpm v0.9.3/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
@ -1264,10 +1264,12 @@ github.com/miekg/dns v1.1.63 h1:8M5aAw6OMZfFXTT7K5V0Eu5YiiL8l7nUAkyN6C9YwaY=
|
||||||
github.com/miekg/dns v1.1.63/go.mod h1:6NGHfjhpmr5lt3XPLuyfDJi5AXbNIPM9PY6H6sF1Nfs=
|
github.com/miekg/dns v1.1.63/go.mod h1:6NGHfjhpmr5lt3XPLuyfDJi5AXbNIPM9PY6H6sF1Nfs=
|
||||||
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8/go.mod h1:mC1jAcsrzbxHt8iiaC+zU4b1ylILSosueou12R++wfY=
|
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8/go.mod h1:mC1jAcsrzbxHt8iiaC+zU4b1ylILSosueou12R++wfY=
|
||||||
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE=
|
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE=
|
||||||
|
github.com/minio/crc64nvme v1.0.1 h1:DHQPrYPdqK7jQG/Ls5CTBZWeex/2FMS3G5XGkycuFrY=
|
||||||
|
github.com/minio/crc64nvme v1.0.1/go.mod h1:eVfm2fAzLlxMdUGc0EEBGSMmPwmXD5XiNRpnu9J3bvg=
|
||||||
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
|
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
|
||||||
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
|
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
|
||||||
github.com/minio/minio-go/v7 v7.0.85 h1:9psTLS/NTvC3MWoyjhjXpwcKoNbkongaCSF3PNpSuXo=
|
github.com/minio/minio-go/v7 v7.0.88 h1:v8MoIJjwYxOkehp+eiLIuvXk87P2raUtoU5klrAAshs=
|
||||||
github.com/minio/minio-go/v7 v7.0.85/go.mod h1:57YXpvc5l3rjPdhqNrDsvVlY0qPI6UTk1bflAe+9doY=
|
github.com/minio/minio-go/v7 v7.0.88/go.mod h1:33+O8h0tO7pCeCWwBVa07RhVVfB/3vS4kEX7rwYKmIg=
|
||||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
|
|
@ -45,13 +45,10 @@ func init() {
|
||||||
// GetSchedulesMapByIDs returns the schedules by given id slice.
|
// GetSchedulesMapByIDs returns the schedules by given id slice.
|
||||||
func GetSchedulesMapByIDs(ctx context.Context, ids []int64) (map[int64]*ActionSchedule, error) {
|
func GetSchedulesMapByIDs(ctx context.Context, ids []int64) (map[int64]*ActionSchedule, error) {
|
||||||
schedules := make(map[int64]*ActionSchedule, len(ids))
|
schedules := make(map[int64]*ActionSchedule, len(ids))
|
||||||
return schedules, db.GetEngine(ctx).In("id", ids).Find(&schedules)
|
if len(ids) == 0 {
|
||||||
|
return schedules, nil
|
||||||
}
|
}
|
||||||
|
return schedules, db.GetEngine(ctx).In("id", ids).Find(&schedules)
|
||||||
// GetReposMapByIDs returns the repos by given id slice.
|
|
||||||
func GetReposMapByIDs(ctx context.Context, ids []int64) (map[int64]*repo_model.Repository, error) {
|
|
||||||
repos := make(map[int64]*repo_model.Repository, len(ids))
|
|
||||||
return repos, db.GetEngine(ctx).In("id", ids).Find(&repos)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateScheduleTask creates new schedule task.
|
// CreateScheduleTask creates new schedule task.
|
||||||
|
|
|
@ -36,7 +36,7 @@ func (specs SpecList) LoadSchedules(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
repoIDs := specs.GetRepoIDs()
|
repoIDs := specs.GetRepoIDs()
|
||||||
repos, err := GetReposMapByIDs(ctx, repoIDs)
|
repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,6 +269,9 @@ func FindIDs(ctx context.Context, tableName, idCol string, cond builder.Cond) ([
|
||||||
// DecrByIDs decreases the given column for entities of the "bean" type with one of the given ids by one
|
// DecrByIDs decreases the given column for entities of the "bean" type with one of the given ids by one
|
||||||
// Timestamps of the entities won't be updated
|
// Timestamps of the entities won't be updated
|
||||||
func DecrByIDs(ctx context.Context, ids []int64, decrCol string, bean any) error {
|
func DecrByIDs(ctx context.Context, ids []int64, decrCol string, bean any) error {
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
_, err := GetEngine(ctx).Decr(decrCol).In("id", ids).NoAutoCondition().NoAutoTime().Update(bean)
|
_, err := GetEngine(ctx).Decr(decrCol).In("id", ids).NoAutoCondition().NoAutoTime().Update(bean)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -546,6 +546,9 @@ func GetIssueByID(ctx context.Context, id int64) (*Issue, error) {
|
||||||
// If keepOrder is true, the order of the returned issues will be the same as the given IDs.
|
// If keepOrder is true, the order of the returned issues will be the same as the given IDs.
|
||||||
func GetIssuesByIDs(ctx context.Context, issueIDs []int64, keepOrder ...bool) (IssueList, error) {
|
func GetIssuesByIDs(ctx context.Context, issueIDs []int64, keepOrder ...bool) (IssueList, error) {
|
||||||
issues := make([]*Issue, 0, len(issueIDs))
|
issues := make([]*Issue, 0, len(issueIDs))
|
||||||
|
if len(issueIDs) == 0 {
|
||||||
|
return issues, nil
|
||||||
|
}
|
||||||
|
|
||||||
if err := db.GetEngine(ctx).In("id", issueIDs).Find(&issues); err != nil {
|
if err := db.GetEngine(ctx).In("id", issueIDs).Find(&issues); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -303,6 +303,9 @@ func GetLabelByID(ctx context.Context, labelID int64) (*Label, error) {
|
||||||
// GetLabelsByIDs returns a list of labels by IDs
|
// GetLabelsByIDs returns a list of labels by IDs
|
||||||
func GetLabelsByIDs(ctx context.Context, labelIDs []int64, cols ...string) ([]*Label, error) {
|
func GetLabelsByIDs(ctx context.Context, labelIDs []int64, cols ...string) ([]*Label, error) {
|
||||||
labels := make([]*Label, 0, len(labelIDs))
|
labels := make([]*Label, 0, len(labelIDs))
|
||||||
|
if len(labelIDs) == 0 {
|
||||||
|
return labels, nil
|
||||||
|
}
|
||||||
return labels, db.GetEngine(ctx).Table("label").
|
return labels, db.GetEngine(ctx).Table("label").
|
||||||
In("id", labelIDs).
|
In("id", labelIDs).
|
||||||
Asc("name").
|
Asc("name").
|
||||||
|
@ -379,6 +382,9 @@ func BuildLabelNamesIssueIDsCondition(labelNames []string) *builder.Builder {
|
||||||
// it silently ignores label IDs that do not belong to the repository.
|
// it silently ignores label IDs that do not belong to the repository.
|
||||||
func GetLabelsInRepoByIDs(ctx context.Context, repoID int64, labelIDs []int64) ([]*Label, error) {
|
func GetLabelsInRepoByIDs(ctx context.Context, repoID int64, labelIDs []int64) ([]*Label, error) {
|
||||||
labels := make([]*Label, 0, len(labelIDs))
|
labels := make([]*Label, 0, len(labelIDs))
|
||||||
|
if len(labelIDs) == 0 {
|
||||||
|
return labels, nil
|
||||||
|
}
|
||||||
return labels, db.GetEngine(ctx).
|
return labels, db.GetEngine(ctx).
|
||||||
Where("repo_id = ?", repoID).
|
Where("repo_id = ?", repoID).
|
||||||
In("id", labelIDs).
|
In("id", labelIDs).
|
||||||
|
@ -451,6 +457,9 @@ func GetLabelInOrgByID(ctx context.Context, orgID, labelID int64) (*Label, error
|
||||||
// it silently ignores label IDs that do not belong to the organization.
|
// it silently ignores label IDs that do not belong to the organization.
|
||||||
func GetLabelsInOrgByIDs(ctx context.Context, orgID int64, labelIDs []int64) ([]*Label, error) {
|
func GetLabelsInOrgByIDs(ctx context.Context, orgID int64, labelIDs []int64) ([]*Label, error) {
|
||||||
labels := make([]*Label, 0, len(labelIDs))
|
labels := make([]*Label, 0, len(labelIDs))
|
||||||
|
if len(labelIDs) == 0 {
|
||||||
|
return labels, nil
|
||||||
|
}
|
||||||
return labels, db.GetEngine(ctx).
|
return labels, db.GetEngine(ctx).
|
||||||
Where("org_id = ?", orgID).
|
Where("org_id = ?", orgID).
|
||||||
In("id", labelIDs).
|
In("id", labelIDs).
|
||||||
|
|
|
@ -293,6 +293,9 @@ func SetDefaultColumn(ctx context.Context, projectID, columnID int64) error {
|
||||||
|
|
||||||
func GetColumnsByIDs(ctx context.Context, projectID int64, columnsIDs []int64) (ColumnList, error) {
|
func GetColumnsByIDs(ctx context.Context, projectID int64, columnsIDs []int64) (ColumnList, error) {
|
||||||
columns := make([]*Column, 0, 5)
|
columns := make([]*Column, 0, 5)
|
||||||
|
if len(columnsIDs) == 0 {
|
||||||
|
return columns, nil
|
||||||
|
}
|
||||||
if err := db.GetEngine(ctx).
|
if err := db.GetEngine(ctx).
|
||||||
Where("project_id =?", projectID).
|
Where("project_id =?", projectID).
|
||||||
In("id", columnsIDs).
|
In("id", columnsIDs).
|
||||||
|
|
|
@ -28,10 +28,10 @@ type GrepResult struct {
|
||||||
HighlightedRanges [][3]int
|
HighlightedRanges [][3]int
|
||||||
}
|
}
|
||||||
|
|
||||||
type grepMode int
|
type GrepMode int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FixedGrepMode grepMode = iota
|
FixedGrepMode GrepMode = iota
|
||||||
FixedAnyGrepMode
|
FixedAnyGrepMode
|
||||||
RegExpGrepMode
|
RegExpGrepMode
|
||||||
)
|
)
|
||||||
|
@ -43,7 +43,7 @@ type GrepOptions struct {
|
||||||
MaxResultLimit int
|
MaxResultLimit int
|
||||||
MatchesPerFile int // >= git 2.38
|
MatchesPerFile int // >= git 2.38
|
||||||
ContextLineNumber int
|
ContextLineNumber int
|
||||||
Mode grepMode
|
Mode GrepMode
|
||||||
Filename string
|
Filename string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,10 +40,6 @@ import (
|
||||||
const (
|
const (
|
||||||
unicodeNormalizeName = "unicodeNormalize"
|
unicodeNormalizeName = "unicodeNormalize"
|
||||||
maxBatchSize = 16
|
maxBatchSize = 16
|
||||||
// fuzzyDenominator determines the levenshtein distance per each character of a keyword
|
|
||||||
fuzzyDenominator = 4
|
|
||||||
// see https://github.com/blevesearch/bleve/issues/1563#issuecomment-786822311
|
|
||||||
maxFuzziness = 2
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func addUnicodeNormalizeTokenFilter(m *mapping.IndexMappingImpl) error {
|
func addUnicodeNormalizeTokenFilter(m *mapping.IndexMappingImpl) error {
|
||||||
|
@ -260,12 +256,14 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
|
||||||
keywordQuery query.Query
|
keywordQuery query.Query
|
||||||
)
|
)
|
||||||
|
|
||||||
phraseQuery := bleve.NewMatchPhraseQuery(opts.Keyword)
|
if opts.Mode == internal.CodeSearchModeUnion {
|
||||||
phraseQuery.FieldVal = "Content"
|
query := bleve.NewDisjunctionQuery()
|
||||||
phraseQuery.Analyzer = repoIndexerAnalyzer
|
for _, field := range strings.Fields(opts.Keyword) {
|
||||||
keywordQuery = phraseQuery
|
query.AddQuery(inner_bleve.MatchPhraseQuery(field, "Content", repoIndexerAnalyzer, 0))
|
||||||
if opts.IsKeywordFuzzy {
|
}
|
||||||
phraseQuery.Fuzziness = min(maxFuzziness, len(opts.Keyword)/fuzzyDenominator)
|
keywordQuery = query
|
||||||
|
} else {
|
||||||
|
keywordQuery = inner_bleve.MatchPhraseQuery(opts.Keyword, "Content", repoIndexerAnalyzer, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opts.RepoIDs) > 0 {
|
if len(opts.RepoIDs) > 0 {
|
||||||
|
@ -325,13 +323,16 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
|
||||||
for i, hit := range result.Hits {
|
for i, hit := range result.Hits {
|
||||||
startIndex, endIndex := -1, -1
|
startIndex, endIndex := -1, -1
|
||||||
for _, locations := range hit.Locations["Content"] {
|
for _, locations := range hit.Locations["Content"] {
|
||||||
|
if startIndex != -1 && endIndex != -1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
location := locations[0]
|
location := locations[0]
|
||||||
locationStart := int(location.Start)
|
locationStart := int(location.Start)
|
||||||
locationEnd := int(location.End)
|
locationEnd := int(location.End)
|
||||||
if startIndex < 0 || locationStart < startIndex {
|
if startIndex < 0 || locationStart < startIndex {
|
||||||
startIndex = locationStart
|
startIndex = locationStart
|
||||||
}
|
}
|
||||||
if endIndex < 0 || locationEnd > endIndex {
|
if endIndex < 0 && locationEnd > endIndex {
|
||||||
endIndex = locationEnd
|
endIndex = locationEnd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ const (
|
||||||
// multi-match-types, currently only 2 types are used
|
// multi-match-types, currently only 2 types are used
|
||||||
// Reference: https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-multi-match-query.html#multi-match-types
|
// Reference: https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-multi-match-query.html#multi-match-types
|
||||||
esMultiMatchTypeBestFields = "best_fields"
|
esMultiMatchTypeBestFields = "best_fields"
|
||||||
esMultiMatchTypePhrasePrefix = "phrase_prefix"
|
esMultiMatchTypePhrase = "phrase"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ internal.Indexer = &Indexer{}
|
var _ internal.Indexer = &Indexer{}
|
||||||
|
@ -334,8 +334,8 @@ func extractAggs(searchResult *elastic.SearchResult) []*internal.SearchResultLan
|
||||||
|
|
||||||
// Search searches for codes and language stats by given conditions.
|
// Search searches for codes and language stats by given conditions.
|
||||||
func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int64, []*internal.SearchResult, []*internal.SearchResultLanguages, error) {
|
func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int64, []*internal.SearchResult, []*internal.SearchResultLanguages, error) {
|
||||||
searchType := esMultiMatchTypePhrasePrefix
|
searchType := esMultiMatchTypePhrase
|
||||||
if opts.IsKeywordFuzzy {
|
if opts.Mode == internal.CodeSearchModeUnion {
|
||||||
searchType = esMultiMatchTypeBestFields
|
searchType = esMultiMatchTypeBestFields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
|
||||||
PageSize: 10,
|
PageSize: 10,
|
||||||
},
|
},
|
||||||
Filename: kw.Filename,
|
Filename: kw.Filename,
|
||||||
IsKeywordFuzzy: true,
|
Mode: SearchModeUnion,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, kw.IDs, int(total))
|
assert.Len(t, kw.IDs, int(total))
|
||||||
|
|
|
@ -20,13 +20,27 @@ type Indexer interface {
|
||||||
Search(ctx context.Context, opts *SearchOptions) (int64, []*SearchResult, []*SearchResultLanguages, error)
|
Search(ctx context.Context, opts *SearchOptions) (int64, []*SearchResult, []*SearchResultLanguages, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CodeSearchMode int
|
||||||
|
|
||||||
|
const (
|
||||||
|
CodeSearchModeExact CodeSearchMode = iota
|
||||||
|
CodeSearchModeUnion
|
||||||
|
)
|
||||||
|
|
||||||
|
func (mode CodeSearchMode) String() string {
|
||||||
|
if mode == CodeSearchModeUnion {
|
||||||
|
return "union"
|
||||||
|
}
|
||||||
|
return "exact"
|
||||||
|
}
|
||||||
|
|
||||||
type SearchOptions struct {
|
type SearchOptions struct {
|
||||||
RepoIDs []int64
|
RepoIDs []int64
|
||||||
Keyword string
|
Keyword string
|
||||||
Language string
|
Language string
|
||||||
Filename string
|
Filename string
|
||||||
|
|
||||||
IsKeywordFuzzy bool
|
Mode CodeSearchMode
|
||||||
|
|
||||||
db.Paginator
|
db.Paginator
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,14 @@ type SearchResultLanguages = internal.SearchResultLanguages
|
||||||
|
|
||||||
type SearchOptions = internal.SearchOptions
|
type SearchOptions = internal.SearchOptions
|
||||||
|
|
||||||
var CodeSearchOptions = [2]string{"exact", "fuzzy"}
|
var CodeSearchOptions = [2]string{"exact", "union"}
|
||||||
|
|
||||||
|
type SearchMode = internal.CodeSearchMode
|
||||||
|
|
||||||
|
const (
|
||||||
|
SearchModeExact = internal.CodeSearchModeExact
|
||||||
|
SearchModeUnion = internal.CodeSearchModeUnion
|
||||||
|
)
|
||||||
|
|
||||||
func indices(content string, selectionStartIndex, selectionEndIndex int) (int, int) {
|
func indices(content string, selectionStartIndex, selectionEndIndex int) (int, int) {
|
||||||
startIndex := selectionStartIndex
|
startIndex := selectionStartIndex
|
||||||
|
@ -206,7 +213,6 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerformSearch perform a search on a repository
|
// PerformSearch perform a search on a repository
|
||||||
// if isFuzzy is true set the Damerau-Levenshtein distance from 0 to 2
|
|
||||||
func PerformSearch(ctx context.Context, opts *SearchOptions) (int, []*Result, []*SearchResultLanguages, error) {
|
func PerformSearch(ctx context.Context, opts *SearchOptions) (int, []*Result, []*SearchResultLanguages, error) {
|
||||||
if opts == nil || len(opts.Keyword) == 0 {
|
if opts == nil || len(opts.Keyword) == 0 {
|
||||||
return 0, nil, nil, nil
|
return 0, nil, nil, nil
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
package keying
|
package keying
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/hkdf"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
|
||||||
"golang.org/x/crypto/chacha20poly1305"
|
"golang.org/x/crypto/chacha20poly1305"
|
||||||
"golang.org/x/crypto/hkdf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -41,7 +41,11 @@ const (
|
||||||
// Set the main IKM for this module.
|
// Set the main IKM for this module.
|
||||||
func Init(ikm []byte) {
|
func Init(ikm []byte) {
|
||||||
// Salt is intentionally left empty, it's not useful to Forgejo's use case.
|
// Salt is intentionally left empty, it's not useful to Forgejo's use case.
|
||||||
prk = hkdf.Extract(hash, ikm, nil)
|
var err error
|
||||||
|
prk, err = hkdf.Extract(hash, ikm, nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specifies the context for which a subkey should be derived for.
|
// Specifies the context for which a subkey should be derived for.
|
||||||
|
@ -62,11 +66,8 @@ func DeriveKey(context Context) *Key {
|
||||||
panic("keying: not initialized")
|
panic("keying: not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
r := hkdf.Expand(hash, prk, []byte(context))
|
key, err := hkdf.Expand(hash, prk, string(context), aeadKeySize)
|
||||||
|
if err != nil {
|
||||||
key := make([]byte, aeadKeySize)
|
|
||||||
// This should never return an error, but if it does, panic.
|
|
||||||
if n, err := r.Read(key); err != nil || n != aeadKeySize {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
poetry.lock
generated
10
poetry.lock
generated
|
@ -404,13 +404,13 @@ files = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yamllint"
|
name = "yamllint"
|
||||||
version = "1.35.1"
|
version = "1.36.0"
|
||||||
description = "A linter for YAML files."
|
description = "A linter for YAML files."
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.8"
|
python-versions = ">=3.9"
|
||||||
files = [
|
files = [
|
||||||
{file = "yamllint-1.35.1-py3-none-any.whl", hash = "sha256:2e16e504bb129ff515b37823b472750b36b6de07963bd74b307341ef5ad8bdc3"},
|
{file = "yamllint-1.36.0-py3-none-any.whl", hash = "sha256:22ab6a7db9d5f0954bd7a50ef70a41c1465c61f955893070b0767c0ec6693b7b"},
|
||||||
{file = "yamllint-1.35.1.tar.gz", hash = "sha256:7a003809f88324fd2c877734f2d575ee7881dd9043360657cc8049c809eba6cd"},
|
{file = "yamllint-1.36.0.tar.gz", hash = "sha256:3835a65994858679ea06fd998dd968c3f71935cd93742990405999d888e21130"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.dependencies]
|
[package.dependencies]
|
||||||
|
@ -423,4 +423,4 @@ dev = ["doc8", "flake8", "flake8-import-order", "rstcheck[sphinx]", "sphinx"]
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.10"
|
python-versions = "^3.10"
|
||||||
content-hash = "f0f2f5f83d2277f5c289c62b96a2526fc89a7d54a88ac5fd044a022486c1cbb7"
|
content-hash = "c8ff4ba89b1588b4222e79f9832b3596b5c5d5a2fce8c5659b90bd31bd0f61b0"
|
||||||
|
|
|
@ -6,7 +6,7 @@ python = "^3.10"
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
djlint = "1.36.4"
|
djlint = "1.36.4"
|
||||||
yamllint = "1.35.1"
|
yamllint = "1.36.0"
|
||||||
codespell = "2.4.1"
|
codespell = "2.4.1"
|
||||||
|
|
||||||
[tool.djlint]
|
[tool.djlint]
|
||||||
|
|
|
@ -85,7 +85,7 @@ func Search(ctx *context.APIContext) {
|
||||||
// type: boolean
|
// type: boolean
|
||||||
// - name: is_private
|
// - name: is_private
|
||||||
// in: query
|
// in: query
|
||||||
// description: show only pubic, private or all repositories (defaults to all)
|
// description: show only public, private or all repositories (defaults to all)
|
||||||
// type: boolean
|
// type: boolean
|
||||||
// - name: template
|
// - name: template
|
||||||
// in: query
|
// in: query
|
||||||
|
|
|
@ -37,19 +37,17 @@ func Code(ctx *context.Context) {
|
||||||
keyword := ctx.FormTrim("q")
|
keyword := ctx.FormTrim("q")
|
||||||
path := ctx.FormTrim("path")
|
path := ctx.FormTrim("path")
|
||||||
|
|
||||||
isFuzzy := ctx.FormOptionalBool("fuzzy").ValueOrDefault(true)
|
mode := code_indexer.SearchModeExact
|
||||||
if mode := ctx.FormTrim("mode"); len(mode) > 0 {
|
if m := ctx.FormTrim("mode"); m == "union" ||
|
||||||
isFuzzy = mode == "fuzzy"
|
m == "fuzzy" ||
|
||||||
|
ctx.FormBool("fuzzy") {
|
||||||
|
mode = code_indexer.SearchModeUnion
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["Keyword"] = keyword
|
ctx.Data["Keyword"] = keyword
|
||||||
ctx.Data["Language"] = language
|
ctx.Data["Language"] = language
|
||||||
ctx.Data["CodeSearchOptions"] = []string{"exact", "fuzzy"}
|
ctx.Data["CodeSearchOptions"] = code_indexer.CodeSearchOptions
|
||||||
if isFuzzy {
|
ctx.Data["CodeSearchMode"] = mode.String()
|
||||||
ctx.Data["CodeSearchMode"] = "fuzzy"
|
|
||||||
} else {
|
|
||||||
ctx.Data["CodeSearchMode"] = "exact"
|
|
||||||
}
|
|
||||||
ctx.Data["PageIsViewCode"] = true
|
ctx.Data["PageIsViewCode"] = true
|
||||||
|
|
||||||
if keyword == "" {
|
if keyword == "" {
|
||||||
|
@ -90,7 +88,7 @@ func Code(ctx *context.Context) {
|
||||||
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, &code_indexer.SearchOptions{
|
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, &code_indexer.SearchOptions{
|
||||||
RepoIDs: repoIDs,
|
RepoIDs: repoIDs,
|
||||||
Keyword: keyword,
|
Keyword: keyword,
|
||||||
IsKeywordFuzzy: isFuzzy,
|
Mode: mode,
|
||||||
Language: language,
|
Language: language,
|
||||||
Filename: path,
|
Filename: path,
|
||||||
Paginator: &db.ListOptions{
|
Paginator: &db.ListOptions{
|
||||||
|
|
|
@ -21,14 +21,14 @@ type searchMode int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ExactSearchMode searchMode = iota
|
ExactSearchMode searchMode = iota
|
||||||
FuzzySearchMode
|
UnionSearchMode
|
||||||
RegExpSearchMode
|
RegExpSearchMode
|
||||||
)
|
)
|
||||||
|
|
||||||
func searchModeFromString(s string) searchMode {
|
func searchModeFromString(s string) searchMode {
|
||||||
switch s {
|
switch s {
|
||||||
case "fuzzy", "union":
|
case "fuzzy", "union":
|
||||||
return FuzzySearchMode
|
return UnionSearchMode
|
||||||
case "regexp":
|
case "regexp":
|
||||||
return RegExpSearchMode
|
return RegExpSearchMode
|
||||||
default:
|
default:
|
||||||
|
@ -40,8 +40,8 @@ func (m searchMode) String() string {
|
||||||
switch m {
|
switch m {
|
||||||
case ExactSearchMode:
|
case ExactSearchMode:
|
||||||
return "exact"
|
return "exact"
|
||||||
case FuzzySearchMode:
|
case UnionSearchMode:
|
||||||
return "fuzzy"
|
return "union"
|
||||||
case RegExpSearchMode:
|
case RegExpSearchMode:
|
||||||
return "regexp"
|
return "regexp"
|
||||||
default:
|
default:
|
||||||
|
@ -49,6 +49,24 @@ func (m searchMode) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m searchMode) ToIndexer() code_indexer.SearchMode {
|
||||||
|
if m == ExactSearchMode {
|
||||||
|
return code_indexer.SearchModeExact
|
||||||
|
}
|
||||||
|
return code_indexer.SearchModeUnion
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m searchMode) ToGitGrep() git.GrepMode {
|
||||||
|
switch m {
|
||||||
|
case RegExpSearchMode:
|
||||||
|
return git.RegExpGrepMode
|
||||||
|
case UnionSearchMode:
|
||||||
|
return git.FixedAnyGrepMode
|
||||||
|
default:
|
||||||
|
return git.FixedGrepMode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Search render repository search page
|
// Search render repository search page
|
||||||
func Search(ctx *context.Context) {
|
func Search(ctx *context.Context) {
|
||||||
language := ctx.FormTrim("l")
|
language := ctx.FormTrim("l")
|
||||||
|
@ -59,7 +77,7 @@ func Search(ctx *context.Context) {
|
||||||
if modeStr := ctx.FormString("mode"); len(modeStr) > 0 {
|
if modeStr := ctx.FormString("mode"); len(modeStr) > 0 {
|
||||||
mode = searchModeFromString(modeStr)
|
mode = searchModeFromString(modeStr)
|
||||||
} else if ctx.FormOptionalBool("fuzzy").ValueOrDefault(true) { // for backward compatibility in links
|
} else if ctx.FormOptionalBool("fuzzy").ValueOrDefault(true) { // for backward compatibility in links
|
||||||
mode = FuzzySearchMode
|
mode = UnionSearchMode
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["Keyword"] = keyword
|
ctx.Data["Keyword"] = keyword
|
||||||
|
@ -92,7 +110,7 @@ func Search(ctx *context.Context) {
|
||||||
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, &code_indexer.SearchOptions{
|
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, &code_indexer.SearchOptions{
|
||||||
RepoIDs: []int64{ctx.Repo.Repository.ID},
|
RepoIDs: []int64{ctx.Repo.Repository.ID},
|
||||||
Keyword: keyword,
|
Keyword: keyword,
|
||||||
IsKeywordFuzzy: mode == FuzzySearchMode,
|
Mode: mode.ToIndexer(),
|
||||||
Language: language,
|
Language: language,
|
||||||
Filename: path,
|
Filename: path,
|
||||||
Paginator: &db.ListOptions{
|
Paginator: &db.ListOptions{
|
||||||
|
@ -110,19 +128,12 @@ func Search(ctx *context.Context) {
|
||||||
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
|
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
grepOpt := git.GrepOptions{
|
res, err := git.GrepSearch(ctx, ctx.Repo.GitRepo, keyword, git.GrepOptions{
|
||||||
ContextLineNumber: 1,
|
ContextLineNumber: 1,
|
||||||
RefName: ctx.Repo.RefName,
|
RefName: ctx.Repo.RefName,
|
||||||
Filename: path,
|
Filename: path,
|
||||||
}
|
Mode: mode.ToGitGrep(),
|
||||||
switch mode {
|
})
|
||||||
case FuzzySearchMode:
|
|
||||||
grepOpt.Mode = git.FixedAnyGrepMode
|
|
||||||
ctx.Data["CodeSearchMode"] = "union"
|
|
||||||
case RegExpSearchMode:
|
|
||||||
grepOpt.Mode = git.RegExpGrepMode
|
|
||||||
}
|
|
||||||
res, err := git.GrepSearch(ctx, ctx.Repo.GitRepo, keyword, grepOpt)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GrepSearch", err)
|
ctx.ServerError("GrepSearch", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -41,19 +41,17 @@ func CodeSearch(ctx *context.Context) {
|
||||||
keyword := ctx.FormTrim("q")
|
keyword := ctx.FormTrim("q")
|
||||||
path := ctx.FormTrim("path")
|
path := ctx.FormTrim("path")
|
||||||
|
|
||||||
isFuzzy := ctx.FormOptionalBool("fuzzy").ValueOrDefault(true)
|
mode := code_indexer.SearchModeExact
|
||||||
if mode := ctx.FormTrim("mode"); len(mode) > 0 {
|
if m := ctx.FormTrim("mode"); m == "union" ||
|
||||||
isFuzzy = mode == "fuzzy"
|
m == "fuzzy" ||
|
||||||
|
ctx.FormBool("fuzzy") {
|
||||||
|
mode = code_indexer.SearchModeUnion
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["Keyword"] = keyword
|
ctx.Data["Keyword"] = keyword
|
||||||
ctx.Data["Language"] = language
|
ctx.Data["Language"] = language
|
||||||
ctx.Data["CodeSearchOptions"] = []string{"exact", "fuzzy"}
|
ctx.Data["CodeSearchOptions"] = code_indexer.CodeSearchOptions
|
||||||
if isFuzzy {
|
ctx.Data["CodeSearchMode"] = mode.String()
|
||||||
ctx.Data["CodeSearchMode"] = "fuzzy"
|
|
||||||
} else {
|
|
||||||
ctx.Data["CodeSearchMode"] = "exact"
|
|
||||||
}
|
|
||||||
ctx.Data["IsCodePage"] = true
|
ctx.Data["IsCodePage"] = true
|
||||||
|
|
||||||
if keyword == "" {
|
if keyword == "" {
|
||||||
|
@ -87,7 +85,7 @@ func CodeSearch(ctx *context.Context) {
|
||||||
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, &code_indexer.SearchOptions{
|
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, &code_indexer.SearchOptions{
|
||||||
RepoIDs: repoIDs,
|
RepoIDs: repoIDs,
|
||||||
Keyword: keyword,
|
Keyword: keyword,
|
||||||
IsKeywordFuzzy: isFuzzy,
|
Mode: mode,
|
||||||
Language: language,
|
Language: language,
|
||||||
Filename: path,
|
Filename: path,
|
||||||
Paginator: &db.ListOptions{
|
Paginator: &db.ListOptions{
|
||||||
|
|
2
templates/swagger/v1_json.tmpl
generated
2
templates/swagger/v1_json.tmpl
generated
|
@ -4645,7 +4645,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "show only pubic, private or all repositories (defaults to all)",
|
"description": "show only public, private or all repositories (defaults to all)",
|
||||||
"name": "is_private",
|
"name": "is_private",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
},
|
},
|
||||||
|
|
|
@ -82,19 +82,10 @@ func testSearchRepo(t *testing.T, indexer bool) {
|
||||||
testSearch(t, "/user2/glob/search?q=loren&page=1", []string{"a.txt"}, indexer)
|
testSearch(t, "/user2/glob/search?q=loren&page=1", []string{"a.txt"}, indexer)
|
||||||
testSearch(t, "/user2/glob/search?q=loren&page=1&mode=exact", []string{"a.txt"}, indexer)
|
testSearch(t, "/user2/glob/search?q=loren&page=1&mode=exact", []string{"a.txt"}, indexer)
|
||||||
|
|
||||||
if indexer {
|
// union search: Union/OR of all the keywords
|
||||||
// fuzzy search: matches both file3 (x/b.txt) and file1 (a.txt)
|
|
||||||
// when indexer is enabled
|
|
||||||
testSearch(t, "/user2/glob/search?q=file3&mode=fuzzy&page=1", []string{"x/b.txt", "a.txt"}, indexer)
|
|
||||||
testSearch(t, "/user2/glob/search?q=file4&mode=fuzzy&page=1", []string{"x/b.txt", "a.txt"}, indexer)
|
|
||||||
testSearch(t, "/user2/glob/search?q=file5&mode=fuzzy&page=1", []string{"x/b.txt", "a.txt"}, indexer)
|
|
||||||
} else {
|
|
||||||
// fuzzy search: Union/OR of all the keywords
|
|
||||||
// when indexer is disabled
|
|
||||||
testSearch(t, "/user2/glob/search?q=file3+file1&mode=union&page=1", []string{"a.txt", "x/b.txt"}, indexer)
|
testSearch(t, "/user2/glob/search?q=file3+file1&mode=union&page=1", []string{"a.txt", "x/b.txt"}, indexer)
|
||||||
testSearch(t, "/user2/glob/search?q=file4&mode=union&page=1", []string{}, indexer)
|
testSearch(t, "/user2/glob/search?q=file4&mode=union&page=1", []string{}, indexer)
|
||||||
testSearch(t, "/user2/glob/search?q=file5&mode=union&page=1", []string{}, indexer)
|
testSearch(t, "/user2/glob/search?q=file5&mode=union&page=1", []string{}, indexer)
|
||||||
}
|
|
||||||
|
|
||||||
testSearch(t, "/user2/glob/search?q=file3&page=1&mode=exact", []string{"x/b.txt"}, indexer)
|
testSearch(t, "/user2/glob/search?q=file3&page=1&mode=exact", []string{"x/b.txt"}, indexer)
|
||||||
testSearch(t, "/user2/glob/search?q=file4&page=1&mode=exact", []string{}, indexer)
|
testSearch(t, "/user2/glob/search?q=file4&page=1&mode=exact", []string{}, indexer)
|
||||||
|
@ -121,11 +112,11 @@ func testSearch(t *testing.T, url string, expected []string, indexer bool) {
|
||||||
})
|
})
|
||||||
|
|
||||||
if indexer {
|
if indexer {
|
||||||
assert.EqualValues(t, []string{"exact", "fuzzy"}, dropdownOptions)
|
assert.EqualValues(t, []string{"exact", "union"}, dropdownOptions)
|
||||||
} else {
|
} else {
|
||||||
assert.EqualValues(t, []string{"exact", "union", "regexp"}, dropdownOptions)
|
assert.EqualValues(t, []string{"exact", "union", "regexp"}, dropdownOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
filenames := resultFilenames(t, doc)
|
filenames := resultFilenames(t, doc)
|
||||||
assert.EqualValues(t, expected, filenames)
|
assert.ElementsMatch(t, expected, filenames)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue