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