From 69f15a4de049c0482720cf5810eb1a69bef1549a Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Fri, 6 Mar 2020 19:54:52 +0100 Subject: [PATCH] Adds first version of status --- cmd/root.go | 1 + cmd/status.go | 25 +++++++++++++++++++++++++ jira/jira.go | 6 ++++++ model/campaign.go | 18 ++++++++++++++++++ model/ticket.go | 6 ++++++ 5 files changed, 56 insertions(+) create mode 100644 cmd/status.go diff --git a/cmd/root.go b/cmd/root.go index d4773b1..6e3e41f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -18,6 +18,7 @@ func RootCmd() *cobra.Command { FilterCmd(), InitCmd(), StandaloneCmd(), + StatusCmd(), TokenCmd(), PublishCmd(), SyncCmd(), diff --git a/cmd/status.go b/cmd/status.go new file mode 100644 index 0000000..f865800 --- /dev/null +++ b/cmd/status.go @@ -0,0 +1,25 @@ +package cmd + +import ( + "git.ctrlz.es/mgdelacroix/campaigner/campaign" + + "github.com/spf13/cobra" +) + +func StatusCmd() *cobra.Command { + return &cobra.Command{ + Use: "status", + Short: "Prints the current status of the campaign", + Args: cobra.NoArgs, + Run: statusCmdF, + } +} + +func statusCmdF(cmd *cobra.Command, _ []string) { + cmp, err := campaign.Read() + if err != nil { + ErrorAndExit(cmd, err) + } + + cmp.PrintStatus(cmd.OutOrStdout()) +} diff --git a/jira/jira.go b/jira/jira.go index 469e203..9fbec84 100644 --- a/jira/jira.go +++ b/jira/jira.go @@ -127,7 +127,13 @@ func (c *JiraClient) PublishNextTicket(cmp *model.Campaign, dryRun bool) (bool, return true, nil } + issue, _, err = c.Issue.Get(issue.Key, nil) + if err != nil { + return false, err + } + ticket.JiraLink = issue.Key + ticket.Summary = issue.Fields.Summary if err := campaign.Save(cmp); err != nil { return false, err } diff --git a/model/campaign.go b/model/campaign.go index 68f6339..2d93a6a 100644 --- a/model/campaign.go +++ b/model/campaign.go @@ -1,5 +1,10 @@ package model +import ( + "fmt" + "io" +) + // ToDo: add key-value extra params as a map to allow for customfield_whatever = team type Campaign struct { Url string `json:"url"` @@ -19,3 +24,16 @@ func (c *Campaign) NextUnpublishedTicket() *Ticket { } return nil } + +func (c *Campaign) PrintStatus(w io.Writer) { + fmt.Fprintf(w, "Url: %s\n", c.Url) + fmt.Fprintf(w, "Project: %s\n", c.Project) + fmt.Fprintf(w, "Epic: %s\n", c.Epic) + fmt.Fprintf(w, "Issue Type: %s\n", c.IssueType) + fmt.Fprintf(w, "Summary: %s\n", c.Summary) + fmt.Fprintf(w, "Template: %s\n", c.Template) + + for _, ticket := range c.Tickets { + ticket.PrintStatus(w) + } +} diff --git a/model/ticket.go b/model/ticket.go index 6e9aed4..912c2ca 100644 --- a/model/ticket.go +++ b/model/ticket.go @@ -2,11 +2,13 @@ package model import ( "fmt" + "io" ) type Ticket struct { GithubLink string `json:"githubLink,omitempty"` JiraLink string `json:"jiraLink,omitempty"` + Summary string `json:"summary,omitempty"` Data map[string]interface{} `json:"data,omitempty"` } @@ -29,3 +31,7 @@ func RemoveDuplicateTickets(tickets []*Ticket, fileOnly bool) []*Ticket { return cleanTickets } + +func (t *Ticket) PrintStatus(w io.Writer) { + fmt.Fprintf(w, " [%s] %s\n", t.JiraLink, t.Summary) +}