Skip to content

Commit

Permalink
🐛 Ignore the errors if the project layout is already on same type
Browse files Browse the repository at this point in the history
  • Loading branch information
prafull01 committed Nov 2, 2020
1 parent 70108bf commit d45b242
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
24 changes: 14 additions & 10 deletions pkg/plugin/v2/scaffolds/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func NewEditScaffolder(config *config.Config, multigroup bool) scaffold.Scaffold

// Scaffold implements Scaffolder
func (s *editScaffolder) Scaffold() error {
s.config.MultiGroup = s.multigroup
filename := "Dockerfile"
bs, err := ioutil.ReadFile(filename)
if err != nil {
Expand All @@ -56,21 +55,26 @@ func (s *editScaffolder) Scaffold() error {
str,
"COPY api/ api/",
`COPY apis/ apis/`)
if err != nil {
return err
}
} else {
str, err = ensureExistAndReplace(
str,
"COPY apis/ apis/",
`COPY api/ api/`)
if err != nil {
return err
}
}
// false positive
// nolint:gosec
return ioutil.WriteFile(filename, []byte(str), 0644)

if err != nil && s.multigroup != s.config.MultiGroup {
return err
}

s.config.MultiGroup = s.multigroup

if str != "" {
// false positive
// nolint:gosec
return ioutil.WriteFile(filename, []byte(str), 0644)
}

return nil
}

func ensureExistAndReplace(input, match, replace string) (string, error) {
Expand Down
25 changes: 15 additions & 10 deletions pkg/plugin/v3/scaffolds/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func NewEditScaffolder(config *config.Config, multigroup bool) scaffold.Scaffold

// Scaffold implements Scaffolder
func (s *editScaffolder) Scaffold() error {
s.config.MultiGroup = s.multigroup
filename := "Dockerfile"
bs, err := ioutil.ReadFile(filename)
if err != nil {
Expand All @@ -56,21 +55,27 @@ func (s *editScaffolder) Scaffold() error {
str,
"COPY api/ api/",
`COPY apis/ apis/`)
if err != nil {
return err
}

} else {
str, err = ensureExistAndReplace(
str,
"COPY apis/ apis/",
`COPY api/ api/`)
if err != nil {
return err
}
}
// false positive
// nolint:gosec
return ioutil.WriteFile(filename, []byte(str), 0644)

if err != nil && s.multigroup != s.config.MultiGroup {
return err
}

s.config.MultiGroup = s.multigroup

if str != "" {
// false positive
// nolint:gosec
return ioutil.WriteFile(filename, []byte(str), 0644)
}

return nil
}

func ensureExistAndReplace(input, match, replace string) (string, error) {
Expand Down

0 comments on commit d45b242

Please sign in to comment.