Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/go-core-fx/bunfx v0.0.2-0.20260409044649-8812f14d88ce
github.com/go-core-fx/config v0.1.0
github.com/go-core-fx/fiberfx v0.5.0
github.com/go-core-fx/fxutil v0.0.1
github.com/go-core-fx/goosefx v0.0.1
github.com/go-core-fx/healthfx v0.0.2-0.20260109013230-f7729a0a06bc
github.com/go-core-fx/logger v0.0.1
Expand All @@ -25,7 +26,7 @@ require (
github.com/uptrace/bun/dialect/mysqldialect v1.2.18
github.com/urfave/cli/v3 v3.8.0
go.uber.org/fx v1.24.0
go.uber.org/zap v1.27.1
go.uber.org/zap v1.28.0
golang.org/x/crypto v0.50.0
)

Expand All @@ -43,7 +44,6 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
github.com/go-core-fx/fxutil v0.0.0-20251027105421-acea37162eb9 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/go-core-fx/config v0.1.0 h1:uKmo+mTt5a8Gtusb7Xf4gkrGcLIbm2doTEUMkdd6o
github.com/go-core-fx/config v0.1.0/go.mod h1:gvoLaHr5fHfG5DlYYtNSPTqRlbnxWMqiWL4iWy2oezY=
github.com/go-core-fx/fiberfx v0.5.0 h1:e42gDP7R5k2T93pt1ibVS6nrnPNaGR/+6efHO90a398=
github.com/go-core-fx/fiberfx v0.5.0/go.mod h1:9MZcRCgYzqGLOpdnisW4+jQef8O9kcfaUKXAiAJZGTY=
github.com/go-core-fx/fxutil v0.0.0-20251027105421-acea37162eb9 h1:0rpJfg+QM3TAFCTignjzPovNkBHeEjOe+ILo+2Mz9aA=
github.com/go-core-fx/fxutil v0.0.0-20251027105421-acea37162eb9/go.mod h1:nljLWn+Ck1Rrqv9DPdD7Czdd0j5uF+9YRPNs/DpCfnw=
github.com/go-core-fx/fxutil v0.0.1 h1:A5pqeiTleSw4vDxhVh38uXkt8IPhCEEFpvb5kZJfHvo=
github.com/go-core-fx/fxutil v0.0.1/go.mod h1:nljLWn+Ck1Rrqv9DPdD7Czdd0j5uF+9YRPNs/DpCfnw=
github.com/go-core-fx/goosefx v0.0.1 h1:R5JsN44HMjsacqJe5VX38Acr+tFsfDUfxSxyBhoK9h4=
github.com/go-core-fx/goosefx v0.0.1/go.mod h1:C4Xw9ea44//B3JEpWmZ7MbeMrHOnWWLBGa182STrkXo=
github.com/go-core-fx/healthfx v0.0.2-0.20260109013230-f7729a0a06bc h1:jJTE0YeQwyqsr9qhvKZxDmxoR322tBZjvwFjQTauM84=
Expand Down Expand Up @@ -228,8 +228,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.uber.org/zap v1.28.0 h1:IZzaP1Fv73/T/pBMLk4VutPl36uNC+OSUh3JLG3FIjo=
go.uber.org/zap v1.28.0/go.mod h1:rDLpOi171uODNm/mxFcuYWxDsqWSAVkFdX4XojSKg/Q=
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
Expand Down
15 changes: 1 addition & 14 deletions internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package internal

import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
Expand All @@ -21,19 +20,7 @@ func Run(version healthfx.Version) {
Version: version.Version,
DefaultCommand: "serve",
Flags: []cli.Flag{},
Commands: []*cli.Command{
{
Name: "serve",
Usage: "Start the HTTP server",
Description: `Start the HTTP server`,
Action: func(ctx context.Context, _ *cli.Command) error {
if err := commands.Serve(ctx, version); err != nil {
return fmt.Errorf("serve: %w", err)
}
return nil
},
},
},
Commands: commands.Commands(version),
}

ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
Expand Down
15 changes: 15 additions & 0 deletions internal/commands/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package commands

import (
"github.com/bit-issues/backend/internal/commands/importer"
"github.com/bit-issues/backend/internal/commands/serve"
"github.com/go-core-fx/healthfx"
"github.com/urfave/cli/v3"
)

func Commands(version healthfx.Version) []*cli.Command {
return []*cli.Command{
serve.Command(version),
importer.Command(version),
}
}
45 changes: 45 additions & 0 deletions internal/commands/importer/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package importer

import "github.com/urfave/cli/v3"

type Config struct {
Filename string

ProjectSlug string
DefaultUser string
DryRun bool
}

func (c *Config) Flags() []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "project",
Usage: "Target project slug (required)",
Required: true,
},
&cli.StringFlag{
Name: "file",
Usage: "Path to the JSON file (required)",
Required: true,
},
&cli.StringFlag{
Name: "default-user",
Usage: "Default user ID or slug for unmapped authors (required)",
Required: true,
},
&cli.BoolFlag{
Name: "dry-run",
Usage: "Simulate import without writing to database",
Value: false,
},
}
}

func parseConfig(cmd *cli.Command) Config {
return Config{
Filename: cmd.String("file"),
ProjectSlug: cmd.String("project"),
DefaultUser: cmd.String("default-user"),
DryRun: cmd.Bool("dry-run"),
}
}
97 changes: 97 additions & 0 deletions internal/commands/importer/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package importer

import (
"context"
"errors"
"fmt"

"github.com/bit-issues/backend/internal/attachments"
"github.com/bit-issues/backend/internal/comments"
"github.com/bit-issues/backend/internal/config"
"github.com/bit-issues/backend/internal/db"
"github.com/bit-issues/backend/internal/projects"
"github.com/bit-issues/backend/internal/storage"
"github.com/bit-issues/backend/internal/tasks"
"github.com/bit-issues/backend/internal/users"
"github.com/go-core-fx/bunfx"
"github.com/go-core-fx/fxutil"
"github.com/go-core-fx/healthfx"
"github.com/go-core-fx/logger"
"github.com/go-core-fx/sqlfx"
"github.com/urfave/cli/v3"
"go.uber.org/fx"
)

func Command(_ healthfx.Version) *cli.Command {
return &cli.Command{
Name: "import",
Usage: "Import issues from a JSON file",
Description: `Import issues from a BitBucket export JSON file into a specified project`,
Flags: (*Config)(nil).Flags(),
Action: run,
}
}

// ImportResult holds the results of an import operation.
type ImportResult struct {
IssuesImported int
IssuesSkipped int
CommentsImported int
CommentsSkipped int
}

// run imports issues from a BitBucket export JSON file.
func run(ctx context.Context, cmd *cli.Command) error {
// Run the import within an FX app
app := fx.New(
logger.Module(),
logger.WithFxDefaultLogger(),
bunfx.Module(),
sqlfx.Module(),

config.Module(),
db.Module(),
storage.Module(),

users.Module(),
projects.Module(),
tasks.Module(),
attachments.Module(),
comments.Module(),

fx.Supply(parseConfig(cmd)),

fx.Provide(newImporter),
fx.Invoke(fxutil.RegisterRunnable[*importer]()),
)

startCtx, cancelStart := context.WithTimeout(ctx, app.StartTimeout())
defer cancelStart()

if startErr := app.Start(startCtx); startErr != nil {
return fmt.Errorf("failed to start app: %w", startErr)
}

var runErr error
select {
case <-ctx.Done():
runErr = ctx.Err()
case sig := <-app.Wait():
if sig.ExitCode != 0 {
runErr = cli.Exit("app exited with non-zero status code", sig.ExitCode)
}
}

stopCtx, cancelStop := context.WithTimeout(context.Background(), app.StopTimeout())
defer cancelStop()

if stopErr := app.Stop(stopCtx); stopErr != nil {
return fmt.Errorf("failed to stop app: %w", stopErr)
}

if runErr != nil && !errors.Is(runErr, context.Canceled) {
return fmt.Errorf("import failed: %w", runErr)
}

return nil
}
Comment thread
capcom6 marked this conversation as resolved.
Loading
Loading