Add report user command
This commit is contained in:
parent
177ed7fd6e
commit
0e6678534e
5 changed files with 69 additions and 4 deletions
33
cmd/report.go
Normal file
33
cmd/report.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"git.ctrlz.es/mgdelacroix/campaigner/app"
|
||||
)
|
||||
|
||||
func UsersReportCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "users",
|
||||
Short: "A users report",
|
||||
Args: cobra.NoArgs,
|
||||
Run: withApp(userReportCmdF),
|
||||
}
|
||||
}
|
||||
|
||||
func ReportCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "report",
|
||||
Short: "Generates reports on campaign information",
|
||||
}
|
||||
|
||||
cmd.AddCommand(
|
||||
UserReportCmd(),
|
||||
)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func userReportCmdF(a *app.App, cmd *cobra.Command, _ []string) {
|
||||
a.Campaign.PrintUserReport()
|
||||
}
|
|
@ -51,6 +51,7 @@ func RootCmd() *cobra.Command {
|
|||
PublishCmd(),
|
||||
PullCmd(),
|
||||
SyncCmd(),
|
||||
ReportCmd(),
|
||||
)
|
||||
|
||||
return cmd
|
||||
|
|
|
@ -62,8 +62,9 @@ func (c *Campaign) PrintStatus() {
|
|||
totalPublishedGithub++
|
||||
if t.IsAssigned() {
|
||||
totalAssigned++
|
||||
} else if t.IsClosed() {
|
||||
totalClosed++
|
||||
if t.IsClosed() {
|
||||
totalClosed++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
30
model/campaign_reports.go
Normal file
30
model/campaign_reports.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
)
|
||||
|
||||
func (c *Campaign) PrintUserReport() {
|
||||
userTickets := map[string]int{}
|
||||
for _, ticket := range c.Tickets {
|
||||
user := ticket.GithubAssignee
|
||||
if user != "" {
|
||||
if count, ok := userTickets[user]; ok {
|
||||
userTickets[user] = count+1
|
||||
} else {
|
||||
userTickets[user] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("User report:\n")
|
||||
w := tabwriter.NewWriter(os.Stdout, 3, 0, 3, ' ', tabwriter.AlignRight)
|
||||
fmt.Fprintln(w, "GitHub username\tTickets closed\t")
|
||||
for user, count := range userTickets {
|
||||
fmt.Fprintf(w, "%s\t%d\t\n", user, count)
|
||||
}
|
||||
w.Flush()
|
||||
fmt.Println()
|
||||
}
|
|
@ -24,11 +24,11 @@ func (t *Ticket) IsPublishedGithub() bool {
|
|||
}
|
||||
|
||||
func (t *Ticket) IsAssigned() bool {
|
||||
return t.IsPublishedGithub() && t.GithubAssignee != "" && t.GithubStatus == "open"
|
||||
return t.IsPublishedGithub() && t.GithubAssignee != ""
|
||||
}
|
||||
|
||||
func (t *Ticket) IsClosed() bool {
|
||||
return t.IsPublishedGithub() && t.GithubAssignee != "" && t.GithubStatus == "closed"
|
||||
return t.IsAssigned() && t.GithubStatus == "closed"
|
||||
}
|
||||
|
||||
func (t *Ticket) PrintStatus() {
|
||||
|
|
Loading…
Reference in a new issue