2019-02-19 22:39:39 +08:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-02-19 22:39:39 +08:00
|
|
|
|
|
|
|
package setting
|
|
|
|
|
|
|
|
import (
|
2023-03-29 10:23:23 +08:00
|
|
|
"net/url"
|
2019-02-19 22:39:39 +08:00
|
|
|
"path/filepath"
|
2019-09-12 01:26:28 +08:00
|
|
|
"strings"
|
2019-10-15 21:39:51 +08:00
|
|
|
"time"
|
2019-09-12 01:26:28 +08:00
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
2019-02-19 22:39:39 +08:00
|
|
|
)
|
|
|
|
|
2022-01-21 01:46:10 +08:00
|
|
|
// Indexer settings
|
|
|
|
var Indexer = struct {
|
|
|
|
IssueType string
|
|
|
|
IssuePath string
|
|
|
|
IssueConnStr string
|
2023-03-29 10:23:23 +08:00
|
|
|
IssueConnAuth string
|
2022-01-21 01:46:10 +08:00
|
|
|
IssueIndexerName string
|
|
|
|
StartupTimeout time.Duration
|
|
|
|
|
2023-05-25 16:13:47 +08:00
|
|
|
RepoIndexerEnabled bool
|
|
|
|
RepoIndexerRepoTypes []string
|
|
|
|
RepoType string
|
|
|
|
RepoPath string
|
|
|
|
RepoConnStr string
|
|
|
|
RepoIndexerName string
|
|
|
|
MaxIndexerFileSize int64
|
2024-05-03 17:13:48 +08:00
|
|
|
IncludePatterns []*GlobMatcher
|
|
|
|
ExcludePatterns []*GlobMatcher
|
2023-05-25 16:13:47 +08:00
|
|
|
ExcludeVendored bool
|
2022-01-21 01:46:10 +08:00
|
|
|
}{
|
|
|
|
IssueType: "bleve",
|
|
|
|
IssuePath: "indexers/issues.bleve",
|
|
|
|
IssueConnStr: "",
|
2023-03-29 10:23:23 +08:00
|
|
|
IssueConnAuth: "",
|
2022-01-21 01:46:10 +08:00
|
|
|
IssueIndexerName: "gitea_issues",
|
|
|
|
|
2023-05-25 16:13:47 +08:00
|
|
|
RepoIndexerEnabled: false,
|
|
|
|
RepoIndexerRepoTypes: []string{"sources", "forks", "mirrors", "templates"},
|
|
|
|
RepoType: "bleve",
|
|
|
|
RepoPath: "indexers/repos.bleve",
|
|
|
|
RepoConnStr: "",
|
|
|
|
RepoIndexerName: "gitea_codes",
|
|
|
|
MaxIndexerFileSize: 1024 * 1024,
|
|
|
|
ExcludeVendored: true,
|
2022-01-21 01:46:10 +08:00
|
|
|
}
|
2019-02-19 22:39:39 +08:00
|
|
|
|
2023-02-20 00:12:01 +08:00
|
|
|
func loadIndexerFrom(rootCfg ConfigProvider) {
|
|
|
|
sec := rootCfg.Section("indexer")
|
2019-02-21 13:01:28 +08:00
|
|
|
Indexer.IssueType = sec.Key("ISSUE_INDEXER_TYPE").MustString("bleve")
|
2024-02-09 22:06:03 +08:00
|
|
|
if Indexer.IssueType == "bleve" {
|
|
|
|
Indexer.IssuePath = filepath.ToSlash(sec.Key("ISSUE_INDEXER_PATH").MustString(filepath.ToSlash(filepath.Join(AppDataPath, "indexers/issues.bleve"))))
|
|
|
|
if !filepath.IsAbs(Indexer.IssuePath) {
|
|
|
|
Indexer.IssuePath = filepath.ToSlash(filepath.Join(AppWorkPath, Indexer.IssuePath))
|
|
|
|
}
|
2024-04-07 09:11:25 +08:00
|
|
|
checkOverlappedPath("[indexer].ISSUE_INDEXER_PATH", Indexer.IssuePath)
|
2024-02-09 22:06:03 +08:00
|
|
|
} else {
|
|
|
|
Indexer.IssueConnStr = sec.Key("ISSUE_INDEXER_CONN_STR").MustString(Indexer.IssueConnStr)
|
|
|
|
if Indexer.IssueType == "meilisearch" {
|
|
|
|
u, err := url.Parse(Indexer.IssueConnStr)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("Failed to parse ISSUE_INDEXER_CONN_STR: %v", err)
|
|
|
|
u = &url.URL{}
|
|
|
|
}
|
|
|
|
Indexer.IssueConnAuth, _ = u.User.Password()
|
|
|
|
u.User = nil
|
|
|
|
Indexer.IssueConnStr = u.String()
|
2023-03-29 10:23:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-13 14:06:17 +08:00
|
|
|
Indexer.IssueIndexerName = sec.Key("ISSUE_INDEXER_NAME").MustString(Indexer.IssueIndexerName)
|
|
|
|
|
2019-02-19 22:39:39 +08:00
|
|
|
Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
|
2023-05-25 16:13:47 +08:00
|
|
|
Indexer.RepoIndexerRepoTypes = strings.Split(sec.Key("REPO_INDEXER_REPO_TYPES").MustString("sources,forks,mirrors,templates"), ",")
|
2020-08-31 00:08:01 +08:00
|
|
|
Indexer.RepoType = sec.Key("REPO_INDEXER_TYPE").MustString("bleve")
|
2021-05-26 10:50:35 +08:00
|
|
|
Indexer.RepoPath = filepath.ToSlash(sec.Key("REPO_INDEXER_PATH").MustString(filepath.ToSlash(filepath.Join(AppDataPath, "indexers/repos.bleve"))))
|
2019-02-19 22:39:39 +08:00
|
|
|
if !filepath.IsAbs(Indexer.RepoPath) {
|
2021-05-26 10:50:35 +08:00
|
|
|
Indexer.RepoPath = filepath.ToSlash(filepath.Join(AppWorkPath, Indexer.RepoPath))
|
2019-02-19 22:39:39 +08:00
|
|
|
}
|
2020-08-31 00:08:01 +08:00
|
|
|
Indexer.RepoConnStr = sec.Key("REPO_INDEXER_CONN_STR").MustString("")
|
|
|
|
Indexer.RepoIndexerName = sec.Key("REPO_INDEXER_NAME").MustString("gitea_codes")
|
|
|
|
|
2019-09-12 01:26:28 +08:00
|
|
|
Indexer.IncludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_INCLUDE").MustString(""))
|
|
|
|
Indexer.ExcludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_EXCLUDE").MustString(""))
|
2020-02-21 03:53:55 +08:00
|
|
|
Indexer.ExcludeVendored = sec.Key("REPO_INDEXER_EXCLUDE_VENDORED").MustBool(true)
|
2019-02-19 22:39:39 +08:00
|
|
|
Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
|
2019-10-15 21:39:51 +08:00
|
|
|
Indexer.StartupTimeout = sec.Key("STARTUP_TIMEOUT").MustDuration(30 * time.Second)
|
2019-02-19 22:39:39 +08:00
|
|
|
}
|
2019-09-12 01:26:28 +08:00
|
|
|
|
|
|
|
// IndexerGlobFromString parses a comma separated list of patterns and returns a glob.Glob slice suited for repo indexing
|
2024-05-03 17:13:48 +08:00
|
|
|
func IndexerGlobFromString(globstr string) []*GlobMatcher {
|
|
|
|
extarr := make([]*GlobMatcher, 0, 10)
|
2019-09-12 01:26:28 +08:00
|
|
|
for _, expr := range strings.Split(strings.ToLower(globstr), ",") {
|
|
|
|
expr = strings.TrimSpace(expr)
|
|
|
|
if expr != "" {
|
2024-05-03 17:13:48 +08:00
|
|
|
if g, err := GlobMatcherCompile(expr, '.', '/'); err != nil {
|
2021-07-08 19:38:13 +08:00
|
|
|
log.Info("Invalid glob expression '%s' (skipped): %v", expr, err)
|
2019-09-12 01:26:28 +08:00
|
|
|
} else {
|
|
|
|
extarr = append(extarr, g)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return extarr
|
|
|
|
}
|