-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a735362
commit 4d5fddb
Showing
195 changed files
with
549 additions
and
975 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
|
||
"github.com/charmbracelet/soft-serve/pkg/backend" | ||
"github.com/charmbracelet/soft-serve/pkg/config" | ||
"github.com/charmbracelet/soft-serve/pkg/db" | ||
"github.com/charmbracelet/soft-serve/pkg/hooks" | ||
"github.com/charmbracelet/soft-serve/pkg/store" | ||
"github.com/charmbracelet/soft-serve/pkg/store/database" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func InitBackendContext(cmd *cobra.Command, _ []string) error { | ||
ctx := cmd.Context() | ||
cfg := config.FromContext(ctx) | ||
if _, err := os.Stat(cfg.DataPath); errors.Is(err, fs.ErrNotExist) { | ||
if err := os.MkdirAll(cfg.DataPath, os.ModePerm); err != nil { | ||
return fmt.Errorf("create data directory: %w", err) | ||
} | ||
} | ||
dbx, err := db.Open(ctx, cfg.DB.Driver, cfg.DB.DataSource) | ||
if err != nil { | ||
return fmt.Errorf("open database: %w", err) | ||
} | ||
|
||
ctx = db.WithContext(ctx, dbx) | ||
dbstore := database.New(ctx, dbx) | ||
ctx = store.WithContext(ctx, dbstore) | ||
be := backend.New(ctx, cfg, dbx) | ||
ctx = backend.WithContext(ctx, be) | ||
|
||
cmd.SetContext(ctx) | ||
|
||
return nil | ||
} | ||
|
||
func CloseDBContext(cmd *cobra.Command, _ []string) error { | ||
ctx := cmd.Context() | ||
dbx := db.FromContext(ctx) | ||
if dbx != nil { | ||
if err := dbx.Close(); err != nil { | ||
return fmt.Errorf("close database: %w", err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func InitializeHooks(ctx context.Context, cfg *config.Config, be *backend.Backend) error { | ||
repos, err := be.Repositories(ctx) | ||
if err != nil { | ||
return err | ||
Check failure on line 58 in cmd/cmd.go GitHub Actions / lint-soft
|
||
} | ||
|
||
for _, repo := range repos { | ||
if err := hooks.GenerateHooks(ctx, cfg, repo.Name()); err != nil { | ||
return err | ||
Check failure on line 63 in cmd/cmd.go GitHub Actions / lint-soft
|
||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.