feat: replace repo based server-side hooks with centralised hooks (#10397)

This PR is replacing repository based hooks hooks with centralised files, this way the files don't need to be copied into every repository, only one line of config need to be added in the repository.

Closes: #3523

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10397
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
Gabor Pihaj 2026-04-27 22:34:46 +02:00 committed by Gusted
commit 73b30acbd0
26 changed files with 419 additions and 440 deletions

View file

@ -47,10 +47,29 @@ func fatalTestError(fmtStr string, args ...any) {
// InitSettings initializes config provider and load common settings for tests
func InitSettings() {
if setting.CustomConf == "" {
setting.CustomConf = filepath.Join(setting.CustomPath, "conf/app-unittest-tmp.ini")
_ = os.Remove(setting.CustomConf)
InitCustomSettings("unittest.ini")
}
func InitCustomSettings(confFileName string) {
root := base.SetupGiteaRoot()
if root == "" {
fatalTestError("Environment variable $GITEA_ROOT not set")
}
setting.AppPath = filepath.Join(root, "gitea")
if setting.CustomConf == "" {
templateFile := confFileName + ".tmpl"
content, err := os.ReadFile(filepath.Join(root, "tests", templateFile))
if err != nil {
log.Fatalf("couldn't read config template: %s", templateFile)
}
err = os.WriteFile(filepath.Join(root, "tests", confFileName), content, 0o644)
if err != nil {
log.Fatalf("couldn't write config: %s", confFileName)
}
setting.CustomConf = filepath.Join(root, "tests", confFileName)
}
os.Setenv("GITEA_CONF", setting.CustomConf)
setting.InitCfgProvider(setting.CustomConf)
setting.LoadCommonSettings()
@ -72,9 +91,10 @@ func InitSettings() {
// TestOptions represents test options
type TestOptions struct {
FixtureFiles []string
SetUp func() error // SetUp will be executed before all tests in this package
TearDown func() error // TearDown will be executed after all tests in this package
FixtureFiles []string
SetUp func() error // SetUp will be executed before all tests in this package
TearDown func() error // TearDown will be executed after all tests in this package
IniFileOverride string
}
// MainTest a reusable TestMain(..) function for unit tests that need to use a
@ -97,7 +117,11 @@ func MainTest(m *testing.M, testOpts ...*TestOptions) {
giteaRoot = searchDir
setting.CustomPath = filepath.Join(giteaRoot, "custom")
InitSettings()
if len(testOpts) == 0 || testOpts[0].IniFileOverride == "" {
InitSettings()
} else {
InitCustomSettings(testOpts[0].IniFileOverride)
}
fixturesDir = filepath.Join(giteaRoot, "models", "fixtures")
var opts FixturesOptions