diff --git a/README.md b/README.md index 2fa869c..18973ec 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Command line tool to create and manage community campaigns. `campaigner` takes c - `campaigner publish` builds the tickets information and publishes it both to jira and github. - `campaigner sync` downloads updated information of the campaign progress. - `campaigner status` shows the current campaign data and progression. + - `campaigner list` shows the current campaign tickets and their status. - `campaigner report` generates reports from the campaign data. ## Install diff --git a/cmd/list.go b/cmd/list.go new file mode 100644 index 0000000..6cd99f0 --- /dev/null +++ b/cmd/list.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/spf13/cobra" + + "git.ctrlz.es/mgdelacroix/campaigner/app" +) + +func ListCmd() *cobra.Command { + return &cobra.Command{ + Use: "list", + Short: "Prints a list of the campaign's tickets", + Long: "Prints a list of the campaign's tickets with their statuses and external ids", + Args: cobra.NoArgs, + Run: withApp(listCmdF), + } +} + +func listCmdF(a *app.App, cmd *cobra.Command, _ []string) { + a.Campaign.PrintList() +} diff --git a/cmd/root.go b/cmd/root.go index 78f211f..952a393 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -50,6 +50,7 @@ func RootCmd() *cobra.Command { // FilterCmd(), InitCmd(), LabelCmd(), + ListCmd(), StatusCmd(), PublishCmd(), PullCmd(), diff --git a/model/campaign.go b/model/campaign.go index 8c5f29e..e971f94 100644 --- a/model/campaign.go +++ b/model/campaign.go @@ -2,6 +2,7 @@ package model import ( "bytes" + "encoding/json" "fmt" "os" "strings" @@ -87,6 +88,26 @@ func (c *Campaign) PrintStatus() { w.Flush() } +func (c *Campaign) PrintList() { + for _, t := range c.Tickets { + if t.IsPublishedJira() { + var str string + if t.IsPublishedGithub() { + str = fmt.Sprintf("[%s / #%d] %s", t.JiraLink, t.GithubLink, t.Summary) + } else { + str = fmt.Sprintf("[%s] %s", t.JiraLink, t.Summary) + } + if t.GithubStatus != "" { + str += fmt.Sprintf(" (%s)", t.GithubStatus) + } + fmt.Println(str) + } else { + b, _ := json.Marshal(t) + fmt.Printf("unpublished: %s\n", string(b)) + } + } +} + func (c *Campaign) AddTickets(tickets []*Ticket, fileOnly bool) { c.Tickets = append(c.Tickets, tickets...) c.RemoveDuplicateTickets(fileOnly)