Skip to content

Commit d70176c

Browse files
committed
report total project hours
1 parent ba9e325 commit d70176c

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

command/report.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Options:
4141
4242
Report Formats:
4343
44-
-format=commits Specify report format [summary|commits|files|timeline-hours|timeline-commits] (default commits)
44+
-format=commits Specify report format [summary|project|commits|files|timeline-hours|timeline-commits] (default commits)
4545
-full-message=false Include full commit message
4646
-terminal-off=false Exclude time spent in terminal (Terminal plug-in is required)
4747
-force-color=false Always output color even if no terminal is detected, i.e 'gtm report -color | less -R'
@@ -103,7 +103,7 @@ func (c ReportCmd) Run(args []string) int {
103103
return 1
104104
}
105105

106-
if !util.StringInSlice([]string{"summary", "commits", "timeline-hours", "files", "timeline-commits"}, format) {
106+
if !util.StringInSlice([]string{"summary", "commits", "timeline-hours", "files", "timeline-commits", "project"}, format) {
107107
c.Ui.Error(fmt.Sprintf("report --format=%s not valid\n", format))
108108
return 1
109109
}
@@ -175,6 +175,12 @@ func (c ReportCmd) Run(args []string) int {
175175
return 1
176176
}
177177

178+
// hack, if project format we want all commits for the project
179+
if format == "project" && limit == 0 {
180+
// set max to absurdly high value for number of possible commits
181+
limit = 2147483647
182+
}
183+
178184
limiter, err := scm.NewCommitLimiter(
179185
limit, fromDate, toDate, author, message,
180186
today, yesterday, thisWeek, lastWeek,
@@ -204,6 +210,8 @@ func (c ReportCmd) Run(args []string) int {
204210
Limit: limit}
205211

206212
switch format {
213+
case "project":
214+
out, err = report.ProjectSummary(projCommits, options)
207215
case "summary":
208216
out, err = report.CommitSummary(projCommits, options)
209217
case "commits":

report/report.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,38 @@ func CommitSummary(projects []ProjectCommits, options OutputOptions) (string, er
133133
return b.String(), nil
134134
}
135135

136+
// ProjectSummary returns the commit summary report
137+
func ProjectSummary(projects []ProjectCommits, options OutputOptions) (string, error) {
138+
notes := options.limitNotes(retrieveNotes(projects, options.TerminalOff, "Mon Jan 02"))
139+
if len(notes) == 0 {
140+
return "", nil
141+
}
142+
143+
projectTotals := map[string]int{}
144+
for _, n := range notes {
145+
projectTotals[n.Project] += n.Note.Total()
146+
}
147+
148+
b := new(bytes.Buffer)
149+
t := template.Must(template.New("ProjectSummary").Funcs(funcMap).Parse(projectTotalsTpl))
150+
cf := colorFormater{color: options.Color}
151+
err := t.Execute(
152+
b,
153+
struct {
154+
Projects map[string]int
155+
BoldFormat string
156+
GreenFormat string
157+
}{
158+
projectTotals,
159+
cf.white(true),
160+
cf.green(false),
161+
})
162+
if err != nil {
163+
return "", err
164+
}
165+
return b.String(), nil
166+
}
167+
136168
// Commits returns the commits report
137169
func Commits(projects []ProjectCommits, options OutputOptions) (string, error) {
138170
notes := options.limitNotes(retrieveNotes(projects, options.TerminalOff, ""))

report/templates.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const (
2020
{{- if $line.CommitLine }}
2121
{{- FormatDuration $line.Total | printf "\n%14s" }} {{ printf $greenFormat $line.Subject }} [{{ $line.Project }}]
2222
{{- end }}
23+
{{- end -}}`
24+
projectTotalsTpl string = `
25+
{{- $boldFormat := .BoldFormat }}
26+
{{- range $project, $total := .Projects }}
27+
{{- FormatDuration $total | printf "\n%14s" }} {{ printf $boldFormat $project }}
2328
{{- end -}}`
2429
commitsTpl string = `
2530
{{ $boldFormat := .BoldFormat }}

0 commit comments

Comments
 (0)