Skip to content

Commit

Permalink
Release v0.1.1 (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
kilpkonn committed Dec 16, 2020
2 parents 83251a9 + 424e82e commit 12094b4
Show file tree
Hide file tree
Showing 12 changed files with 734 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/develop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
submodules: true
- name: Install apt dependecies
run: |
sudo apt-get install libgit2-dev libssh2-1-dev libssl-dev cmake
sudo apt-get update && sudo apt-get install libgit2-dev libssh2-1-dev libssl-dev cmake
- name: Install go dependencies
run: |
go get -d github.com/Masterminds/sprig
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
- uses: crazy-max/ghaction-chocolatey@v1
with:
args: -h
- name: Install pkg config
- name: Install dependecies
run: |
choco install pkgconfiglite
- name: Install Go
Expand All @@ -87,7 +87,7 @@ jobs:
cd vendor/libgit2
new-item -Name "build" -ItemType directory
cd build
cmake -DCMAKE_INSTALL_PREFIX=D:\a\gtm-enhanced\gtm-enhanced\src\github.com\libgit2\git2go\vendor\libgit2\install ..
cmake -DUSE_SSH=OFF -DCMAKE_INSTALL_PREFIX=D:\a\gtm-enhanced\gtm-enhanced\src\github.com\libgit2\git2go\vendor\libgit2\install ..
cmake --build . --target install
- name: Build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
submodules: true
- name: Install apt dependecies
run: |
sudo apt-get install libgit2-dev libssh2-1-dev libssl-dev cmake
sudo apt-get update && sudo apt-get install libgit2-dev libssh2-1-dev libssl-dev cmake
- name: Install go dependencies
run: |
go get -d github.com/Masterminds/sprig
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
submodules: true
- name: Install apt dependecies
run: |
sudo apt-get install libgit2-dev libssh2-1-dev libssl-dev cmake
sudo apt-get update && sudo apt-get install libgit2-dev libssh2-1-dev libssl-dev cmake
- name: Install go dependencies
run: |
go get -d github.com/Masterminds/sprig
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
cd vendor/libgit2
new-item -Name "build" -ItemType directory
cd build
cmake -DCMAKE_INSTALL_PREFIX=D:\a\gtm-enhanced\gtm-enhanced\src\github.com\libgit2\git2go\vendor\libgit2\install ..
cmake -DUSE_SSH=OFF -DCMAKE_INSTALL_PREFIX=D:\a\gtm-enhanced\gtm-enhanced\src\github.com\libgit2\git2go\vendor\libgit2\install ..
cmake --build . --target install
- name: Build
run: |
Expand Down
674 changes: 674 additions & 0 deletions LICENCE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Usage: gtm init [options]
Options:
-terminal=true Enable time tracking for terminal (requires Terminal plug-in).
-auto-log="" Enable automatic logging to commits for platform [gitlab].
-auto-log="" Enable automatic logging to commits for platform [gitlab, jira].
-local=false Initialize gtm locally, ak no push / fetch hooks are added.
-tags=tag1,tag2 Add tags to projects, multiple calls appends tags.
-clear-tags Clear all tags.
Expand Down
5 changes: 4 additions & 1 deletion command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Options:
-long-duration If total-only, display total pending time in long duration format
-tags="" Project tags to report status for, i.e --tags tag1,tag2
-all=false Show status for all projects
-auto-log="" Format output for auto logging time [gitlab, jira]
-cwd="" Set cwd (useful for plugins)
`
return strings.TrimSpace(helpText)
Expand All @@ -51,7 +52,7 @@ Options:
// Run executes status command with args
func (c StatusCmd) Run(args []string) int {
var color, terminalOff, appOff, totalOnly, all, profile, longDuration bool
var tags, cwd string
var tags, cwd, autoLog string
cmdFlags := flag.NewFlagSet("status", flag.ContinueOnError)
cmdFlags.BoolVar(&color, "color", false, "Always output color even if no terminal is detected. Use this with pagers i.e 'less -R' or 'more -R'")
cmdFlags.BoolVar(&terminalOff, "terminal-off", false, "Exclude time spent in terminal (Terminal plugin is required)")
Expand All @@ -60,6 +61,7 @@ func (c StatusCmd) Run(args []string) int {
cmdFlags.BoolVar(&longDuration, "long-duration", false, "Display total time in long duration format")
cmdFlags.StringVar(&tags, "tags", "", "Project tags to show status on")
cmdFlags.BoolVar(&all, "all", false, "Show status for all projects")
cmdFlags.StringVar(&autoLog, "auto-log", "", "Format time for auto logging")
cmdFlags.StringVar(&cwd, "cwd", "", "Set cwd")
cmdFlags.BoolVar(&profile, "profile", false, "Enable profiling")
cmdFlags.Usage = func() { c.UI.Output(c.Help()) }
Expand Down Expand Up @@ -102,6 +104,7 @@ func (c StatusCmd) Run(args []string) int {

options := report.OutputOptions{
TotalOnly: totalOnly,
AutoLog: autoLog,
LongDuration: longDuration,
TerminalOff: terminalOff,
AppOff: appOff,
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Licence
See `LICENCE` to see licence included from `Git-Time-Metrics/gtm`.
This is only here as it has to be included. This project is not listed under MIT licence. See licence in root directory to see
licence of this repo.
2 changes: 1 addition & 1 deletion project/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (i *Index) path() (string, error) {
if err != nil {
return "", err
}
return filepath.Join(u.HomeDir, ".git-time-metric", "project.json"), nil
return filepath.Join(u.HomeDir, ".gtm", "project.json"), nil
}

func (i *Index) load() error {
Expand Down
27 changes: 19 additions & 8 deletions project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ var (
}
// GitConfig is map of git configuration settingsx
GitConfig = map[string]string{
"alias.pushgtm": "push origin refs/notes/gtm-data",
"alias.fetchgtm": "fetch origin refs/notes/gtm-data:refs/notes/gtm-data",
"notes.rewriteref": "refs/notes/gtm-data"}
"alias.pushgtm": "push origin refs/notes/gtm-data",
"alias.fetchgtm": "fetch origin refs/notes/gtm-data:refs/notes/gtm-data",
"notes.rewriteRef": "refs/notes/gtm-data",
"notes.rewriteMode": "concatenate"}
// GitIgnore is file ignore to apply to git repo
GitIgnore = "/.gtm/"

Expand All @@ -63,10 +64,18 @@ var (
GitLabHooks = map[string]scm.GitHook{
"prepare-commit-msg": {
Exe: "git",
Command: "echo -n \"/spend \" >> $1; gtm status -total-only >> $1",
Command: "gtm status --auto-log=gitlab >> $1",
RE: regexp.MustCompile(
`(?s)[/:a-zA-Z0-9$_=()"\.\|\-\\ ]*echo\s+-n\s+"/spend\s+"\s+>>\s+\$1;` +
`\s+gtm(.exe"|)\s+status\s+-total-only\s+>>\s+\$1\.*`),
`(?s)[/:a-zA-Z0-9$_=()"\.\|\-\\ ]*gtm(.exe"|)\s+status\s+--auto-log=gitlab\s+>>\s+\$1\.*`),
},
}

JiraHooks = map[string]scm.GitHook{
"prepare-commit-msg": {
Exe: "git",
Command: "gtm status --auto-log=jira >> $1",
RE: regexp.MustCompile(
`(?s)[/:a-zA-Z0-9$_=()"\.\|\-\\ ]*gtm(.exe"|)\s+status\s+--auto-log=jira\s+>>\s+\$1\.*`),
},
}
)
Expand Down Expand Up @@ -220,8 +229,10 @@ func SetupHooks(local bool, gitRepoPath, autoLog string) error {
for k, v := range GitLabHooks {
GitHooks[k] = v
}
case "github":
// TODO Add hooks
case "jira":
for k, v := range JiraHooks {
GitHooks[k] = v
}
}

if err := scm.SetHooks(GitHooks, gitRepoPath); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type OutputOptions struct {
Color bool
Limit int
Subdir string
AutoLog string
}

func (o OutputOptions) limitNotes(notes commitNoteDetails) commitNoteDetails {
Expand All @@ -64,6 +65,13 @@ func Status(n note.CommitNote, options OutputOptions, projPath ...string) (strin
n = n.FilterOutApp()
}

switch options.AutoLog {
case "gitlab":
return fmt.Sprintf("/spend %s", util.DurationStr(n.Total())), nil
case "jira":
return fmt.Sprintf("#time %s", util.DurationStrJira(n.Total())), nil
}

if options.TotalOnly {
if options.LongDuration {
return util.DurationStrLong(n.Total()), nil
Expand Down
17 changes: 17 additions & 0 deletions util/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import (
"github.com/hako/durafmt"
)

const (
SecInMinute = 60
MinInHour = 60
HoursInDay = 8
DaysInWeek = 5
)

// Percent returns a values percent of the total
func Percent(val, total int) float64 {
if total == 0 {
Expand Down Expand Up @@ -43,6 +50,16 @@ func DurationStr(secs int) string {
return (time.Duration(secs) * time.Second).String()
}

// DurationStrJira returns seconds as duration string, i.e. 1d 9h 10m
func DurationStrJira(secs int) string {
total := (time.Duration(secs) * time.Second).Truncate(time.Second).Seconds()
weeks := int(total / (DaysInWeek * HoursInDay * MinInHour * SecInMinute))
days := int(total/(HoursInDay*MinInHour*SecInMinute)) % DaysInWeek
hours := int(total/(MinInHour*SecInMinute)) % HoursInDay
minutes := int(total/SecInMinute) % SecInMinute
return fmt.Sprintf("%dw %dd %dh %dm", weeks, days, hours, minutes)
}

// DurationStrLong returns a human readable format for the duration
func DurationStrLong(secs int) string {
d, err := durafmt.ParseString(DurationStr(secs))
Expand Down

0 comments on commit 12094b4

Please sign in to comment.