summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorEarl Warren <contact@earl-warren.org>2024-01-23 10:43:29 +0100
committerEarl Warren <contact@earl-warren.org>2024-06-14 12:52:12 +0200
commite99d3f7055e7a2495c4f6916e6ae0aff4598bd26 (patch)
tree89877d53dca486095c6dd9f3f4a9faf4c6100cf6 /cmd
parentMerge pull request 'Fix default values for ui.meta settings in app.example.in... (diff)
downloadforgejo-e99d3f7055e7a2495c4f6916e6ae0aff4598bd26.tar.xz
forgejo-e99d3f7055e7a2495c4f6916e6ae0aff4598bd26.zip
feat(F3): CLI: f3 mirror to convert to/from Forgejo
feat(F3): driver stub feat(F3): util.Logger feat(F3): driver compliance tests feat(F3): driver/users implementation feat(F3): driver/user implementation feat(F3): driver/{projects,project} implementation feat(F3): driver/{labels,label} implementation feat(F3): driver/{milestones,milestone} implementation feat(F3): driver/{repositories,repository} implementation feat(F3): driver/{organizations,organization} implementation feat(F3): driver/{releases,release} implementation feat(F3): driver/{issues,issue} implementation feat(F3): driver/{comments,comment} implementation feat(F3): driver/{assets,asset} implementation feat(F3): driver/{pullrequests,pullrequest} implementation feat(F3): driver/{reviews,review} implementation feat(F3): driver/{topics,topic} implementation feat(F3): driver/{reactions,reaction} implementation feat(F3): driver/{reviewComments,reviewComment} implementation feat(F3): CLI: f3 mirror chore(F3): move to code.forgejo.org feat(f3): upgrade to gof3 3.1.0 repositories in pull requests are represented with a reference instead of an owner/project pair of names
Diffstat (limited to 'cmd')
-rw-r--r--cmd/forgejo/actions.go2
-rw-r--r--cmd/forgejo/f3.go70
-rw-r--r--cmd/forgejo/forgejo.go1
-rw-r--r--cmd/main.go15
4 files changed, 85 insertions, 3 deletions
diff --git a/cmd/forgejo/actions.go b/cmd/forgejo/actions.go
index fc6b5f70f7..70f9452cb8 100644
--- a/cmd/forgejo/actions.go
+++ b/cmd/forgejo/actions.go
@@ -134,8 +134,8 @@ func validateSecret(secret string) error {
}
func RunRegister(ctx context.Context, cliCtx *cli.Context) error {
+ var cancel context.CancelFunc
if !ContextGetNoInit(ctx) {
- var cancel context.CancelFunc
ctx, cancel = installSignals(ctx)
defer cancel()
diff --git a/cmd/forgejo/f3.go b/cmd/forgejo/f3.go
new file mode 100644
index 0000000000..574c776ded
--- /dev/null
+++ b/cmd/forgejo/f3.go
@@ -0,0 +1,70 @@
+// Copyright Earl Warren <contact@earl-warren.org>
+// Copyright Loïc Dachary <loic@dachary.org>
+// SPDX-License-Identifier: MIT
+
+package forgejo
+
+import (
+ "context"
+
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/storage"
+ "code.gitea.io/gitea/services/f3/util"
+
+ _ "code.gitea.io/gitea/services/f3/driver" // register the driver
+
+ f3_cmd "code.forgejo.org/f3/gof3/v3/cmd"
+ f3_logger "code.forgejo.org/f3/gof3/v3/logger"
+ f3_util "code.forgejo.org/f3/gof3/v3/util"
+ "github.com/urfave/cli/v2"
+)
+
+func CmdF3(ctx context.Context) *cli.Command {
+ ctx = f3_logger.ContextSetLogger(ctx, util.NewF3Logger(nil, log.GetLogger(log.DEFAULT)))
+ return &cli.Command{
+ Name: "f3",
+ Usage: "F3",
+ Subcommands: []*cli.Command{
+ SubcmdF3Mirror(ctx),
+ },
+ }
+}
+
+func SubcmdF3Mirror(ctx context.Context) *cli.Command {
+ mirrorCmd := f3_cmd.CreateCmdMirror(ctx)
+ mirrorCmd.Before = prepareWorkPathAndCustomConf(ctx)
+ f3Action := mirrorCmd.Action
+ mirrorCmd.Action = func(c *cli.Context) error { return runMirror(ctx, c, f3Action) }
+ return mirrorCmd
+}
+
+func runMirror(ctx context.Context, c *cli.Context, action cli.ActionFunc) error {
+ var cancel context.CancelFunc
+ if !ContextGetNoInit(ctx) {
+ ctx, cancel = installSignals(ctx)
+ defer cancel()
+
+ if err := initDB(ctx); err != nil {
+ return err
+ }
+
+ if err := storage.Init(); err != nil {
+ return err
+ }
+
+ if err := git.InitSimple(ctx); err != nil {
+ return err
+ }
+ if err := models.Init(ctx); err != nil {
+ return err
+ }
+ }
+
+ err := action(c)
+ if panicError, ok := err.(f3_util.PanicError); ok {
+ log.Debug("F3 Stack trace\n%s", panicError.Stack())
+ }
+ return err
+}
diff --git a/cmd/forgejo/forgejo.go b/cmd/forgejo/forgejo.go
index 710996e1c0..1b7e16ca8f 100644
--- a/cmd/forgejo/forgejo.go
+++ b/cmd/forgejo/forgejo.go
@@ -36,6 +36,7 @@ func CmdForgejo(ctx context.Context) *cli.Command {
Flags: []cli.Flag{},
Subcommands: []*cli.Command{
CmdActions(ctx),
+ CmdF3(ctx),
},
}
}
diff --git a/cmd/main.go b/cmd/main.go
index 6e3d46cc35..b48a6143d7 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -124,6 +124,7 @@ func NewMainApp(version, versionExtra string) *cli.App {
var subCmdsStandalone []*cli.Command = make([]*cli.Command, 0, 10)
var subCmdWithConfig []*cli.Command = make([]*cli.Command, 0, 10)
+ var globalFlags []cli.Flag = make([]cli.Flag, 0, 10)
//
// If the executable is forgejo-cli, provide a Forgejo specific CLI
@@ -131,6 +132,15 @@ func NewMainApp(version, versionExtra string) *cli.App {
//
if executable == "forgejo-cli" {
subCmdsStandalone = append(subCmdsStandalone, forgejo.CmdActions(context.Background()))
+ subCmdWithConfig = append(subCmdWithConfig, forgejo.CmdF3(context.Background()))
+ globalFlags = append(globalFlags, []cli.Flag{
+ &cli.BoolFlag{
+ Name: "quiet",
+ },
+ &cli.BoolFlag{
+ Name: "verbose",
+ },
+ }...)
} else {
//
// Otherwise provide a Gitea compatible CLI which includes Forgejo
@@ -142,10 +152,10 @@ func NewMainApp(version, versionExtra string) *cli.App {
subCmdWithConfig = append(subCmdWithConfig, CmdActions)
}
- return innerNewMainApp(version, versionExtra, subCmdsStandalone, subCmdWithConfig)
+ return innerNewMainApp(version, versionExtra, subCmdsStandalone, subCmdWithConfig, globalFlags)
}
-func innerNewMainApp(version, versionExtra string, subCmdsStandaloneArgs, subCmdWithConfigArgs []*cli.Command) *cli.App {
+func innerNewMainApp(version, versionExtra string, subCmdsStandaloneArgs, subCmdWithConfigArgs []*cli.Command, globalFlagsArgs []cli.Flag) *cli.App {
app := cli.NewApp()
app.HelpName = "forgejo"
app.Name = "Forgejo"
@@ -185,6 +195,7 @@ func innerNewMainApp(version, versionExtra string, subCmdsStandaloneArgs, subCmd
app.DefaultCommand = CmdWeb.Name
globalFlags := appGlobalFlags()
+ globalFlags = append(globalFlags, globalFlagsArgs...)
app.Flags = append(app.Flags, cli.VersionFlag)
app.Flags = append(app.Flags, globalFlags...)
app.HideHelp = true // use our own help action to show helps (with more information like default config)