Skip to content

Commit

Permalink
Merge pull request #5 from smlx/fix-end-ignore
Browse files Browse the repository at this point in the history
Handle ending timesheet with an ignore block
  • Loading branch information
smlx authored Jul 21, 2021
2 parents d5c9102 + 19779b2 commit 6e4f320
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/parse/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,9 @@ var timesheetTransitions = []fsm.Transition{
Src: gotImplicitIssue,
Event: eof,
Dst: end,
}, {
Src: start,
Event: eof,
Dst: end,
},
}
5 changes: 4 additions & 1 deletion internal/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ func Input(r io.Reader, c *config.Config) (map[string][]Worklog, error) {
},
},
end: {
func(e fsm.Event, _ fsm.State) error {
func(_ fsm.Event, s fsm.State) error {
if s == start {
return nil
}
addWorklog(worklogs, &timesheet)
return nil
},
Expand Down
28 changes: 28 additions & 0 deletions internal/parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,34 @@ func TestParseInput(t *testing.T) {
},
},
},
"worklog2": {
input: &parseInput{
dataFile: "testdata/worklog2",
config: &config.Config{
Issues: []config.Issue{
{
ID: "ADMIN-1",
Regexes: wrapRegexes([]string{
"^admin$",
}),
},
},
Ignore: wrapRegexes([]string{
"^lunch$",
}),
},
},
expect: map[string][]parse.Worklog{
"ADMIN-1": {
{
Started: time.Date(now.Year(), now.Month(), now.Day(), 9, 0, 0,
0, now.Location()),
Duration: 45 * time.Minute,
Comment: "",
},
},
},
},
}
for name, tc := range testCases {
t.Run(name, func(tt *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions internal/parse/testdata/worklog2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0900-0945
admin
1200-1300
lunch

0 comments on commit 6e4f320

Please sign in to comment.