Skip to content

Commit

Permalink
fixes. v.1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
monomonedula committed Mar 29, 2023
1 parent 07a2758 commit ff148df
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ GLOBAL OPTIONS:
--help, -h show help
```


Example output:
```json
[{"id":"209-c992021","ticket":"209","estimate":30,"role":"DEV","lines":"3-5","body":"whatever 1234. Please fix soon 1.","file":"/home/user/gopdd/resources/foobar.py","author":"monomonedula","email":"email@xxx.xyz","time":"2023-03-26T23:27:31+03:00"},{"id":"321-b7bbd66","ticket":"321","estimate":60,"role":"DEV","lines":"9-11","body":"very important issue. Please fix soon 2.","file":"/home/user/gopdd/resources/foobar.py","author":"monomonedula","email":"email@xxx.xyz","time":"2023-03-26T23:27:31+03:00"}]
```
2 changes: 1 addition & 1 deletion cmd/gopdd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
&cli.StringFlag{
Name: "source",
Value: ".",
Usage: "Source directory to parse ('.' by default)",
Usage: "Source directory to parse",
Aliases: []string{"s"},
},
&cli.StringFlag{
Expand Down
21 changes: 21 additions & 0 deletions pkg/gopdd/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gopdd

import (
"encoding/json"
"errors"
"os"
"runtime"
"runtime/debug"
Expand Down Expand Up @@ -49,6 +50,10 @@ func (b Base) Puzzles(skipErrors bool) []Puzzle {
puzzles = append(puzzles, p)
}
}
err = b.ApplyRules(puzzles)
if err != nil {
panic(err)
}
return puzzles
}

Expand All @@ -59,3 +64,19 @@ func (b Base) JsonPuzzles(skipErrors bool) []byte {
}
return out
}

func (b Base) ApplyRules(puzzles []Puzzle) error {
total := 0
for _, rule := range b.Rules {
errors := rule.ApplyTo(puzzles)
total += len(errors)
for _, err := range errors {
b.Logger.Error(err)
}
}
if total == 0 {
return nil
}
b.Logger.Errorf("Got %d errors. See logs above", total)
return errors.New("puzzles do not comply with the rules")
}
17 changes: 0 additions & 17 deletions pkg/gopdd/rules.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gopdd

import (
"errors"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -136,22 +135,6 @@ func (r AvailableRolesRule) ApplyTo(puzzles []Puzzle) []string {
return errors
}

func (b Base) ApplyRules(puzzles []Puzzle) error {
total := 0
for _, rule := range b.Rules {
errors := rule.ApplyTo(puzzles)
total += len(errors)
for _, err := range errors {
b.Logger.Error(err)
}
}
if total == 0 {
return nil
}
b.Logger.Errorf("Got %d errors. See logs above", total)
return errors.New("puzzles do not comply with the rules")
}

func RulesOf(rulesstrings []string) []Rule {
var rules []Rule
for _, rulestr := range rulesstrings {
Expand Down

0 comments on commit ff148df

Please sign in to comment.