change linux

This commit is contained in:
2023-07-08 00:45:18 -04:00
parent 71fe930228
commit 7e2e5c85f5
10 changed files with 252 additions and 125 deletions
+10 -103
View File
@@ -1,16 +1,11 @@
package cmdCreate
import (
"bytes"
"encoding/json"
"fmt"
"kode-creator/config"
"kode-creator/structures"
"kode-creator/utils"
"log"
"net/http"
"os"
"os/exec"
"github.com/joho/godotenv"
"github.com/spf13/cobra"
@@ -27,7 +22,7 @@ func InitConfig(config *config.Config) {
var CreateCmd = &cobra.Command{
Use: "create",
Short: "Create Github project",
Short: "CREATE Github project",
Long: `A simple CLI app to create a startup project on Github`,
Run: func(cmd *cobra.Command, args []string) {
@@ -79,18 +74,19 @@ func CreateProject(cmd *cobra.Command, args []string) error {
}
// if readme flag is set, create readme in project
if CfgGlobal.GetCreateReadmeFlag() {
fmt.Println("==> Creating readme...")
isCreated := CreateReadme(name, description, "BC", "")
if isCreated {
fmt.Println("==> Created README.md")
}
}
// if readme flag is set, create readme in project
if CfgGlobal.GetCreateReadmeFlag() {
fmt.Println("==> Creating readme...")
isCreated := CreateReadme(name, description, "BC", "")
if isCreated {
fmt.Println("==> Created README.md")
}
}
// if github flag is set, create structure in github
if CfgGlobal.GetCreateGitFlag() {
if CfgGlobal.GetCreateTeaFlag() {
} else if CfgGlobal.GetCreateTeaFlag() {
@@ -104,92 +100,3 @@ func CreateProject(cmd *cobra.Command, args []string) error {
return nil
}
// The function creates a directory for a project and changes the current working directory to the
// newly created directory.
func CreateProjectStructure(project structures.Project) {
fmt.Println("==> Creating directory...")
// Create directory of the project
fmt.Println("==> Creating directory...")
utils.CreateDir(project.Name)
fmt.Println("==> Created directory")
// Change to project directory
err := os.Chdir(project.Name)
if err != nil {
log.Fatal(err)
}
}
// The function `CreateGiteaProject` creates a new Gitea project, initializes a Git repository, and
// makes an initial commit.
func CreateGiteaProject(prj structures.Project, cmd *cobra.Command, args []string) error {
// Make API request to create Gitea project
jsonData, _ := json.Marshal(prj)
req, err := http.NewRequest("POST",
fmt.Sprintf("%s/%s/repos", CfgGlobal.GetUrlApiOrgs(), CfgGlobal.GetCreateCmd().Organization),
bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "token "+CfgGlobal.GetGitTeaTokenEnv())
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
log.Fatalln(err)
}
var dataReceived structures.GitOrgsRepoResponse
err = json.NewDecoder(res.Body).Decode(&dataReceived)
if err != nil {
log.Fatal(err)
}
fmt.Println(dataReceived)
fmt.Printf("==> Created project '%s' URL: '%s'\n", name, dataReceived.CloneURL)
defer res.Body.Close()
// Git commands
gitCmd := exec.Command("git", "init")
err = gitCmd.Run()
if err != nil {
log.Fatal(err)
} else {
fmt.Printf("==> Initialized empty Git repository in %s\n", name)
}
gitCmd = exec.Command("git", "checkout", "-b", "main")
err = gitCmd.Run()
if err != nil {
log.Fatal(err)
} else {
fmt.Println("==> Switched to a new branch 'main'")
}
gitCmd = exec.Command("git", "add", "-A")
err = gitCmd.Run()
if err != nil {
log.Fatal(err)
} else {
fmt.Println("==> Switched to a new branch 'main'")
}
gitCmd = exec.Command("git", "commit", "-m", "first commit from project creator !")
err = gitCmd.Run()
if err != nil {
log.Fatal(err)
} else {
fmt.Println("==> first commit from Kode-Creator !")
}
// Get project info from API response
var project structures.Project
json.NewDecoder(res.Body).Decode(&project)
fmt.Println(project)
return nil
}
func CreateGithubProject() {}
+26
View File
@@ -0,0 +1,26 @@
package cmdCreate
import (
"fmt"
"kode-creator/structures"
"kode-creator/utils"
"log"
"os"
)
// The function creates a directory for a project and changes the current working directory to the
// newly created directory.
func CreateProjectStructure(project structures.Project) {
fmt.Println("==> Creating directory...")
// Create directory of the project
fmt.Println("==> Creating directory...")
utils.CreateDir(project.Name)
fmt.Println("==> Created directory")
// Change to project directory
err := os.Chdir(project.Name)
if err != nil {
log.Fatal(err)
}
}
+83
View File
@@ -0,0 +1,83 @@
package cmdCreate
import (
"bytes"
"encoding/json"
"fmt"
"kode-creator/structures"
"log"
"net/http"
"os/exec"
"github.com/spf13/cobra"
)
// The function `CreateGiteaProject` creates a new Gitea project, initializes a Git repository, and
// makes an initial commit.
func CreateGiteaProject(prj structures.Project, cmd *cobra.Command, args []string) error {
// Make API request to create Gitea project
jsonData, _ := json.Marshal(prj)
req, err := http.NewRequest("POST",
fmt.Sprintf("%s/%s/repos", CfgGlobal.GetUrlApiOrgs(), CfgGlobal.GetCreateCmd().Organization),
bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "token "+CfgGlobal.GetGitTeaTokenEnv())
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
log.Fatalln(err)
}
var dataReceived structures.GitOrgsRepoResponse
err = json.NewDecoder(res.Body).Decode(&dataReceived)
if err != nil {
log.Fatal(err)
}
fmt.Println(dataReceived)
fmt.Printf("==> Created project '%s' URL: '%s'\n", name, dataReceived.CloneURL)
defer res.Body.Close()
// Git commands
gitCmd := exec.Command("git", "init")
err = gitCmd.Run()
if err != nil {
log.Fatal(err)
} else {
fmt.Printf("==> Initialized empty Git repository in %s\n", name)
}
gitCmd = exec.Command("git", "checkout", "-b", "main")
err = gitCmd.Run()
if err != nil {
log.Fatal(err)
} else {
fmt.Println("==> Switched to a new branch 'main'")
}
gitCmd = exec.Command("git", "add", "-A")
err = gitCmd.Run()
if err != nil {
log.Fatal(err)
} else {
fmt.Println("==> Switched to a new branch 'main'")
}
gitCmd = exec.Command("git", "commit", "-m", "first commit from project creator !")
err = gitCmd.Run()
if err != nil {
log.Fatal(err)
} else {
fmt.Println("==> first commit from Kode-Creator !")
}
// Get project info from API response
var project structures.Project
json.NewDecoder(res.Body).Decode(&project)
fmt.Println(project)
return nil
}
+5
View File
@@ -0,0 +1,5 @@
package cmdCreate
func CreateGithubProject() {
}