Skip to content

Commit

Permalink
merge: branch 'release/0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sascha-andres committed Sep 17, 2019
2 parents 6b657a2 + d4b00c1 commit b4e59dd
Show file tree
Hide file tree
Showing 15 changed files with 539 additions and 127 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Go

on: [push, pull_request]

jobs:
test:
strategy:
matrix:
go-version: [1.12.9, 1.13]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v1
- name: Test
run: go test ./...
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ This is in an early phase but used regularly with the toggl backend and from tim

|Version|Description|
|---|---|
|0.5.0|add support for daily summary|
||better output for entry duration|
|0.4.0|add project command|
|0.3.0|Add cli|
||Open in browser|
Expand Down
33 changes: 10 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,43 +1,30 @@
module livingit.de/code/timenote

require (
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 // indirect
github.com/chzyer/logex v1.1.10 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
github.com/coreos/etcd v3.3.13+incompatible // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/go-sql-driver/mysql v1.4.1
github.com/golang/protobuf v1.3.1 // indirect
github.com/google/gops v0.3.6
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mgutz/str v1.2.0
github.com/mitchellh/go-homedir v1.1.0
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/onsi/ginkgo v1.10.1
github.com/onsi/gomega v1.7.0
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
github.com/pkg/errors v0.8.1
github.com/russross/blackfriday v2.0.0+incompatible // indirect
github.com/sascha-andres/go-toggl v0.0.0-20190124051419-9384593946d2
github.com/shirou/gopsutil v2.18.12+incompatible // indirect
github.com/sascha-andres/go-toggl v1.1.0
github.com/sirupsen/logrus v1.4.2
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cobra v0.0.4
github.com/spf13/cobra v0.0.5
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.3.2
github.com/stretchr/objx v0.2.0 // indirect
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect
golang.org/x/net v0.0.0-20190520210107-018c4d40a106 // indirect
golang.org/x/sys v0.0.0-20190522034248-c46e0d965b18 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/tools v0.0.0-20190521203540-521d6ed310dd // indirect
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
rsc.io/goversion v1.2.0 // indirect
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.3.0 // indirect
golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae // indirect
google.golang.org/appengine v1.6.1 // indirect
)

go 1.13
190 changes: 111 additions & 79 deletions go.sum

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions persistence/mysqldriver/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,7 @@ func (mysql *MySQLPersistor) Clients() ([]timenote.Client, error) {
func (mysql *MySQLPersistor) NewClient(name string) error {
return errors.New("not yet implemented")
}

func (mysql *MySQLPersistor) ListForDay() ([]timenote.TimeEntry, error) {
return nil, errors.New("not yet implemented")
}
4 changes: 2 additions & 2 deletions persistence/storage_persistor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type Persistor interface {
Done() error
// Close the connection to the persistence backend
Close() error
// List of entries for the current day - delta
// ListForDay(delta int) ([]timenote.TimeEntry, error)
// List of entries for the current day
ListForDay() ([]timenote.TimeEntry, error)
// Get currently running time entry
Current() (*timenote.TimeEntry, error)
// GetWebsite returns a URL to the time management system
Expand Down
24 changes: 24 additions & 0 deletions persistence/toggldriver/toggl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package toggldriver
import (
"fmt"
"github.com/pkg/errors"
"time"

"github.com/sascha-andres/go-toggl"
"livingit.de/code/timenote"
Expand Down Expand Up @@ -208,3 +209,26 @@ func (t *TogglPersistor) NewClient(name string) error {
_, err = t.session.CreateClient(name, account.Data.Workspaces[0].ID)
return err
}

func (t *TogglPersistor) ListForDay() ([]timenote.TimeEntry, error) {
year, month, day := time.Now().Date()
loc, _ := time.LoadLocation("")
startDate := time.Date(year, month, day, 0, 0, 0, 0, loc)
endDate := time.Date(year, month, day, 23, 59, 59, 0, loc)
entries, err := t.session.GetTimeEntries(startDate, endDate)
if err != nil {
return nil, err
}
result := make([]timenote.TimeEntry, 0)
for _, entry := range entries {
result = append(result, timenote.TimeEntry{
ID: entry.ID,
Tag: fmt.Sprintf("%v", entry.Tags),
Note: entry.Description,
Start: *entry.Start,
Stop: entry.Stop,
Duration: entry.Duration,
})
}
return result, nil
}
19 changes: 15 additions & 4 deletions timeentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,25 @@ type (
)

func (te *TimeEntry) String() string {
humanTime := ""
if te.Duration < 0 {
t := time.Now().UTC().Add(time.Duration(te.Duration) * time.Second)
humanTime = t.Format("15:04:05")
} else {
td, err := NewTogglDuration(te.Duration)
if err != nil {
panic(err)
}
humanTime = td.String()
}
if "[]" == te.Tag {
if "" == te.Note {
return fmt.Sprintf("duration: %s\n", te.Start.Format("15:04:05"))
return fmt.Sprintf("duration: %s\n", humanTime)
}
return fmt.Sprintf("duration: %s\nnote: %s\n", te.Start.Format("15:04:05"), te.Note)
return fmt.Sprintf("duration: %s\nnote: %s\n", humanTime, te.Note)
}
if "" == te.Note {
return fmt.Sprintf("duration: %s - tags:%s\n", te.Start.Format("15:04:05"), te.Tag)
return fmt.Sprintf("duration: %s - tags:%s\n", humanTime, te.Tag)
}
return fmt.Sprintf("duration: %s - tags:%s\n%s\n", te.Start.Format("15:04:05"), te.Tag, te.Note)
return fmt.Sprintf("duration: %s - tags:%s\n%s\n", humanTime, te.Tag, te.Note)
}
18 changes: 3 additions & 15 deletions timenote/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build:
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
binary: devenv
binary: timenote
env:
- CGO_ENABLED=0
goos:
Expand All @@ -9,24 +9,12 @@ build:
- freebsd
goarch:
- amd64
- arm
- arm64
goarm:
- 6
- 7
ignore:
- goos: freebsd
goarch: arm
goarm: 7
- goos: freebsd
goarch: arm
goarm: 6
snapshot:
name_template: "{{.Commit}}"
fpm:
nfpm:
vendor: Sascha Andres
homepage: https://livingit.de/code/timenote/
description: timenote is a tool to take notes with timestamps. You can choose between two different backends
license: Apache 2.0
formats:
- deb
- deb
2 changes: 1 addition & 1 deletion timenote/cmd/timestamp_current.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ package cmd
import (
"fmt"

"livingit.de/code/timenote/persistence/factory"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"livingit.de/code/timenote/persistence/factory"
)

// timestampCurrentCmd represents the current command
Expand Down
53 changes: 53 additions & 0 deletions timenote/cmd/timestamp_description.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright © 2018 Sascha Andres <sascha.andres@outlook.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"livingit.de/code/timenote/persistence/factory"
)

// timestampCurrentCmd represents the current command
var timestampDescriptionCmd = &cobra.Command{
Use: "description",
Short: "Print current timestamp description",
Long: `Prints the current timestamp's description`,
Run: func(cmd *cobra.Command, args []string) {
persistence, err := factory.CreatePersistence(viper.GetString("persistor"), viper.GetString("dsn"))
if err != nil {
log.Fatal(err)
}
defer func() {
err := persistence.Close()
if err != nil {
log.Fatal(err)
}
}()

ts, err := persistence.Current()
if err != nil {
log.Error(err)
return
}
fmt.Println(ts.Note)
},
}

func init() {
timestampCmd.AddCommand(timestampDescriptionCmd)
}
21 changes: 18 additions & 3 deletions timenote/cmd/timestamp_duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"livingit.de/code/timenote"
"livingit.de/code/timenote/persistence/factory"
"time"
)
Expand Down Expand Up @@ -46,15 +47,29 @@ hh:mm:ss'`,
log.Error(err)
return
}
if ts.Duration != 0 {
var td *timenote.TogglDuration
if ts.Duration < 0 {
t := time.Now().UTC().Add(time.Duration(ts.Duration) * time.Second)
fmt.Printf("%s %s - %s", ts.Tag, t.Format("15:04:05"), ts.Note)
td, err = timenote.TogglDurationFromTime(t)
if err != nil {
panic(err)
}
} else {
fmt.Println("not supported for storage type")
td, err = timenote.NewTogglDuration(ts.Duration)
if err != nil {
panic(err)
}
}
if !viper.GetBool("timestamp.duration.include-seconds") {
td.OmitSeconds()
}
fmt.Println(td.String())
},
}

func init() {
timestampCmd.AddCommand(timestampDurationCmd)

timestampDurationCmd.Flags().BoolP("include-seconds", "", true, "Include seconds when writing out time entry")
_ = viper.BindPFlag("timestamp.duration.include-seconds", timestampDurationCmd.Flags().Lookup("include-seconds"))
}
Loading

0 comments on commit b4e59dd

Please sign in to comment.