Skip to content

Commit

Permalink
Merge pull request #9 from Goutte/feat-adapt-to-actual-usage
Browse files Browse the repository at this point in the history
Improve the overall reliability
  • Loading branch information
Goutte authored Apr 6, 2024
2 parents 203cfd9 + 4d3572e commit ff502ec
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 79 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.20"

Expand All @@ -28,7 +28,9 @@ jobs:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3
- name: Checkout the source repository
# https://github.com/actions/checkout
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
Expand All @@ -37,7 +39,7 @@ jobs:
run: git fetch --tags origin main

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
# Integration testing with coverage requires >=1.20
go-version: ">=1.20"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install upx
run: sudo apt install upx
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ">=1.20"
- name: Generate the artifacts
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ sudo git spend man --install
Develop
-------

First, you'll need to [install Golang](https://go.dev/dl/).

```
git clone https://github.com/Goutte/git-spend.git
cd git-spend
Expand All @@ -258,6 +260,10 @@ make install
[`upx`]: https://upx.github.io/

---

You can compare the checksums, and they should be the same unless microsoft is being naughty.


### Build for other platforms

Expand Down
1 change: 1 addition & 0 deletions gitime/gitime.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var expressions = []*regexp.Regexp{
// If no time unit is specified, minutes are assumed.
func CollectTimeSpent(message string) *TimeSpent {
ts := &TimeSpent{}
message = strings.ReplaceAll(message, "\r", "\n")
lines := strings.Split(message, "\n")

for _, line := range lines {
Expand Down
11 changes: 11 additions & 0 deletions gitime/gitime_test_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ collect:
expected:
minutes: 60

- rule: Allow alias /spent (/spent 0.5h)
message: |
/spent 0.5h
expected:
minutes: 30

- rule: Allow full units (/spend 1 hour 10 minutes)
message: |
/spend 1 hour 10 minutes
Expand Down Expand Up @@ -201,6 +207,11 @@ collect:
expected:
minutes: 120

- rule: Handle Windows carriage returns as newlines
message: "style: main menu fixed\r/spent 0.5h"
expected:
minutes: 30

- rule: Tolerate missing space typo (/spend3h)
message: |
/spend3h
Expand Down
2 changes: 1 addition & 1 deletion gitime/grammar.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package gitime

import "regexp"

var commandRegex = "/spen[dt]\\s*:?\\s*"
var commandRegex = "^\\s*/spen[dt]\\s*:?\\s*"
var floatRegex = "[0-9]+[.]?[0-9]*|[0-9]*[.]?[0-9]+"

// no negative lookahead in regexp, so we hack around it (to ignore datetime suffix)
Expand Down
10 changes: 8 additions & 2 deletions gitime/reader/git_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ func ReadGitLog(onlyAuthors []string, excludeMerge bool, since string, until str
continue
}

s += commit.Subject + "\n"
s += commit.Body + "\n"
// We read from the raw body because some newlines are eaten when separating subject an body.
// My non-tech friend commits without separating subject and body, like this:
// > style: something amazing
// > /spent 0.5h
// … and the "/spend 0.5h" ends up at the end of the Subject, without newline.
s += commit.RawBody + "\n"
// We also read from the note, and it might or might not be correct.
s += commit.Note + "\n"
}

return s
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ require (

replace github.com/spf13/cobra => github.com/Goutte/cobra v0.0.0-20230404093907-b279579671a9

replace github.com/tsuyoshiwada/go-gitlog => github.com/Goutte/go-gitlog v0.0.0-20240406102306-1efcfa30a305

require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -31,6 +33,8 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/sys v0.3.0 // indirect
github.com/tsuyoshiwada/go-gitcmd v0.0.0-20180205145712-5f1f5f9475df // indirect
golang.org/x/sys v0.19.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
13 changes: 8 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Goutte/cobra v0.0.0-20230404093907-b279579671a9 h1:6DqPA8KTHj+BmPBB5J7viX8jgPxuYcLqoUjxj+IfemQ=
github.com/Goutte/cobra v0.0.0-20230404093907-b279579671a9/go.mod h1:kKQTiXzwhSqS83iXVA/L4jqCpe2jy7X+14DyQ1wmImI=
github.com/Goutte/go-gitlog v0.0.0-20240406102306-1efcfa30a305 h1:IM41iOGTwRv6w/zV5emUaLia4j3a8AKsfIZ/OK/xDo8=
github.com/Goutte/go-gitlog v0.0.0-20240406102306-1efcfa30a305/go.mod h1:nVMD+1UEtGO3Dl5TrjnZUmawWuLs/fp83Vwq77MXO98=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
Expand Down Expand Up @@ -180,8 +182,8 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/tsuyoshiwada/go-gitlog v0.0.1 h1:ZBIfQG2IUmguQzP8llKgAxUvorcYnI+OhzWXi1vpv38=
github.com/tsuyoshiwada/go-gitlog v0.0.1/go.mod h1:kfjd4M5xSFPqL0Mp2pAk0WM9hP9pJkLQiAndAoQHSRc=
github.com/tsuyoshiwada/go-gitcmd v0.0.0-20180205145712-5f1f5f9475df h1:Y2l28Jr3vOEeYtxfVbMtVfOdAwuUqWaP9fvNKiBVeXY=
github.com/tsuyoshiwada/go-gitcmd v0.0.0-20180205145712-5f1f5f9475df/go.mod h1:pnyouUty/nBr/zm3GYwTIt+qFTLWbdjeLjZmJdzJOu8=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -324,8 +326,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -488,8 +490,9 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
Loading

0 comments on commit ff502ec

Please sign in to comment.