From c7829a3e9d40a3111930e4620290482e1b2ec4d1 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 3 Aug 2023 12:14:34 -0400 Subject: [PATCH] feat: print clone url on repo create Prints the repo ssh clone url on create Fixes: https://github.com/charmbracelet/soft-serve/issues/297 --- server/ssh/cmd/create.go | 14 ++++++++++++-- testscript/script_test.go | 3 +-- testscript/testdata/repo-create.txtar | 4 ++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/server/ssh/cmd/create.go b/server/ssh/cmd/create.go index 7e301b3fd..545470ff5 100644 --- a/server/ssh/cmd/create.go +++ b/server/ssh/cmd/create.go @@ -1,7 +1,10 @@ package cmd import ( + "fmt" + "github.com/charmbracelet/soft-serve/server/backend" + "github.com/charmbracelet/soft-serve/server/config" "github.com/charmbracelet/soft-serve/server/proto" "github.com/spf13/cobra" ) @@ -20,17 +23,24 @@ func createCommand() *cobra.Command { PersistentPreRunE: checkIfCollab, RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() + cfg := config.FromContext(ctx) be := backend.FromContext(ctx) user := proto.UserFromContext(ctx) name := args[0] - if _, err := be.CreateRepository(ctx, name, user, proto.RepositoryOptions{ + r, err := be.CreateRepository(ctx, name, user, proto.RepositoryOptions{ Private: private, Description: description, ProjectName: projectName, Hidden: hidden, - }); err != nil { + }) + if err != nil { return err } + + cloneurl := fmt.Sprintf("%s/%s.git", cfg.SSH.PublicURL, r.Name()) + cmd.PrintErrf("Created repository %s\n", r.Name()) + cmd.Println(cloneurl) + return nil }, } diff --git a/testscript/script_test.go b/testscript/script_test.go index 7c345dd71..3c544b037 100644 --- a/testscript/script_test.go +++ b/testscript/script_test.go @@ -99,8 +99,7 @@ func TestScript(t *testing.T) { cfg.Stats.ListenAddr = statsListen cfg.DB.Driver = "sqlite" cfg.LFS.Enabled = true - // TODO: run tests with both SSH enabled/disabled - cfg.LFS.SSHEnabled = false + cfg.LFS.SSHEnabled = true if err := cfg.Validate(); err != nil { return err diff --git a/testscript/testdata/repo-create.txtar b/testscript/testdata/repo-create.txtar index 6787ee9d0..794294a16 100644 --- a/testscript/testdata/repo-create.txtar +++ b/testscript/testdata/repo-create.txtar @@ -5,6 +5,8 @@ # create a repo soft repo create repo1 -d 'description' -H -p -n 'repo11' +stderr 'Created repository repo1.*' +stdout ssh://localhost:$SSH_PORT/repo1.git soft repo hidden repo1 stdout true soft repo private repo1 @@ -95,6 +97,8 @@ soft user create bar --key "$USER1_AUTHORIZED_KEY" # user create a repo usoft repo create repo2 -d 'description' -H -p -n 'repo2' +stderr 'Created repository repo2.*' +stdout ssh://localhost:$SSH_PORT/repo2.git usoft repo hidden repo2 stdout true usoft repo private repo2