Skip to content

Commit 74528df

Browse files
authored
Merge pull request #171 from commitdev/integrate-repo-creation
Integrated repo creation into create command
2 parents 12c0eb4 + ce94969 commit 74528df

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

cmd/create.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import (
55
"path"
66
"strings"
77

8+
"github.com/commitdev/zero/internal/config/globalconfig"
89
"github.com/commitdev/zero/internal/config/projectconfig"
910
"github.com/commitdev/zero/internal/constants"
1011
"github.com/commitdev/zero/internal/generate"
12+
"github.com/commitdev/zero/internal/vcs"
1113
"github.com/commitdev/zero/pkg/util/exit"
14+
"github.com/commitdev/zero/pkg/util/flog"
1215
"github.com/spf13/cobra"
1316
)
1417

@@ -36,4 +39,17 @@ func Create(dir string, createConfigPath string) {
3639
projectConfig := projectconfig.LoadConfig(configFilePath)
3740

3841
generate.Generate(*projectConfig)
42+
43+
if projectConfig.ShouldPushRepositories {
44+
flog.Infof(":up_arrow: Done Rendering - committing repositories to version control.")
45+
46+
globalConfig := globalconfig.GetProjectCredentials(projectConfig.Name)
47+
for _, module := range projectConfig.Modules {
48+
vcs.InitializeRepository(module.Files.Repository, globalConfig.GithubResourceConfig.AccessToken)
49+
}
50+
} else {
51+
flog.Infof(":up_arrow: Done Rendering - you will need to commit the created projects to version control.")
52+
}
53+
54+
flog.Infof(":check_mark_button: Done - run zero apply to create any required infrastructure or execute any other remote commands to prepare your environments.")
3955
}

internal/context/init.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
project "github.com/commitdev/zero/pkg/credentials"
2020
"github.com/commitdev/zero/pkg/util/exit"
2121
"github.com/commitdev/zero/pkg/util/flog"
22-
"github.com/k0kubun/pp"
2322
"github.com/manifoldco/promptui"
2423
)
2524

@@ -74,7 +73,6 @@ func Init(outDir string) *projectconfig.ZeroProjectConfig {
7473
}
7574

7675
}
77-
pp.Println(mappedSources)
7876
projectConfig.Modules[moduleName] = projectconfig.NewModule(projectModuleParams, repoName, repoURL, mappedSources[moduleName])
7977
}
8078

internal/generate/generate_modules.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ func Generate(projectConfig projectconfig.ZeroProjectConfig) error {
5656

5757
executeTemplates(fileTemplates, templateData, delimiters)
5858
}
59-
60-
flog.Infof(":up_arrow: Done Rendering - committing repositories to version control")
61-
// TODO : Integrate this work
62-
63-
flog.Infof(":check_mark_button: Done - run zero apply to create any required infrastructure or execute any other remote commands to prepare your environments.")
6459
return nil
6560
}
6661

internal/vcs/create-git-repos.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package vcs
33
import (
44
"context"
55
"fmt"
6-
"github.com/machinebox/graphql"
76
"os/exec"
87
"strings"
8+
9+
"github.com/commitdev/zero/pkg/util/flog"
10+
"github.com/machinebox/graphql"
911
)
1012

1113
// InitializeRepository Creates and initializes a github repository for the given url
@@ -53,19 +55,19 @@ func InitializeRepository(repositoryUrl string, githubApiKey string) {
5355
return
5456
}
5557

56-
fmt.Printf("Repository successfully created and initialized for module: %s\n", repositoryName)
58+
flog.Infof(":check_mark_button: Repository created: %s", repositoryUrl)
5759
}
5860

5961
// parseRepositoryUrl extracts the owner name and repository name from a repository url.
6062
// repositoryUrl is expected to be in the format "github.com/{ownerName}/{repositoryName}"
6163
func parseRepositoryUrl(repositoryUrl string) (string, string, error) {
6264
if len(repositoryUrl) == 0 {
63-
return "","", fmt.Errorf("invalid repository url. expected format \"github.com/{ownerName}/{repositoryName}\"")
65+
return "", "", fmt.Errorf("invalid repository url. expected format \"github.com/{ownerName}/{repositoryName}\"")
6466
}
6567

6668
segments := strings.Split(repositoryUrl, "/")
6769
if len(segments) != 3 {
68-
return "","", fmt.Errorf("invalid repository url. expected format \"github.com/{ownerName}/{repositoryName}\"")
70+
return "", "", fmt.Errorf("invalid repository url. expected format \"github.com/{ownerName}/{repositoryName}\"")
6971
}
7072

7173
ownerName := segments[1]
@@ -77,10 +79,10 @@ func parseRepositoryUrl(repositoryUrl string) (string, string, error) {
7779
const createPersonalRepositoryMutation = `mutation ($repoName: String!, $repoDescription: String!) {
7880
createRepository(
7981
input: {
80-
name:$repoName,
81-
visibility: PRIVATE,
82+
name:$repoName,
83+
visibility: PRIVATE,
8284
description: $repoDescription
83-
})
85+
})
8486
{
8587
clientMutationId
8688
}
@@ -89,11 +91,11 @@ const createPersonalRepositoryMutation = `mutation ($repoName: String!, $repoDes
8991
const createOrganizationRepositoryMutation = `mutation ($repoName: String!, $repoDescription: String!, $ownerId: String!) {
9092
createRepository(
9193
input: {
92-
name:$repoName,
93-
visibility: PRIVATE,
94+
name:$repoName,
95+
visibility: PRIVATE,
9496
description: $repoDescription
9597
ownerId: $ownerId
96-
})
98+
})
9799
{
98100
clientMutationId
99101
}
@@ -183,21 +185,23 @@ func doInitialCommit(ownerName string, repositoryName string) error {
183185
}
184186

185187
for _, command := range commands {
186-
fmt.Printf(">> %s\n", command.description)
188+
// TODO: Debug-level logging?
189+
// fmt.Printf(">> %s\n", command.description)
187190

188191
cmd := exec.Command(command.command, command.args...)
189192
cmd.Dir = "./" + repositoryName
190-
out, err := cmd.CombinedOutput()
193+
_, err := cmd.CombinedOutput()
191194
if err != nil {
192195
fmt.Printf("ERROR: failed to run %s: %s\n", command.description, err.Error())
193196
// this is a partial failure. some commands may have exec'ed successfully.
194197
break
195-
} else {
196-
response := string(out)
197-
if len(response) > 0 {
198-
fmt.Println(response)
199-
}
200-
}
198+
} //else {
199+
// TODO: Debug-level logging?
200+
// response := string(out)
201+
// if len(response) > 0 {
202+
// fmt.Println(response)
203+
// }
204+
// }
201205
}
202206

203207
return nil

0 commit comments

Comments
 (0)