Skip to content

Commit

Permalink
Merge pull request #23 from kumparan/feature/add-gocek-reporter
Browse files Browse the repository at this point in the history
feature: update gocek checker result path
  • Loading branch information
fahmi irfan authored Sep 9, 2020
2 parents 3c20661 + a5d5a99 commit a967112
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#Fer

<a name="v1.8.0"></a>
## [v1.8.0] - 2020-09-04
### New Features
- update gocek checker result path


<a name="v1.7.2"></a>
## [v1.7.2] - 2020-08-04
### Fixes
Expand Down Expand Up @@ -117,7 +123,8 @@
- db migrationfile generator ([#3](https://github.com/kumparan/fer/issues/3))


[Unreleased]: https://github.com/kumparan/fer/compare/v1.7.2...HEAD
[Unreleased]: https://github.com/kumparan/fer/compare/v1.8.0...HEAD
[v1.8.0]: https://github.com/kumparan/fer/compare/v1.7.2...v1.8.0
[v1.7.2]: https://github.com/kumparan/fer/compare/v1.7.1...v1.7.2
[v1.7.1]: https://github.com/kumparan/fer/compare/v1.7.0...v1.7.1
[v1.7.0]: https://github.com/kumparan/fer/compare/v1.6.0...v1.7.0
Expand Down
2 changes: 1 addition & 1 deletion config/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config

// Version define version of fer
const Version = "v1.7.2"
const Version = "v1.8.0"
5 changes: 3 additions & 2 deletions console/gocek.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ var gocekAllCmd = &cobra.Command{
func gocekAll(cmd *cobra.Command, args []string) {
cfg := config.GetFerConfig()
checker := gocek.ModuleChecker{
RootDir: cfg.Gocek.SaveOutputDir,
RootDir: cfg.Gocek.SaveOutputDir,
ServicesDirs: cfg.Gocek.ProjectDirs,
}

checker.Checks(cfg.Gocek.ProjectDirs)
checker.Checks()
}

func gocekCWD(cmd *cobra.Command, args []string) {
Expand Down
41 changes: 24 additions & 17 deletions gocek/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ import (

const (
_defaultMaxQueueSize = int(10)
timeLayout = "2006-01-02"
)

// ModuleChecker :nodoc:
type ModuleChecker struct {
RootDir string
RootDir string
ServicesDirs []string
}

// CheckCWD call CheckCWD() and print into stdout
// CheckCWD call checkCWD() and print into stdout
func (mc *ModuleChecker) CheckCWD() {
modlist, err := CheckCWD()
modlist, err := checkCWD()
if err != nil {
log.Fatal(err)
}
Expand All @@ -40,16 +42,24 @@ func (mc *ModuleChecker) CheckCWD() {
}

// Checks check module projects and save the json file
func (mc *ModuleChecker) Checks(dirs []string) {
for _, dir := range dirs {
func (mc *ModuleChecker) Checks() {
now := time.Now()
folder := now.Format(timeLayout)
savePath := path.Join(mc.RootDir, folder)
err := os.MkdirAll(savePath, 0755)
if err != nil {
log.Fatal(err)
}

for _, dir := range mc.ServicesDirs {
os.Chdir(dir)
modules, err := CheckCWD()
modules, err := checkCWD()
if err != nil {
continue
}

sdir := strings.Split(dir, "/")
err = mc.save(sdir[len(sdir)-1], modules)
err = mc.save(savePath, sdir[len(sdir)-1], modules)
if err != nil {
log.Error(err)
return
Expand All @@ -59,13 +69,9 @@ func (mc *ModuleChecker) Checks(dirs []string) {
}

// save modules as json
func (mc *ModuleChecker) save(modName string, modules []*SimpleModule) error {
now := time.Now()
layout := "2006-01-02"
fileName := fmt.Sprintf("%s.%s.json", modName, now.Format(layout))
dst := path.Join(mc.RootDir, fileName)

f, err := os.Create(dst)
func (mc *ModuleChecker) save(savePath, modName string, modules []*SimpleModule) error {
fileName := fmt.Sprintf("%s.json", modName)
f, err := os.Create(path.Join(savePath, fileName))
if err != nil {
log.Error(err)
return err
Expand All @@ -83,8 +89,8 @@ func (mc *ModuleChecker) save(modName string, modules []*SimpleModule) error {
return err
}

// CheckCWD check current working directory
func CheckCWD() (modules []*SimpleModule, err error) {
// checkCWD check current working directory
func checkCWD() (modules []*SimpleModule, err error) {
modList, err := findDirectModList()
if err != nil {
log.Error(err)
Expand Down Expand Up @@ -118,7 +124,7 @@ func findAllModuleUpdate(mods []string) (modules []*SimpleModule, err error) {

mod, err := findModuleUpdate(m)
if err != nil {
log.Error(err)
log.Error("findModuleUpdate: ", err)
return
}

Expand Down Expand Up @@ -183,6 +189,7 @@ func findModList() ([]string, error) {
func findDirectModList() ([]string, error) {
out, err := exec.Command("go", "list", "-m", "-f", `{{ .Path }} | {{ .Indirect }}`, "all").Output()
if err != nil {
log.Error("findDirectModList: ", err)
return nil, err
}
splitted := strings.Split(string(out), "\n")
Expand Down

0 comments on commit a967112

Please sign in to comment.