Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Support gitlab provider on command add repo #350

Merged
merged 8 commits into from
Aug 5, 2020
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
22 changes: 15 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
"os"
"time"

"github.com/ZupIT/ritchie-cli/pkg/git/github"
"github.com/ZupIT/ritchie-cli/pkg/git/gitlab"

"k8s.io/kubectl/pkg/util/templates"

"github.com/ZupIT/ritchie-cli/pkg/credential"
Expand All @@ -31,7 +34,6 @@ import (
"github.com/ZupIT/ritchie-cli/pkg/formula/repo"
"github.com/ZupIT/ritchie-cli/pkg/formula/runner"
"github.com/ZupIT/ritchie-cli/pkg/formula/tree"
"github.com/ZupIT/ritchie-cli/pkg/github"
"github.com/ZupIT/ritchie-cli/pkg/rtutorial"

"github.com/ZupIT/ritchie-cli/pkg/upgrade"
Expand Down Expand Up @@ -78,10 +80,16 @@ func buildCommands() *cobra.Command {
fileManager := stream.NewFileManager()
dirManager := stream.NewDirManager(fileManager)

gitRepo := github.NewRepoManager(http.DefaultClient)
githubRepo := github.NewRepoManager(http.DefaultClient)
gitlabRepo := gitlab.NewRepoManager(http.DefaultClient)

repoProviders := formula.NewRepoProviders()
repoProviders.Add("Github", formula.Git{Repos: githubRepo, NewRepoInfo: github.NewRepoInfo})
repoProviders.Add("Gitlab", formula.Git{Repos: gitlabRepo, NewRepoInfo: gitlab.NewRepoInfo})

treeGen := tree.NewGenerator(dirManager, fileManager)

repoCreator := repo.NewCreator(ritchieHomeDir, gitRepo, dirManager, fileManager)
repoCreator := repo.NewCreator(ritchieHomeDir, repoProviders, dirManager, fileManager)
repoLister := repo.NewLister(ritchieHomeDir, fileManager)
repoAdder := repo.NewAdder(ritchieHomeDir, repoCreator, treeGen, dirManager, fileManager)
repoListCreator := repo.NewListCreator(repoLister, repoCreator)
Expand All @@ -91,7 +99,7 @@ func buildCommands() *cobra.Command {
repoDeleter := repo.NewDeleter(ritchieHomeDir, fileManager, dirManager)
repoPrioritySetter := repo.NewPrioritySetter(ritchieHomeDir, fileManager)

tplManager := template.NewManager(api.RitchieHomeDir())
tplManager := template.NewManager(api.RitchieHomeDir(), dirManager)
ctxFinder := rcontext.NewFinder(ritchieHomeDir, fileManager)
ctxSetter := rcontext.NewSetter(ritchieHomeDir, ctxFinder)
ctxRemover := rcontext.NewRemover(ritchieHomeDir, ctxFinder)
Expand Down Expand Up @@ -139,7 +147,7 @@ func buildCommands() *cobra.Command {
addCmd := cmd.NewAddCmd()
createCmd := cmd.NewCreateCmd()
deleteCmd := cmd.NewDeleteCmd()
initCmd := cmd.NewInitCmd(repoAdder, gitRepo, tutorialFinder)
initCmd := cmd.NewInitCmd(repoAdder, githubRepo, tutorialFinder, inputBool)
listCmd := cmd.NewListCmd()
setCmd := cmd.NewSetCmd()
showCmd := cmd.NewShowCmd()
Expand All @@ -162,8 +170,8 @@ func buildCommands() *cobra.Command {
deleteCtxCmd := cmd.NewDeleteContextCmd(ctxFindRemover, inputBool, inputList)
setCtxCmd := cmd.NewSetContextCmd(ctxFindSetter, inputText, inputList)
showCtxCmd := cmd.NewShowContextCmd(ctxFinder)
addRepoCmd := cmd.NewAddRepoCmd(repoAddLister, gitRepo, inputTextValidator, inputPassword, inputURL, inputList, inputBool, inputInt, tutorialFinder)
updateRepoCmd := cmd.NewUpdateRepoCmd(http.DefaultClient, repoListUpdater, gitRepo, inputText, inputPassword, inputURL, inputList, inputBool, inputInt)
addRepoCmd := cmd.NewAddRepoCmd(repoAddLister, repoProviders, inputTextValidator, inputPassword, inputURL, inputList, inputBool, inputInt, tutorialFinder)
updateRepoCmd := cmd.NewUpdateRepoCmd(http.DefaultClient, repoListUpdater, repoProviders, inputText, inputPassword, inputURL, inputList, inputBool, inputInt)
listRepoCmd := cmd.NewListRepoCmd(repoLister, tutorialFinder)
deleteRepoCmd := cmd.NewDeleteRepoCmd(repoLister, inputList, repoDeleter)
setPriorityCmd := cmd.NewSetPriorityCmd(inputList, inputInt, repoLister, repoPrioritySetter)
Expand Down
23 changes: 19 additions & 4 deletions functional/core/core_feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,38 @@
{
"entry":"Add new repo",
"steps":[
{
"key":"Select your provider:",
"value":"Github",
"action":"select"
},
{
"key":"",
"value":"add repo",
"action":"main"
},
{
"key":"Name of the repository:",
"key":"Repository name:",
"value":"Leonidas",
"action":"sendkey"
},
{
"key":"URL of the tree",
"value":"https://commons-repo.ritchiecli.io/tree/tree.json",
"key":"Repository URL:",
"value":"https://github.com/zupIt/ritchie-formulas",
"action":"sendkey"
},
{
"key":"Priority",
"key":"Is a private repository?",
"value":"no",
"action":"select"
},
{
"key":"Select a tag version:",
"value":"1.0.0",
"action":"select"
},
{
"key":"Set the priority:",
"value":"999",
"action":"sendkey"
}
Expand Down
16 changes: 5 additions & 11 deletions functional/init/init_feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@
],
"result":"To start using rit, you need to initialize rit first."
},
{
"entry":"Add new repo",
"steps":[
{
"key":"",
"value":"add repo",
"action":"main"
}
],
"result":"To start using rit, you need to initialize rit first."
},
{
"entry":"List repo",
"steps":[
Expand Down Expand Up @@ -95,6 +84,11 @@
"key":"",
"value":"init",
"action":"main"
},
{
"key":"Would you like to add the community repository? [https://github.com/ZupIT/ritchie-formulas]",
"value":"yes",
"action":"select"
}
],
"result":""
Expand Down
12 changes: 6 additions & 6 deletions functional/init/init_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ var _ = Describe("RitSingleInit", func() {
Entry("Show context", scenariosCore[0]),
Entry("Set context", scenariosCore[1]),
Entry("Delete context", scenariosCore[2]),
Entry("Add new repo", scenariosCore[3]),
Entry("List repo", scenariosCore[4]),
Entry("Delete repo", scenariosCore[5]),
Entry("Set Credential", scenariosCore[6]),
Entry("Update repo", scenariosCore[7]),
Entry("Do init", scenariosCore[8]),
// Entry("Add new repo", scenariosCore[3]),
Entry("List repo", scenariosCore[3]),
Entry("Delete repo", scenariosCore[4]),
Entry("Set Credential", scenariosCore[5]),
Entry("Update repo", scenariosCore[6]),
Entry("Do init", scenariosCore[7]),
)

})
10 changes: 0 additions & 10 deletions functional/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ func RitSingleInit() {
fmt.Println("Setup Done..")
}

func RitTeamInit() {
os := runtime.GOOS
if os == "windows" {
// TODO setup Windows for TEAM
} else {
setUpRitTeamUnix()
}
fmt.Println("Setup Done..")
}

func RitClearConfigs() {
os := runtime.GOOS
if os == "windows" {
Expand Down
56 changes: 9 additions & 47 deletions functional/runner_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,63 +77,25 @@ func setUpRitSingleUnix() {
fmt.Println("Running Setup for Unix..")

fmt.Println("Running INIT")
initStepEcho := Step{Key: "", Value: "{\"passphrase\":\"12345\"}", Action: "echo"}
initStepRit := Step{Key: "", Value: "init --stdin", Action: "rit"}
init := Scenario{Entry: "Running Init", Result: "", Steps: []Step{initStepEcho, initStepRit}}
initStepRit := Step{Key: "", Value: "init", Action: "rit"}
initAddRepo := Step{Key: "Would you like to add the community repository? [https://github.com/ZupIT/ritchie-formulas]", Value: "yes", Action: "select"}

_, err := init.runStdinForUnix()
if err != nil {
log.Printf("Error when do init: %q", err)
}

}
init := Scenario{Entry: "Running Init", Result: "", Steps: []Step{initStepRit, initAddRepo}}

func setUpRitTeamUnix(){
fmt.Println("Running Setup for Unix Team..")

fmt.Println("Running INIT")
initStepEcho := Step{Key: "", Value: "{\"organization\":\"zup\", \"url\":\"https://ritchie-server.itiaws.dev\"}", Action: "echo"}
initStepRit := Step{Key: "", Value: "init --stdin", Action: "rit"}
init := Scenario{Entry: "Running Init", Result: "", Steps: []Step{initStepEcho, initStepRit}}

out, err := init.runStdinForUnix()
err, _ := init.runStepsForUnix()
if err != nil {
log.Printf("Error when do init: %q", err)
}
fmt.Println(out)

fmt.Println("Running Login")
loginStepEcho := Step{Key: "", Value: "{\"username\":\"admin.ritchie\", \"password\":\"C@m@r0@m@r3l0\"}", Action: "echo"}
loginStepRit := Step{Key: "", Value: "login --stdin", Action: "rit"}
login := Scenario{Entry: "Running Init", Result: "", Steps: []Step{loginStepEcho, loginStepRit}}

out, err = login.runStdinForUnix()
if err != nil {
log.Printf("Error when do Login: %q", err)
}
fmt.Println(out)
}

func setUpClearSetupUnix() {
fmt.Println("Running Clear for Unix..")
myPath := "/.rit/"
myPath := ".rit"
usr, _ := user.Current()
dir := usr.HomeDir + myPath
dir := filepath.Join(usr.HomeDir, myPath)

d, err := os.Open(dir)
if err != nil {
log.Printf("Error Open dir: %q", err)
}
defer d.Close()
names, err := d.Readdirnames(-1)
if err != nil {
log.Printf("Error Readdirnames: %q", err)
}
for _, name := range names {
err := os.RemoveAll(filepath.Join(dir, name))
if err != nil {
log.Printf("Error cleaning repo rit: %q", err)
}
if err := os.RemoveAll(dir); err != nil {
log.Fatal(err)
}
}

Expand Down Expand Up @@ -235,7 +197,7 @@ func sendKeys(step Step, out io.Reader, stdin io.WriteCloser) error {
valueFinal := step.Value + "\n"
scanner := scannerTerminal(out)
startKey := false
//Need to work on this possibility
// Need to work on this possibility
// optionNumber := 0
for scanner.Scan() {
m := scanner.Text()
Expand Down
2 changes: 1 addition & 1 deletion functional/stdin/stdin_feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"steps":[
{
"key":"",
"value":"{\"name\":\"Leonidas\", \"url\":\"https://github.com/viniciussousazup/ritchie-formulas\", \"version\":\"0.0.3\",\"priority\":999}",
"value":"{\"provider\":\"Github\", \"name\":\"Leonidas\", \"url\":\"https://github.com/viniciussousazup/ritchie-formulas\", \"version\":\"0.0.3\",\"priority\":999}",
"action":"echo"
},
{
Expand Down
1 change: 1 addition & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
{Parent: "root", Usage: "init"},
{Parent: "root", Usage: "list"},
{Parent: "root_list", Usage: "repo"},
{Parent: "root_list", Usage: "credential"},
{Parent: "root", Usage: "set"},
{Parent: "root_set", Usage: "context"},
{Parent: "root_set", Usage: "credential"},
Expand Down
Loading