mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Storage buckets, indexer names, the bleve analyzer, the lock prefix, SSH host keys, the markdown front-matter key, the container data paths, the RPM repo id and the API security scheme all read as this product now, and app.example.ini matches the code again. The upstream maintainer list and the changelog generator config went with the release history they belonged to, and the citation comments state the fact rather than link the issue. Three inert rules turn out to have been inert because they named a module path this tree does not use: gci grouped no first-party imports under prefix(), and depguard let models/migrations import models and modules/structs. They now name github.com/hanzoai/git. The config example also documented .gitea/workflows while the code has read .hanzo/workflows for some time. The authorized_keys marker follows the delegate-hook precedent: the new name is written and the old one is still recognised, because a marker we do not know is copied through as a hand-added key and leaves a revoked key authorized. The stored user_setting key keeps its value; only a migration may change that. Co-authored-by: Hanzo Dev <[email protected]>
111 lines
3.9 KiB
Go
111 lines
3.9 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package setting
|
|
|
|
import (
|
|
"net/url"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/hanzoai/git/modules/log"
|
|
)
|
|
|
|
// Indexer settings
|
|
var Indexer = struct {
|
|
IssueType string
|
|
IssuePath string
|
|
IssueConnStr string
|
|
IssueConnAuth string
|
|
IssueIndexerName string
|
|
StartupTimeout time.Duration
|
|
|
|
RepoIndexerEnabled bool
|
|
RepoIndexerRepoTypes []string
|
|
RepoType string
|
|
RepoPath string
|
|
RepoConnStr string
|
|
RepoIndexerName string
|
|
MaxIndexerFileSize int64
|
|
IncludePatterns []*GlobMatcher
|
|
ExcludePatterns []*GlobMatcher
|
|
ExcludeVendored bool
|
|
|
|
TypeBleveMaxFuzzniess int
|
|
}{
|
|
IssueType: "bleve",
|
|
IssuePath: "indexers/issues.bleve",
|
|
IssueConnStr: "",
|
|
IssueConnAuth: "",
|
|
IssueIndexerName: "forge_issues",
|
|
|
|
RepoIndexerEnabled: false,
|
|
RepoIndexerRepoTypes: []string{"sources", "forks", "mirrors", "templates"},
|
|
RepoType: "bleve",
|
|
RepoPath: "indexers/repos.bleve",
|
|
RepoConnStr: "",
|
|
RepoIndexerName: "forge_codes",
|
|
MaxIndexerFileSize: 1024 * 1024,
|
|
ExcludeVendored: true,
|
|
}
|
|
|
|
func loadIndexerFrom(rootCfg ConfigProvider) {
|
|
sec := rootCfg.Section("indexer")
|
|
Indexer.IssueType = sec.Key("ISSUE_INDEXER_TYPE").MustString("bleve")
|
|
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))
|
|
}
|
|
checkOverlappedPath("[indexer].ISSUE_INDEXER_PATH", Indexer.IssuePath)
|
|
} 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()
|
|
}
|
|
}
|
|
|
|
Indexer.IssueIndexerName = sec.Key("ISSUE_INDEXER_NAME").MustString(Indexer.IssueIndexerName)
|
|
|
|
Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
|
|
Indexer.RepoIndexerRepoTypes = strings.Split(sec.Key("REPO_INDEXER_REPO_TYPES").MustString("sources,forks,mirrors,templates"), ",")
|
|
Indexer.RepoType = sec.Key("REPO_INDEXER_TYPE").MustString("bleve")
|
|
Indexer.RepoPath = filepath.ToSlash(sec.Key("REPO_INDEXER_PATH").MustString(filepath.ToSlash(filepath.Join(AppDataPath, "indexers/repos.bleve"))))
|
|
if !filepath.IsAbs(Indexer.RepoPath) {
|
|
Indexer.RepoPath = filepath.ToSlash(filepath.Join(AppWorkPath, Indexer.RepoPath))
|
|
}
|
|
Indexer.RepoConnStr = sec.Key("REPO_INDEXER_CONN_STR").MustString("")
|
|
Indexer.RepoIndexerName = sec.Key("REPO_INDEXER_NAME").MustString("forge_codes")
|
|
|
|
Indexer.IncludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_INCLUDE").MustString(""))
|
|
Indexer.ExcludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_EXCLUDE").MustString(""))
|
|
Indexer.ExcludeVendored = sec.Key("REPO_INDEXER_EXCLUDE_VENDORED").MustBool(true)
|
|
Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
|
|
Indexer.StartupTimeout = sec.Key("STARTUP_TIMEOUT").MustDuration(30 * time.Second)
|
|
Indexer.TypeBleveMaxFuzzniess = sec.Key("TYPE_BLEVE_MAX_FUZZINESS").MustInt(0)
|
|
}
|
|
|
|
// IndexerGlobFromString parses a comma separated list of patterns and returns a glob.Glob slice suited for repo indexing
|
|
func IndexerGlobFromString(globstr string) []*GlobMatcher {
|
|
extarr := make([]*GlobMatcher, 0, 10)
|
|
for expr := range strings.SplitSeq(strings.ToLower(globstr), ",") {
|
|
expr = strings.TrimSpace(expr)
|
|
if expr != "" {
|
|
if g, err := GlobMatcherCompile(expr, '.', '/'); err != nil {
|
|
log.Warn("Invalid glob expression '%s' (skipped): %v", expr, err)
|
|
} else {
|
|
extarr = append(extarr, g)
|
|
}
|
|
}
|
|
}
|
|
return extarr
|
|
}
|