mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-24 13:56:57 +00:00
rename gitea to forge for cli and add gitea options as aliases
This commit is contained in:
parent
9ce901bfa0
commit
5cac5e105c
6 changed files with 73 additions and 44 deletions
24
cli/flags.go
24
cli/flags.go
|
@ -22,29 +22,31 @@ var (
|
||||||
|
|
||||||
ServerFlags = append(CertStorageFlags, []cli.Flag{
|
ServerFlags = append(CertStorageFlags, []cli.Flag{
|
||||||
// #############
|
// #############
|
||||||
// ### Gitea ###
|
// ### Forge ###
|
||||||
// #############
|
// #############
|
||||||
// GiteaRoot specifies the root URL of the Gitea instance, without a trailing slash.
|
// ForgeRoot specifies the root URL of the Forge instance, without a trailing slash.
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "gitea-root",
|
Name: "forge-root",
|
||||||
Usage: "specifies the root URL of the Gitea instance, without a trailing slash.",
|
Aliases: []string{"gitea-root"},
|
||||||
EnvVars: []string{"GITEA_ROOT"},
|
Usage: "specifies the root URL of the Forgejo/Gitea instance, without a trailing slash.",
|
||||||
|
EnvVars: []string{"FORGE_ROOT", "GITEA_ROOT"},
|
||||||
},
|
},
|
||||||
// GiteaApiToken specifies an api token for the Gitea instance
|
// ForgeApiToken specifies an api token for the Forge instance
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "gitea-api-token",
|
Name: "forge-api-token",
|
||||||
Usage: "specifies an api token for the Gitea instance",
|
Aliases: []string{"gitea-api-token"},
|
||||||
EnvVars: []string{"GITEA_API_TOKEN"},
|
Usage: "specifies an api token for the Forgejo/Gitea instance",
|
||||||
|
EnvVars: []string{"FORGE_API_TOKEN", "GITEA_API_TOKEN"},
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "enable-lfs-support",
|
Name: "enable-lfs-support",
|
||||||
Usage: "enable lfs support, require gitea >= v1.17.0 as backend",
|
Usage: "enable lfs support, gitea must be version v1.17.0 or higher",
|
||||||
EnvVars: []string{"ENABLE_LFS_SUPPORT"},
|
EnvVars: []string{"ENABLE_LFS_SUPPORT"},
|
||||||
Value: false,
|
Value: false,
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "enable-symlink-support",
|
Name: "enable-symlink-support",
|
||||||
Usage: "follow symlinks if enabled, require gitea >= v1.18.0 as backend",
|
Usage: "follow symlinks if enabled, gitea must be version v1.18.0 or higher",
|
||||||
EnvVars: []string{"ENABLE_SYMLINK_SUPPORT"},
|
EnvVars: []string{"ENABLE_SYMLINK_SUPPORT"},
|
||||||
Value: false,
|
Value: false,
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,7 +3,7 @@ package config
|
||||||
type Config struct {
|
type Config struct {
|
||||||
LogLevel string `default:"warn"`
|
LogLevel string `default:"warn"`
|
||||||
Server ServerConfig
|
Server ServerConfig
|
||||||
Gitea GiteaConfig
|
Forge ForgeConfig
|
||||||
Database DatabaseConfig
|
Database DatabaseConfig
|
||||||
ACME ACMEConfig
|
ACME ACMEConfig
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ type ServerConfig struct {
|
||||||
BlacklistedPaths []string
|
BlacklistedPaths []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type GiteaConfig struct {
|
type ForgeConfig struct {
|
||||||
Root string
|
Root string
|
||||||
Token string
|
Token string
|
||||||
LFSEnabled bool `default:"false"`
|
LFSEnabled bool `default:"false"`
|
||||||
|
|
|
@ -51,7 +51,7 @@ func MergeConfig(ctx *cli.Context, config *Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeServerConfig(ctx, &config.Server)
|
mergeServerConfig(ctx, &config.Server)
|
||||||
mergeGiteaConfig(ctx, &config.Gitea)
|
mergeForgeConfig(ctx, &config.Forge)
|
||||||
mergeDatabaseConfig(ctx, &config.Database)
|
mergeDatabaseConfig(ctx, &config.Database)
|
||||||
mergeACMEConfig(ctx, &config.ACME)
|
mergeACMEConfig(ctx, &config.ACME)
|
||||||
}
|
}
|
||||||
|
@ -89,12 +89,12 @@ func mergeServerConfig(ctx *cli.Context, config *ServerConfig) {
|
||||||
config.BlacklistedPaths = append(config.BlacklistedPaths, ALWAYS_BLACKLISTED_PATHS...)
|
config.BlacklistedPaths = append(config.BlacklistedPaths, ALWAYS_BLACKLISTED_PATHS...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeGiteaConfig(ctx *cli.Context, config *GiteaConfig) {
|
func mergeForgeConfig(ctx *cli.Context, config *ForgeConfig) {
|
||||||
if ctx.IsSet("gitea-root") {
|
if ctx.IsSet("forge-root") {
|
||||||
config.Root = ctx.String("gitea-root")
|
config.Root = ctx.String("forge-root")
|
||||||
}
|
}
|
||||||
if ctx.IsSet("gitea-api-token") {
|
if ctx.IsSet("forge-api-token") {
|
||||||
config.Token = ctx.String("gitea-api-token")
|
config.Token = ctx.String("forge-api-token")
|
||||||
}
|
}
|
||||||
if ctx.IsSet("enable-lfs-support") {
|
if ctx.IsSet("enable-lfs-support") {
|
||||||
config.LFSEnabled = ctx.Bool("enable-lfs-support")
|
config.LFSEnabled = ctx.Bool("enable-lfs-support")
|
||||||
|
|
|
@ -110,7 +110,7 @@ func TestValuesReadFromConfigFileShouldBeOverwrittenByArgs(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedConfig.LogLevel = "debug"
|
expectedConfig.LogLevel = "debug"
|
||||||
expectedConfig.Gitea.Root = "not-codeberg.org"
|
expectedConfig.Forge.Root = "not-codeberg.org"
|
||||||
expectedConfig.ACME.AcceptTerms = true
|
expectedConfig.ACME.AcceptTerms = true
|
||||||
expectedConfig.Server.Host = "172.17.0.2"
|
expectedConfig.Server.Host = "172.17.0.2"
|
||||||
expectedConfig.Server.BlacklistedPaths = append(expectedConfig.Server.BlacklistedPaths, ALWAYS_BLACKLISTED_PATHS...)
|
expectedConfig.Server.BlacklistedPaths = append(expectedConfig.Server.BlacklistedPaths, ALWAYS_BLACKLISTED_PATHS...)
|
||||||
|
@ -122,7 +122,7 @@ func TestValuesReadFromConfigFileShouldBeOverwrittenByArgs(t *testing.T) {
|
||||||
[]string{
|
[]string{
|
||||||
"--config-file", "assets/test_config.toml",
|
"--config-file", "assets/test_config.toml",
|
||||||
"--log-level", "debug",
|
"--log-level", "debug",
|
||||||
"--gitea-root", "not-codeberg.org",
|
"--forge-root", "not-codeberg.org",
|
||||||
"--acme-accept-terms",
|
"--acme-accept-terms",
|
||||||
"--host", "172.17.0.2",
|
"--host", "172.17.0.2",
|
||||||
},
|
},
|
||||||
|
@ -146,7 +146,7 @@ func TestMergeConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T
|
||||||
AllowedCorsDomains: []string{"original"},
|
AllowedCorsDomains: []string{"original"},
|
||||||
BlacklistedPaths: []string{"original"},
|
BlacklistedPaths: []string{"original"},
|
||||||
},
|
},
|
||||||
Gitea: GiteaConfig{
|
Forge: ForgeConfig{
|
||||||
Root: "original",
|
Root: "original",
|
||||||
Token: "original",
|
Token: "original",
|
||||||
LFSEnabled: false,
|
LFSEnabled: false,
|
||||||
|
@ -186,7 +186,7 @@ func TestMergeConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T
|
||||||
AllowedCorsDomains: []string{"changed"},
|
AllowedCorsDomains: []string{"changed"},
|
||||||
BlacklistedPaths: append([]string{"changed"}, ALWAYS_BLACKLISTED_PATHS...),
|
BlacklistedPaths: append([]string{"changed"}, ALWAYS_BLACKLISTED_PATHS...),
|
||||||
},
|
},
|
||||||
Gitea: GiteaConfig{
|
Forge: ForgeConfig{
|
||||||
Root: "changed",
|
Root: "changed",
|
||||||
Token: "changed",
|
Token: "changed",
|
||||||
LFSEnabled: true,
|
LFSEnabled: true,
|
||||||
|
@ -227,9 +227,9 @@ func TestMergeConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T
|
||||||
"--port", "8443",
|
"--port", "8443",
|
||||||
"--http-port", "443",
|
"--http-port", "443",
|
||||||
"--enable-http-server",
|
"--enable-http-server",
|
||||||
// Gitea
|
// Forge
|
||||||
"--gitea-root", "changed",
|
"--forge-root", "changed",
|
||||||
"--gitea-api-token", "changed",
|
"--forge-api-token", "changed",
|
||||||
"--enable-lfs-support",
|
"--enable-lfs-support",
|
||||||
"--enable-symlink-support",
|
"--enable-symlink-support",
|
||||||
"--default-mime-type", "changed",
|
"--default-mime-type", "changed",
|
||||||
|
@ -366,11 +366,11 @@ func TestMergeServerConfigShouldReplaceOnlyOneValueExistingValueGivenOnlyOneArgE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeGiteaConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T) {
|
func TestMergeForgeConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T) {
|
||||||
runApp(
|
runApp(
|
||||||
t,
|
t,
|
||||||
func(ctx *cli.Context) error {
|
func(ctx *cli.Context) error {
|
||||||
cfg := &GiteaConfig{
|
cfg := &ForgeConfig{
|
||||||
Root: "original",
|
Root: "original",
|
||||||
Token: "original",
|
Token: "original",
|
||||||
LFSEnabled: false,
|
LFSEnabled: false,
|
||||||
|
@ -379,9 +379,9 @@ func TestMergeGiteaConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *test
|
||||||
ForbiddenMimeTypes: []string{"original"},
|
ForbiddenMimeTypes: []string{"original"},
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeGiteaConfig(ctx, cfg)
|
mergeForgeConfig(ctx, cfg)
|
||||||
|
|
||||||
expectedConfig := &GiteaConfig{
|
expectedConfig := &ForgeConfig{
|
||||||
Root: "changed",
|
Root: "changed",
|
||||||
Token: "changed",
|
Token: "changed",
|
||||||
LFSEnabled: true,
|
LFSEnabled: true,
|
||||||
|
@ -395,8 +395,8 @@ func TestMergeGiteaConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *test
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
"--gitea-root", "changed",
|
"--forge-root", "changed",
|
||||||
"--gitea-api-token", "changed",
|
"--forge-api-token", "changed",
|
||||||
"--enable-lfs-support",
|
"--enable-lfs-support",
|
||||||
"--enable-symlink-support",
|
"--enable-symlink-support",
|
||||||
"--default-mime-type", "changed",
|
"--default-mime-type", "changed",
|
||||||
|
@ -405,25 +405,25 @@ func TestMergeGiteaConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *test
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeGiteaConfigShouldReplaceOnlyOneValueExistingValueGivenOnlyOneArgExists(t *testing.T) {
|
func TestMergeForgeConfigShouldReplaceOnlyOneValueExistingValueGivenOnlyOneArgExists(t *testing.T) {
|
||||||
type testValuePair struct {
|
type testValuePair struct {
|
||||||
args []string
|
args []string
|
||||||
callback func(*GiteaConfig)
|
callback func(*ForgeConfig)
|
||||||
}
|
}
|
||||||
testValuePairs := []testValuePair{
|
testValuePairs := []testValuePair{
|
||||||
{args: []string{"--gitea-root", "changed"}, callback: func(gc *GiteaConfig) { gc.Root = "changed" }},
|
{args: []string{"--forge-root", "changed"}, callback: func(gc *ForgeConfig) { gc.Root = "changed" }},
|
||||||
{args: []string{"--gitea-api-token", "changed"}, callback: func(gc *GiteaConfig) { gc.Token = "changed" }},
|
{args: []string{"--forge-api-token", "changed"}, callback: func(gc *ForgeConfig) { gc.Token = "changed" }},
|
||||||
{args: []string{"--enable-lfs-support"}, callback: func(gc *GiteaConfig) { gc.LFSEnabled = true }},
|
{args: []string{"--enable-lfs-support"}, callback: func(gc *ForgeConfig) { gc.LFSEnabled = true }},
|
||||||
{args: []string{"--enable-symlink-support"}, callback: func(gc *GiteaConfig) { gc.FollowSymlinks = true }},
|
{args: []string{"--enable-symlink-support"}, callback: func(gc *ForgeConfig) { gc.FollowSymlinks = true }},
|
||||||
{args: []string{"--default-mime-type", "changed"}, callback: func(gc *GiteaConfig) { gc.DefaultMimeType = "changed" }},
|
{args: []string{"--default-mime-type", "changed"}, callback: func(gc *ForgeConfig) { gc.DefaultMimeType = "changed" }},
|
||||||
{args: []string{"--forbidden-mime-types", "changed"}, callback: func(gc *GiteaConfig) { gc.ForbiddenMimeTypes = []string{"changed"} }},
|
{args: []string{"--forbidden-mime-types", "changed"}, callback: func(gc *ForgeConfig) { gc.ForbiddenMimeTypes = []string{"changed"} }},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pair := range testValuePairs {
|
for _, pair := range testValuePairs {
|
||||||
runApp(
|
runApp(
|
||||||
t,
|
t,
|
||||||
func(ctx *cli.Context) error {
|
func(ctx *cli.Context) error {
|
||||||
cfg := GiteaConfig{
|
cfg := ForgeConfig{
|
||||||
Root: "original",
|
Root: "original",
|
||||||
Token: "original",
|
Token: "original",
|
||||||
LFSEnabled: false,
|
LFSEnabled: false,
|
||||||
|
@ -435,7 +435,7 @@ func TestMergeGiteaConfigShouldReplaceOnlyOneValueExistingValueGivenOnlyOneArgEx
|
||||||
expectedConfig := cfg
|
expectedConfig := cfg
|
||||||
pair.callback(&expectedConfig)
|
pair.callback(&expectedConfig)
|
||||||
|
|
||||||
mergeGiteaConfig(ctx, &cfg)
|
mergeForgeConfig(ctx, &cfg)
|
||||||
|
|
||||||
expectedConfig.ForbiddenMimeTypes = fixArrayFromCtx(ctx, "forbidden-mime-types", expectedConfig.ForbiddenMimeTypes)
|
expectedConfig.ForbiddenMimeTypes = fixArrayFromCtx(ctx, "forbidden-mime-types", expectedConfig.ForbiddenMimeTypes)
|
||||||
|
|
||||||
|
@ -448,6 +448,33 @@ func TestMergeGiteaConfigShouldReplaceOnlyOneValueExistingValueGivenOnlyOneArgEx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMergeForgeConfigShouldReplaceValuesGivenGiteaOptionsExist(t *testing.T) {
|
||||||
|
runApp(
|
||||||
|
t,
|
||||||
|
func(ctx *cli.Context) error {
|
||||||
|
cfg := &ForgeConfig{
|
||||||
|
Root: "original",
|
||||||
|
Token: "original",
|
||||||
|
}
|
||||||
|
|
||||||
|
mergeForgeConfig(ctx, cfg)
|
||||||
|
|
||||||
|
expectedConfig := &ForgeConfig{
|
||||||
|
Root: "changed",
|
||||||
|
Token: "changed",
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, expectedConfig, cfg)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
[]string{
|
||||||
|
"--gitea-root", "changed",
|
||||||
|
"--gitea-api-token", "changed",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func TestMergeDatabaseConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T) {
|
func TestMergeDatabaseConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T) {
|
||||||
runApp(
|
runApp(
|
||||||
t,
|
t,
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHandlerPerformance(t *testing.T) {
|
func TestHandlerPerformance(t *testing.T) {
|
||||||
cfg := config.GiteaConfig{
|
cfg := config.ForgeConfig{
|
||||||
Root: "https://codeberg.org",
|
Root: "https://codeberg.org",
|
||||||
Token: "",
|
Token: "",
|
||||||
LFSEnabled: false,
|
LFSEnabled: false,
|
||||||
|
|
|
@ -77,7 +77,7 @@ func Serve(ctx *cli.Context) error {
|
||||||
// clientResponseCache stores responses from the Gitea server
|
// clientResponseCache stores responses from the Gitea server
|
||||||
clientResponseCache := cache.NewInMemoryCache()
|
clientResponseCache := cache.NewInMemoryCache()
|
||||||
|
|
||||||
giteaClient, err := gitea.NewClient(cfg.Gitea, clientResponseCache)
|
giteaClient, err := gitea.NewClient(cfg.Forge, clientResponseCache)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create new gitea client: %v", err)
|
return fmt.Errorf("could not create new gitea client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue