Skip to content

Commit

Permalink
- added new config period.timeframe, period.every
Browse files Browse the repository at this point in the history
  • Loading branch information
maZahaca committed Oct 19, 2021
1 parent f092b4b commit 28d3110
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ tracker:
- type: toggl
token: "token-from-toggl"

period:
timeframe: 2w
every: 1d

# places to sync time entries with
sync:
- type: jira
Expand All @@ -40,6 +44,8 @@ sync:
- DEV
```
- `timeframe` - look for timeframe in the past for new entries
- `every` - for `--service` mode, how often to repeat sync
- `projects` it's a list of project keys in Jira.

## Run the app
Expand Down
4 changes: 4 additions & 0 deletions config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ tracker:
- type: toggl
token: "token-from-toggl"

period:
timeframe: 2w
every: 1d

# places to sync time entries with
sync:
- type: jira
Expand Down
22 changes: 17 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,34 @@ func main() {
Usage: "Sync time entries from timers with task trackers",
Flags: []cli.Flag{
cli.StringFlag{
Name: "period",
Value: "1d",
Name: "period",
},
cli.BoolFlag{
Name: "service",
},
},
Action: func(c *cli.Context) error {
service := c.Bool("service")
duration, err := utils.ParseDuration(c.String("period"))
t := viper.GetString("period.timeframe")
p := c.String("period")
if p != "" {
t = p
}
lookupTimeframe, err := utils.ParseDuration(t)
if err != nil {
log.Fatal(err)
}
e := viper.GetString("period.every")
if e == "" {
e = t
}
every, err := utils.ParseDuration(e)
if err != nil {
log.Fatal(err)
}

end := time.Now()
start := end.Add(-duration)
start := end.Add(-lookupTimeframe)

tr := viper.Get("tracker").([]interface{})
trackerSvc, err := trackers.NewTogglTracker((tr[0]).(map[interface{}]interface{}))
Expand All @@ -84,7 +96,7 @@ func main() {
log.Fatal(err)
}
if service {
ticker := time.NewTicker(duration)
ticker := time.NewTicker(every)
quit := make(chan error, 1)
go func() {
for {
Expand Down

0 comments on commit 28d3110

Please sign in to comment.