Adds first version of status

This commit is contained in:
Miguel de la Cruz 2020-03-06 19:54:52 +01:00
parent 7e14e90a0a
commit 69f15a4de0
5 changed files with 56 additions and 0 deletions

View file

@ -18,6 +18,7 @@ func RootCmd() *cobra.Command {
FilterCmd(),
InitCmd(),
StandaloneCmd(),
StatusCmd(),
TokenCmd(),
PublishCmd(),
SyncCmd(),

25
cmd/status.go Normal file
View file

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

View file

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

View file

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

View file

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