diff --git a/cmd/add.go b/cmd/add.go index 9d9d2ec..faa7720 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -77,7 +77,8 @@ func CsvAddCmd() *cobra.Command { func AddCmd() *cobra.Command { cmd := &cobra.Command{ Use: "add", - Short: "Adds tickets to the campaign from the output of grep/ag/govet", + Short: "Adds tickets to the campaign", + Long: "Adds tickets to the campaign from the output of grep/ag/govet", } cmd.AddCommand( diff --git a/cmd/init.go b/cmd/init.go index 0982dd5..08a92a8 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -15,7 +15,8 @@ import ( func InitCmd() *cobra.Command { cmd := &cobra.Command{ Use: "init", - Short: "Creates a new campaign in the current directory", + Short: "Creates a campaign", + Long: "Creates a new campaign in the current directory", Example: ` campaigner init \ --jira-username johndoe \ --jira-token secret \ diff --git a/cmd/publish.go b/cmd/publish.go index 4eba5db..b502a0d 100644 --- a/cmd/publish.go +++ b/cmd/publish.go @@ -43,7 +43,8 @@ func GithubPublishCmd() *cobra.Command { func PublishCmd() *cobra.Command { cmd := &cobra.Command{ Use: "publish", - Short: "Publishes the campaign tickets in different providers", + Short: "Publishes campaign tickets", + Long: "Publishes the campaign tickets in both Jira and Github", } cmd.AddCommand( diff --git a/cmd/root.go b/cmd/root.go index cef6b4e..7708d45 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -15,7 +15,7 @@ func RootCmd() *cobra.Command { cmd.AddCommand( AddCmd(), - FilterCmd(), + // FilterCmd(), InitCmd(), StatusCmd(), PublishCmd(), diff --git a/cmd/status.go b/cmd/status.go index 1c9905c..63b96a9 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -9,7 +9,8 @@ import ( func StatusCmd() *cobra.Command { return &cobra.Command{ Use: "status", - Short: "Prints the current status of the campaign", + Short: "Prints the campaign status", + Long: "Prints the current status of the campaign and its tickets", Args: cobra.NoArgs, Run: statusCmdF, } @@ -21,5 +22,5 @@ func statusCmdF(cmd *cobra.Command, _ []string) { ErrorAndExit(cmd, err) } - cmp.PrintStatus(cmd.OutOrStdout()) + cmp.PrintStatus() } diff --git a/cmd/sync.go b/cmd/sync.go index ccd8196..4196357 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -7,11 +7,16 @@ import ( func SyncCmd() *cobra.Command { cmd := &cobra.Command{ Use: "sync", - Short: "Synchronizes the status of the tickets with remote providers", + Short: "Syncs the tickets", + Long: "Synchronizes the status of the published tickets with remote providers", Args: cobra.NoArgs, Run: syncCmdF, } + cmd.Flags().BoolP("all", "a", false, "syncs all the published tickets") + cmd.Flags().StringP("jira-issue", "j", "", "syncs a ticket by Jira issue number") + cmd.Flags().StringP("github-issue", "g", "", "syncs a ticket by GitHub issue number") + return cmd } diff --git a/github/github.go b/github/github.go index 2df449b..37d6276 100644 --- a/github/github.go +++ b/github/github.go @@ -70,7 +70,7 @@ func (c *GithubClient) PublishNextTicket(cmp *model.Campaign, dryRun bool) (bool return true, nil } - ticket.GithubLink = *issue.ID + ticket.GithubLink = issue.GetNumber() if err := campaign.Save(cmp); err != nil { return false, err } diff --git a/model/campaign.go b/model/campaign.go index abc9afc..ca1f959 100644 --- a/model/campaign.go +++ b/model/campaign.go @@ -3,7 +3,6 @@ package model import ( "bytes" "fmt" - "io" "strings" "text/template" ) @@ -34,7 +33,7 @@ type Campaign struct { func (c *Campaign) NextJiraUnpublishedTicket() *Ticket { for _, ticket := range c.Tickets { - if ticket.JiraLink == "" { + if !ticket.IsPublishedJira() { return ticket } } @@ -43,26 +42,26 @@ func (c *Campaign) NextJiraUnpublishedTicket() *Ticket { func (c *Campaign) NextGithubUnpublishedTicket() *Ticket { for _, ticket := range c.Tickets { - if ticket.JiraLink != "" && ticket.GithubLink == 0 { + if ticket.IsPublishedJira() && !ticket.IsPublishedGithub() { return ticket } } return nil } -func (c *Campaign) PrintStatus(w io.Writer) { - fmt.Fprintf(w, "JIRA URL: %s\n", c.Jira.Url) - fmt.Fprintf(w, "JIRA Project: %s\n", c.Jira.Project) - fmt.Fprintf(w, "JIRA Epic: %s\n", c.Jira.Epic) - fmt.Fprintf(w, "JIRA Issue Type: %s\n", c.Jira.IssueType) - fmt.Fprintf(w, "GitHub Repo: %s\n", c.Github.Repo) - fmt.Fprintf(w, "GitHub Labels: %s\n", c.Github.Labels) - fmt.Fprintf(w, "Summary: %s\n", c.Summary) - fmt.Fprintf(w, "Template: %s\n", c.Template) - fmt.Fprintln(w, "") +func (c *Campaign) PrintStatus() { + fmt.Printf("JIRA URL: %s\n", c.Jira.Url) + fmt.Printf("JIRA Project: %s\n", c.Jira.Project) + fmt.Printf("JIRA Epic: %s\n", c.Jira.Epic) + fmt.Printf("JIRA Issue Type: %s\n", c.Jira.IssueType) + fmt.Printf("GitHub Repo: %s\n", c.Github.Repo) + fmt.Printf("GitHub Labels: %s\n", c.Github.Labels) + fmt.Printf("Summary: %s\n", c.Summary) + fmt.Printf("Template: %s\n", c.Template) + fmt.Println("") for _, ticket := range c.Tickets { - ticket.PrintStatus(w) + ticket.PrintStatus() } } diff --git a/model/ticket.go b/model/ticket.go index 556534e..369af8b 100644 --- a/model/ticket.go +++ b/model/ticket.go @@ -2,11 +2,10 @@ package model import ( "fmt" - "io" ) type Ticket struct { - GithubLink int64 `json:"github_link,omitempty"` + GithubLink int `json:"github_link,omitempty"` GithubStatus string `json:"github_status,omitempty"` JiraLink string `json:"jira_link,omitempty"` JiraStatus string `json:"jira_status,omitempty"` @@ -35,8 +34,16 @@ func RemoveDuplicateTickets(tickets []*Ticket, fileOnly bool) []*Ticket { return cleanTickets } -func (t *Ticket) PrintStatus(w io.Writer) { +func (t *Ticket) IsPublishedJira() bool { + return t.JiraLink != "" +} + +func (t *Ticket) IsPublishedGithub() bool { + return t.JiraLink != "" && t.GithubLink != 0 +} + +func (t *Ticket) PrintStatus() { if t.Summary != "" { - fmt.Fprintf(w, "[%s] %s\n", t.JiraLink, t.Summary) + fmt.Printf("[%s] %s\n", t.JiraLink, t.Summary) } }