Skip to content

Commit

Permalink
feat: add support to use flow package
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Martinez committed Jul 23, 2023
1 parent 8e91b49 commit cb44a26
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 15 deletions.
3 changes: 3 additions & 0 deletions cmd/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/Minnek-Digital-Studio/cominnek/cmd/branch"
"github.com/Minnek-Digital-Studio/cominnek/controllers/project"
pkg_action "github.com/Minnek-Digital-Studio/cominnek/pkg/cli/actions"
"github.com/spf13/cobra"
)
Expand All @@ -10,6 +11,8 @@ var branchCmd = &cobra.Command{
Use: "branch",
Short: "Create a new branch.",
Run: func(cmd *cobra.Command, args []string) {
project.ReadConfigFile(true)

pkg_action.Branch()
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/branch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var stash bool

func SetCommands(Command *cobra.Command) {
project.ReadConfigFile()
project.ReadConfigFile(false)

for _, branch := range project.Config.Git.Branches {
if branch.Config.Hidden {
Expand Down
3 changes: 3 additions & 0 deletions cmd/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/Minnek-Digital-Studio/cominnek/config"
"github.com/Minnek-Digital-Studio/cominnek/controllers/project"
pkg_action "github.com/Minnek-Digital-Studio/cominnek/pkg/cli/actions"
"github.com/spf13/cobra"
)
Expand All @@ -10,6 +11,8 @@ var prCmd = &cobra.Command{
Use: "pr",
Short: "Create a new pull request",
Run: func(cmd *cobra.Command, args []string) {
project.ReadConfigFile(true)

config.AppData.PullRequest.Ticket = ticket
config.AppData.PullRequest.Base = baseBranch

Expand Down
3 changes: 3 additions & 0 deletions cmd/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/Minnek-Digital-Studio/cominnek/config"
"github.com/Minnek-Digital-Studio/cominnek/controllers/project"
pkg_action "github.com/Minnek-Digital-Studio/cominnek/pkg/cli/actions"
"github.com/Minnek-Digital-Studio/cominnek/pkg/git"
"github.com/spf13/cobra"
Expand All @@ -11,6 +12,8 @@ var publishCmd = &cobra.Command{
Use: "publish <message>",
Short: "Publish a branch to GitHub and create a pull request as Draft",
Run: func(cmd *cobra.Command, args []string) {
project.ReadConfigFile(true)

msg := ""
body := ""

Expand Down
6 changes: 4 additions & 2 deletions config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path/filepath"
"time"

"github.com/Minnek-Digital-Studio/cominnek/controllers/project"
project_structs "github.com/Minnek-Digital-Studio/cominnek/controllers/project/structs"
)

type ICommit struct {
Expand Down Expand Up @@ -36,7 +36,7 @@ type IAppData struct {
Base string
}
Branch struct {
Data project.Branch
Data project_structs.Branch
Stash bool
Ticket string
}
Expand Down Expand Up @@ -64,6 +64,7 @@ type IAppData struct {
type IConfig struct {
AppPath string
TempPath string
FlowPath string
KeyPath string
TokenPath string
Version string
Expand All @@ -83,6 +84,7 @@ var Public = IConfig{
KeyPath: filepath.Join(cominnekPath, "key.bin"),
TokenPath: filepath.Join(cominnekPath, "auth.bin"),
PRBody: filepath.Join(cominnekPath, "pr-body.md"),
FlowPath: filepath.Join(cominnekPath, "flows"),
AppPath: cominnekPath,
TempPath: cominnekTempPath,
Logs: false,
Expand Down
8 changes: 6 additions & 2 deletions controllers/folders/Create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ package folders
import "os"

func Create(_path string) {
os.Mkdir(_path, os.ModePerm)
}
err := os.MkdirAll(_path, 0755)

if err != nil {
panic(err)
}
}
63 changes: 56 additions & 7 deletions controllers/project/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,39 @@ package project

import (
"encoding/json"
"os"
"path/filepath"

"github.com/Minnek-Digital-Studio/cominnek/config"
"github.com/Minnek-Digital-Studio/cominnek/controllers/files"
"github.com/Minnek-Digital-Studio/cominnek/controllers/folders"
project_structs "github.com/Minnek-Digital-Studio/cominnek/controllers/project/structs"
"github.com/fatih/color"
)

var Config Cominnek
var Config project_structs.Cominnek
var exitOnFail bool

func ReadConfigFile() bool {
func ReadConfigFile(_exitOnFail bool) bool {
exitOnFail = _exitOnFail
fileNames := []string{
"mnk-config.json",
}

for _, fileName := range fileNames {
if files.CheckExist(fileName) {
configByte := files.Read(fileName)
Config = convertToJSON(configByte).Cominnek
converted := convertToJSON(configByte).Cominnek
Config = getFlow(converted)
return true
}
}

return false
}

func convertToJSON(data []byte) Project {
var project Project
func convertToJSON(data []byte) project_structs.Project {
var project project_structs.Project
err := json.Unmarshal([]byte(data), &project)

if err != nil {
Expand All @@ -35,12 +44,52 @@ func convertToJSON(data []byte) Project {
return project
}

func GetConfigByName(name string) Branch {
func GetConfigByName(name string) project_structs.Branch {
for _, branch := range Config.Git.Branches {
if branch.Name == name {
return branch
}
}

return Branch{}
return project_structs.Branch{}
}

func getFlow(cmk project_structs.Cominnek) project_structs.Cominnek {
flowStr := cmk.Git.Flow

if flowStr == "custom" {
return cmk
}

if !folders.CheckExists(config.Public.FlowPath) {
folders.Create(config.Public.FlowPath)
}

var flow project_structs.Git
fileName := filepath.Join(config.Public.FlowPath, flowStr+".json")

if !files.CheckExist(fileName) {
println("Sorry but the flow " + flowStr + " does not exist")
println("Try to download it with the command:")

color.Green("\tcominnek add flow:" + flowStr)

if exitOnFail {
os.Exit(1)
} else {
return cmk
}
}

file := files.Read(fileName)

err := json.Unmarshal([]byte(file), &flow)

if err != nil {
panic(err)
}

cmk.Git = flow

return cmk
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package project
package project_structs

type Project struct {
Cominnek Cominnek `json:"cominnek"`
Expand All @@ -11,6 +11,7 @@ type Cominnek struct {
type Git struct {
GitConfig
Flow string `json:"flow"` // flow: "git", "github" or "custom"
Version string `json:"version"`
Extends GitConfig `json:"extends"`
}

Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/Minnek-Digital-Studio/cominnek/controllers"
"github.com/Minnek-Digital-Studio/cominnek/controllers/loading"
"github.com/Minnek-Digital-Studio/cominnek/controllers/logger"
"github.com/Minnek-Digital-Studio/cominnek/controllers/project"
"github.com/Minnek-Digital-Studio/cominnek/helper"
"github.com/Minnek-Digital-Studio/cominnek/pkg/emitters"
"github.com/Minnek-Digital-Studio/cominnek/pkg/events"
Expand All @@ -18,7 +17,6 @@ import (
func init() {
events.Watcher()
config.AppData.Start = time.Now()
project.ReadConfigFile()
}

func main() {
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/actions/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func branchQuestion() {
}

func Branch() {
project.ReadConfigFile(true)
branchQuestion()
ticket := config.AppData.Branch.Ticket
data := emitterTypes.IBranchEventData{
Expand Down

0 comments on commit cb44a26

Please sign in to comment.