Add initial version of the sync command
This commit is contained in:
parent
f0d4dfb962
commit
a13a0ec949
3 changed files with 42 additions and 11 deletions
|
@ -128,3 +128,27 @@ func (a *App) PublishBatchInGithub(batch int, dryRun bool) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) GithubSync() error {
|
||||
tickets := a.Campaign.GetPublishedGithubTickets()
|
||||
total := len(tickets)
|
||||
owner, repo := a.Campaign.RepoComponents()
|
||||
|
||||
for i, ticket := range tickets {
|
||||
fmt.Printf("\rUpdating ticket %d of %d", i+1, total)
|
||||
|
||||
issue, _, err := a.GithubClient.Issues.Get(context.Background(), owner, repo, ticket.GithubLink)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
assignee := issue.GetAssignee()
|
||||
if assignee != nil {
|
||||
ticket.GithubAssignee = assignee.GetLogin()
|
||||
}
|
||||
ticket.GithubStatus = issue.GetState()
|
||||
}
|
||||
fmt.Print("\n")
|
||||
|
||||
return a.Save()
|
||||
}
|
||||
|
|
19
cmd/sync.go
19
cmd/sync.go
|
@ -1,27 +1,24 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.ctrlz.es/mgdelacroix/campaigner/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func SyncCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
return &cobra.Command{
|
||||
Use: "sync",
|
||||
Short: "Syncs the tickets",
|
||||
Long: "Synchronizes the status of the published tickets with remote providers",
|
||||
Args: cobra.NoArgs,
|
||||
Run: syncCmdF,
|
||||
Run: withApp(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
|
||||
}
|
||||
|
||||
func syncCmdF(cmd *cobra.Command, _ []string) {
|
||||
ErrorAndExit(cmd, fmt.Errorf("Not implemented yet"))
|
||||
func syncCmdF(a *app.App, cmd *cobra.Command, _ []string) {
|
||||
if err := a.GithubSync(); err != nil {
|
||||
ErrorAndExit(cmd, err)
|
||||
}
|
||||
cmd.Println("Synchronization completed")
|
||||
}
|
||||
|
|
|
@ -105,6 +105,16 @@ func (c *Campaign) RemoveDuplicateTickets(fileOnly bool) {
|
|||
c.Tickets = cleanTickets
|
||||
}
|
||||
|
||||
func (c *Campaign) GetPublishedGithubTickets() []*Ticket {
|
||||
publishedTickets := []*Ticket{}
|
||||
for _, ticket := range c.Tickets {
|
||||
if ticket.IsPublishedGithub() {
|
||||
publishedTickets = append(publishedTickets, ticket)
|
||||
}
|
||||
}
|
||||
return publishedTickets
|
||||
}
|
||||
|
||||
func (c *Campaign) FillTicket(t *Ticket) error {
|
||||
summaryTmpl, err := template.New("").Parse(c.Summary)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue