Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Solves Goreportcard pending issues #854

Merged
merged 7 commits into from
Jan 13, 2018
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
2 changes: 1 addition & 1 deletion buffalo/cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func updateGoDepsCheck() error {
// go old school with the installation
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
wg, ctx := errgroup.WithContext(ctx)
wg, _ := errgroup.WithContext(ctx)
deps, err := deplist.List()
if err != nil {
return errors.WithStack(err)
Expand Down
4 changes: 2 additions & 2 deletions flash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ func Test_FlashAdd(t *testing.T) {

f.Add("error", "something")
r.Equal(f.data, map[string][]string{
"error": []string{"something"},
"error": {"something"},
})

f.Add("error", "other")
r.Equal(f.data, map[string][]string{
"error": []string{"something", "other"},
"error": {"something", "other"},
})
}

Expand Down
170 changes: 110 additions & 60 deletions generators/newapp/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,72 +42,37 @@ func (a Generator) Run(root string, data makr.Data) error {
}

for _, f := range files {
if a.AsAPI {
if strings.Contains(f.WritePath, "locales") || strings.Contains(f.WritePath, "templates") || strings.Contains(f.WritePath, "public") {
continue
}
g.Add(makr.NewFile(f.WritePath, f.Body))
} else {
if !a.AsAPI {
g.Add(makr.NewFile(f.WritePath, f.Body))
continue
}

if strings.Contains(f.WritePath, "locales") || strings.Contains(f.WritePath, "templates") || strings.Contains(f.WritePath, "public") {
continue
}

g.Add(makr.NewFile(f.WritePath, f.Body))
}

data["name"] = a.Name
if err := refresh.Run(root, data); err != nil {
return errors.WithStack(err)
}

// Add CI configuration, if requested
if a.CIProvider == "travis" {
g.Add(makr.NewFile(".travis.yml", nTravis))
} else if a.CIProvider == "gitlab-ci" {
if a.WithPop {
if a.DBType == "postgres" {
data["testDbUrl"] = "postgres://postgres:postgres@postgres:5432/" + a.Name.File() + "_test?sslmode=disable"
} else if a.DBType == "mysql" {
data["testDbUrl"] = "mysql://root:root@(mysql:3306)/" + a.Name.File() + "_test"
} else {
data["testDbUrl"] = ""
}
g.Add(makr.NewFile(".gitlab-ci.yml", nGitlabCi))
} else {
g.Add(makr.NewFile(".gitlab-ci.yml", nGitlabCiNoPop))
}
}
a.setupCI(g, data)

if !a.AsAPI {
if a.WithWebpack {
w := webpack.New()
w.App = a.App
w.Bootstrap = a.Bootstrap
if err := w.Run(root, data); err != nil {
return errors.WithStack(err)
}
} else {
if err := standard.Run(root, data); err != nil {
return errors.WithStack(err)
}
}
if err := a.setupWebpack(root, data); err != nil {
return errors.WithStack(err)
}
if a.WithPop {
sg := soda.New()
sg.App = a.App
sg.Dialect = a.DBType
data["appPath"] = a.Root
data["name"] = a.Name.File()
if err := sg.Run(root, data); err != nil {
return errors.WithStack(err)
}

if err := a.setupPop(root, data); err != nil {
return errors.WithStack(err)
}

if a.Docker != "none" {
o := docker.New()
o.App = a.App
o.Version = a.Version
if err := o.Run(root, data); err != nil {
return errors.WithStack(err)
}
if err := a.setupDocker(root, data); err != nil {
return errors.WithStack(err)
}

g.Add(makr.NewCommand(a.goGet()))

g.Add(makr.Func{
Expand All @@ -117,19 +82,104 @@ func (a Generator) Run(root string, data makr.Data) error {
},
})

if a.VCS == "git" || a.VCS == "bzr" {
// Execute git or bzr case (same CLI API)
if _, err := exec.LookPath(a.VCS); err == nil {
g.Add(makr.NewCommand(exec.Command(a.VCS, "init")))
g.Add(makr.NewCommand(exec.Command(a.VCS, "add", ".")))
g.Add(makr.NewCommand(exec.Command(a.VCS, "commit", "-m", "Initial Commit")))
}
}
a.setupVCS(g)

data["opts"] = a
return g.Run(root, data)
}

func (a Generator) setupVCS(g *makr.Generator) {
if a.VCS != "git" && a.VCS != "bzr" {
return
}
// Execute git or bzr case (same CLI API)
if _, err := exec.LookPath(a.VCS); err != nil {
return
}

g.Add(makr.NewCommand(exec.Command(a.VCS, "init")))
g.Add(makr.NewCommand(exec.Command(a.VCS, "add", ".")))
g.Add(makr.NewCommand(exec.Command(a.VCS, "commit", "-m", "Initial Commit")))
}

func (a Generator) setupDocker(root string, data makr.Data) error {
if a.Docker == "none" {
return nil
}

o := docker.New()
o.App = a.App
o.Version = a.Version
if err := o.Run(root, data); err != nil {
return errors.WithStack(err)
}

return nil
}

func (a Generator) setupPop(root string, data makr.Data) error {
if !a.WithPop {
return nil
}

sg := soda.New()
sg.App = a.App
sg.Dialect = a.DBType
data["appPath"] = a.Root
data["name"] = a.Name.File()

if err := sg.Run(root, data); err != nil {
return errors.WithStack(err)
}

return nil
}

func (a Generator) setupWebpack(root string, data makr.Data) error {
if a.AsAPI {
return nil
}

if a.WithWebpack {
w := webpack.New()
w.App = a.App
w.Bootstrap = a.Bootstrap
if err := w.Run(root, data); err != nil {
return errors.WithStack(err)
}

return nil
}

if err := standard.Run(root, data); err != nil {
return errors.WithStack(err)
}

return nil
}

func (a Generator) setupCI(g *makr.Generator, data makr.Data) {

switch a.CIProvider {
case "travis":
g.Add(makr.NewFile(".travis.yml", nTravis))
case "gitlab-ci":
if a.WithPop {
if a.DBType == "postgres" {
data["testDbUrl"] = "postgres://postgres:postgres@postgres:5432/" + a.Name.File() + "_test?sslmode=disable"
} else if a.DBType == "mysql" {
data["testDbUrl"] = "mysql://root:root@(mysql:3306)/" + a.Name.File() + "_test"
} else {
data["testDbUrl"] = ""
}
g.Add(makr.NewFile(".gitlab-ci.yml", nGitlabCi))
break
}

g.Add(makr.NewFile(".gitlab-ci.yml", nGitlabCiNoPop))
}
}

func (a Generator) goGet() *exec.Cmd {
cd, _ := os.Getwd()
defer os.Chdir(cd)
Expand Down
13 changes: 5 additions & 8 deletions logger_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"os"
"regexp"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -118,15 +119,11 @@ func (f *textFormatter) needsQuoting(text string) bool {
if len(text) == 0 {
return true
}
for _, ch := range text {
if !((ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9') ||
ch == '-' || ch == '.' || ch == '_' || ch == '/' || ch == '@' || ch == '^' || ch == '+') {
return true
}
matched, err := regexp.MatchString("[^a-zA-Z\\-\\._\\/@\\^\\+]", text)
if err != nil {
return false
}
return false
return matched
}

func (f *textFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion mail/mail.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mail

// Sender interface for any upcomming mailers.
// Sender interface for any upcoming mailers.
type Sender interface {
Send(Message) error
}
1 change: 0 additions & 1 deletion route.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func addExtraParamsTo(path string, opts map[string]interface{}) string {
}

path = path + fmt.Sprintf(format, url.QueryEscape(k), url.QueryEscape(pendingParams[k]))
index = index + 1
}

return path
Expand Down