Add campaigner list command

This commit is contained in:
Miguel de la Cruz 2020-10-07 19:52:00 +02:00
parent 27965460d4
commit 0cff217a8b
4 changed files with 44 additions and 0 deletions

View file

@ -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

21
cmd/list.go Normal file
View file

@ -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()
}

View file

@ -50,6 +50,7 @@ func RootCmd() *cobra.Command {
// FilterCmd(),
InitCmd(),
LabelCmd(),
ListCmd(),
StatusCmd(),
PublishCmd(),
PullCmd(),

View file

@ -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)