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
Empty file removed api/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion cli/cmd/deploy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"github.com/leapfrogtechnology/shift/cli/internals/deploy"
"github.com/leapfrogtechnology/shift/cli/internal/deploy"
)

// Deploy triggers deployment for provided project.
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/setup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"github.com/leapfrogtechnology/shift/cli/internals/setup"
"github.com/leapfrogtechnology/shift/cli/internal/setup"
)

// Setup prompts user for required information for creating a project.
Expand Down
11 changes: 0 additions & 11 deletions cli/go.mod

This file was deleted.

158 changes: 19 additions & 139 deletions cli/internals/setup/setup.go → cli/internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ package setup
import (
"encoding/json"
"fmt"
"strings"

"github.com/AlecAivazis/survey/v2"
"github.com/leapfrogtechnology/shift/cli/services/mq/infrastructure"
"github.com/leapfrogtechnology/shift/cli/utils/github"
"github.com/leapfrogtechnology/shift/cli/utils/spinner"
)

type projectDetails struct {
Expand All @@ -18,21 +14,24 @@ type projectDetails struct {
type deploymentDetails struct {
DeploymentName string
CloudProvider string
AccessKey string
SecretKey string
DeploymentType string
GitProvider string
}

type frontendBuildInformation struct {
BuildCommand string
DistFolder string
}

type backendBuildInformation struct {
Port string
HealthCheckPath string
DockerfilePath string
}

type deployment struct {
Name string `json:"name"`
Platform string `json:"platform"`
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`
Type string `json:"type"`
GitProvider string `json:"gitProvider"`
GitToken string `json:"gitToken"`
CloneURL string `json:"cloneURL"`
BuildCommand string `json:"buildCommand"`
DistFolder string `json:"distFolder"`
Port string `json:"port"`
Expand All @@ -41,22 +40,12 @@ type deployment struct {
DockerFilePath string `json:"dockerFilePath"`
}

type projectRequest struct {
// Project defines the overall structure for a project deployment.
type Project struct {
ProjectName string `json:"projectName"`
Deployment deployment `json:"deployment"`
}

type frontendBuildInformation struct {
BuildCommand string
DistFolder string
}

type backendBuildInformation struct {
Port string
HealthCheckPath string
DockerfilePath string
}

func askProjectDetails() *projectDetails {
questions := []*survey.Question{
{
Expand Down Expand Up @@ -92,32 +81,13 @@ func askDeploymentDetails() *deploymentDetails {
Options: []string{"AWS", "Azure", "GCP"},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this final static array, seems like this will be constant always

},
},
{
Name: "accessKey",
Prompt: &survey.Input{
Message: "Access Key:",
},
},
{
Name: "secretKey",
Prompt: &survey.Input{
Message: "Secret Key:",
},
},
{
Name: "deploymentType",
Prompt: &survey.Select{
Message: "Choose Deployment Type:",
Options: []string{"Frontend", "Backend"},
},
},
{
Name: "gitProvider",
Prompt: &survey.Select{
Message: "Choose Git Provider",
Options: []string{"Github", "Gitlab", "BitBucket"},
},
},
}

answers := &deploymentDetails{}
Expand All @@ -130,87 +100,6 @@ func askDeploymentDetails() *deploymentDetails {
return answers
}

func askGitCredentials(gitProvider string) *github.GitCredentials {
fmt.Println("\n Connect " + gitProvider)
questions := []*survey.Question{
{
Name: "username",
Prompt: &survey.Input{
Message: "Username",
},
},
{
Name: "password",
Prompt: &survey.Password{
Message: "Password",
},
},
{
Name: "mfaToken",
Prompt: &survey.Input{
Message: "MfaToken",
},
},
}

answers := &github.GitCredentials{}
err := survey.Ask(questions, answers)

if err != nil {
fmt.Println(err)
}

return answers
}

func chooseOrganization(personalToken string) string {
spinner.Start("Fetching your organizations...")
user, _ := github.FetchUser(personalToken)
organizations, _ := github.FetchOrganizations(personalToken)
spinner.Stop()

questions := &survey.Select{
Message: "Choose user/organization:",
Options: append(organizations, user+" (User)"),
}

org := ""
err := survey.AskOne(questions, &org)

if err != nil {
fmt.Println(err)
}

return org
}

func chooseRepo(personalToken string, organization string) (string, string) {
repos := []string{}
repoURL := map[string]string{}

spinner.Start("Fetching your repositories...")
if strings.Contains(organization, "(User)") {
repos, repoURL, _ = github.FetchUserRepos(personalToken)
} else {
repos, repoURL, _ = github.FetchOrgRepos(personalToken, organization)
}
spinner.Stop()

questions := &survey.Select{
Message: "Choose Repository:",
Options: repos,
}

org := ""
err := survey.AskOne(questions, &org)

if err != nil {
fmt.Println(err)
}

return org, repoURL[org]
}

func askFrontendBuildInformation() *frontendBuildInformation {
questions := []*survey.Question{
{
Expand Down Expand Up @@ -284,14 +173,6 @@ func askSlackEndpoint() string {
func Run() {
projectDetails := askProjectDetails()
deploymentDetails := askDeploymentDetails()
gitCredentials := askGitCredentials(deploymentDetails.GitProvider)

spinner.Start("Connecting to Github...")
personalToken, _ := github.CreatePersonalToken(gitCredentials)
spinner.Stop()

organization := chooseOrganization(personalToken)
_, repoURL := chooseRepo(personalToken, organization)

frontendBuildInformation := &frontendBuildInformation{}

Expand All @@ -305,17 +186,12 @@ func Run() {

slackEndpoint := askSlackEndpoint()

projectRequest := projectRequest{
projectRequest := Project{
ProjectName: projectDetails.ProjectName,
Deployment: deployment{
Name: deploymentDetails.DeploymentName,
Platform: deploymentDetails.CloudProvider,
AccessKey: deploymentDetails.AccessKey,
SecretKey: deploymentDetails.SecretKey,
Type: deploymentDetails.DeploymentType,
GitProvider: deploymentDetails.GitProvider,
GitToken: personalToken,
CloneURL: repoURL,
BuildCommand: frontendBuildInformation.BuildCommand,
DistFolder: frontendBuildInformation.DistFolder,
Port: backendBuildInformation.Port,
Expand All @@ -329,5 +205,9 @@ func Run() {

fmt.Println(string(projectRequestJSON))

infrastructure.Publish(projectRequestJSON)
// 1. Save json code here.

// 2. Run infrastructre code here and save to JSON again

// 3. Deploy to infrastructure code here.
}
30 changes: 0 additions & 30 deletions cli/internals/deploy/deploy.go

This file was deleted.

71 changes: 0 additions & 71 deletions cli/services/mq/infrastructure/infrastructure.go

This file was deleted.

22 changes: 0 additions & 22 deletions cli/services/mq/mq.go

This file was deleted.

Loading