This commit is contained in:
Miguel de la Cruz 2020-04-29 17:37:52 +02:00
parent 8732aee990
commit 5ac2900add
4 changed files with 71 additions and 2 deletions

12
cmd/pull.go Normal file
View file

@ -0,0 +1,12 @@
package cmd
func PullCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "pull",
Short: "Imports tickets from Jira",
Long: "Imports all tickets from a Jira epic issue",
RunE: pullCmdF,
}
cmd.Flags().BoolP("epic")
}

View file

@ -1,7 +1,14 @@
package cmd package cmd
import ( import (
"fmt"
"encoding/json"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"git.ctrlz.es/mgdelacroix/campaigner/campaign"
"git.ctrlz.es/mgdelacroix/campaigner/jira"
"git.ctrlz.es/mgdelacroix/campaigner/model"
) )
func SyncCmd() *cobra.Command { func SyncCmd() *cobra.Command {
@ -15,9 +22,40 @@ func SyncCmd() *cobra.Command {
cmd.Flags().BoolP("all", "a", false, "syncs all the published tickets") 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("jira-issue", "j", "", "syncs a ticket by Jira issue number")
cmd.Flags().StringP("github-issue", "g", "", "syncs a ticket by GitHub issue number") cmd.Flags().IntP("github-issue", "g", 0, "syncs a ticket by GitHub issue number")
return cmd return cmd
} }
func syncCmdF(_ *cobra.Command, _ []string) {} func syncCmdF(cmd *cobra.Command, _ []string) {
jiraIssue, _ := cmd.Flags().GetString("jira-issue")
// githubIssue, _ := cmd.Flags().GetInt()
// check that one is defined, or all
cmp, err := campaign.Read()
if err != nil {
ErrorAndExit(cmd, err)
}
var ticket *model.Ticket
if jiraIssue != "" {
ticket = cmp.GetByJiraIssue(jiraIssue)
if ticket == nil {
ErrorAndExit(cmd, fmt.Errorf("Could not find jira issue %s", jiraIssue))
}
}
jiraClient, err := jira.NewClient(cmp.Jira.Url, cmp.Jira.Username, cmp.Jira.Token)
if err != nil {
ErrorAndExit(cmd, err)
}
i, _, err := jiraClient.Issue.Get(ticket.JiraIssue(), nil)
if err != nil {
ErrorAndExit(cmd, err)
}
b, _ := json.MarshalIndent(i.Fields, "", " ")
fmt.Printf(string(b))
}

View file

@ -102,3 +102,13 @@ func (c *Campaign) RepoComponents() (string, string) {
} }
return "", "" return "", ""
} }
func (c *Campaign) GetByJiraIssue(num string) (ticket *Ticket) {
for _, t := range c.Tickets {
if t.JiraIssue() == num {
ticket = t
return
}
}
return
}

View file

@ -2,6 +2,7 @@ package model
import ( import (
"fmt" "fmt"
"strings"
) )
type Ticket struct { type Ticket struct {
@ -48,3 +49,11 @@ func (t *Ticket) PrintStatus() {
fmt.Printf("[%s] %s\n", t.JiraLink, t.Summary) fmt.Printf("[%s] %s\n", t.JiraLink, t.Summary)
} }
} }
func (t *Ticket) JiraIssue() string {
parts := strings.Split(t.JiraLink, "/")
if len(parts) < 2 {
return ""
}
return parts[len(parts)-1]
}