Print URL of the JIRA and GitHub published tickets/issues

This commit is contained in:
Miguel de la Cruz 2020-10-03 14:40:09 +02:00
parent bebf753f70
commit 817d73abac
3 changed files with 25 additions and 24 deletions

View file

@ -5,6 +5,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"os" "os"
"text/template" "text/template"
@ -71,7 +72,7 @@ func (a *App) PublishInGithub(ticket *model.Ticket, dryRun bool) (*github.Issue,
return newIssue, nil return newIssue, nil
} }
func (a *App) PublishNextInGithub(dryRun bool) (bool, error) { func (a *App) PublishNextInGithub(w io.Writer, dryRun bool) (bool, error) {
ticket := a.Campaign.NextGithubUnpublishedTicket() ticket := a.Campaign.NextGithubUnpublishedTicket()
if ticket == nil { if ticket == nil {
return false, nil return false, nil
@ -92,21 +93,19 @@ func (a *App) PublishNextInGithub(dryRun bool) (bool, error) {
return false, err return false, err
} }
// ToDo: print here the newly created issue fmt.Fprintf(w, "Issue published: https://github.com/%s/issues/%d\n", a.Campaign.Github.Repo, ticket.GithubLink)
if !dryRun {
if err := a.UpdateJiraAfterGithub(ticket); err != nil { if err := a.UpdateJiraAfterGithub(ticket); err != nil {
fmt.Fprintf(os.Stderr, "error updating Jira info for %s after publishing in Github\n", ticket.JiraLink) fmt.Fprintf(os.Stderr, "error updating Jira info for %s after publishing in Github\n", ticket.JiraLink)
} }
}
return true, nil return true, nil
} }
func (a *App) PublishAllInGithub(dryRun bool) (int, error) { func (a *App) PublishAllInGithub(w io.Writer, dryRun bool) (int, error) {
count := 0 count := 0
for { for {
next, err := a.PublishNextInGithub(dryRun) next, err := a.PublishNextInGithub(w, dryRun)
if err != nil { if err != nil {
return count, err return count, err
} }
@ -118,9 +117,9 @@ func (a *App) PublishAllInGithub(dryRun bool) (int, error) {
return count, nil return count, nil
} }
func (a *App) PublishBatchInGithub(batch int, dryRun bool) error { func (a *App) PublishBatchInGithub(w io.Writer, batch int, dryRun bool) error {
for i := 1; i <= batch; i++ { for i := 1; i <= batch; i++ {
next, err := a.PublishNextInGithub(dryRun) next, err := a.PublishNextInGithub(w, dryRun)
if err != nil { if err != nil {
return err return err
} }

View file

@ -4,6 +4,8 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"strings"
"text/template" "text/template"
"git.ctrlz.es/mgdelacroix/campaigner/model" "git.ctrlz.es/mgdelacroix/campaigner/model"
@ -126,7 +128,7 @@ func (a *App) GetIssue(issueNo string) (*jira.Issue, error) {
return issue, nil return issue, nil
} }
func (a *App) PublishNextInJira(dryRun bool) (bool, error) { func (a *App) PublishNextInJira(w io.Writer, dryRun bool) (bool, error) {
ticket := a.Campaign.NextJiraUnpublishedTicket() ticket := a.Campaign.NextJiraUnpublishedTicket()
if ticket == nil { if ticket == nil {
return false, nil return false, nil
@ -154,15 +156,15 @@ func (a *App) PublishNextInJira(dryRun bool) (bool, error) {
return false, err return false, err
} }
// ToDo: print here the newly created issue fmt.Fprintf(w, "Ticket published: %s/browse/%s\n", strings.TrimSuffix(a.Campaign.Jira.Url, "/"), ticket.JiraLink)
return true, nil return true, nil
} }
func (a *App) PublishAllInJira(dryRun bool) (int, error) { func (a *App) PublishAllInJira(w io.Writer, dryRun bool) (int, error) {
count := 0 count := 0
for { for {
next, err := a.PublishNextInJira(dryRun) next, err := a.PublishNextInJira(w, dryRun)
if err != nil { if err != nil {
return count, err return count, err
} }
@ -174,9 +176,9 @@ func (a *App) PublishAllInJira(dryRun bool) (int, error) {
return count, nil return count, nil
} }
func (a *App) PublishBatchInJira(batch int, dryRun bool) error { func (a *App) PublishBatchInJira(w io.Writer, batch int, dryRun bool) error {
for i := 1; i <= batch; i++ { for i := 1; i <= batch; i++ {
next, err := a.PublishNextInJira(dryRun) next, err := a.PublishNextInJira(w, dryRun)
if err != nil { if err != nil {
return err return err
} }

View file

@ -63,16 +63,16 @@ func jiraPublishCmdF(a *app.App, cmd *cobra.Command, _ []string) error {
} }
if all { if all {
count, err := a.PublishAllInJira(dryRun) count, err := a.PublishAllInJira(cmd.OutOrStdout(), dryRun)
if err != nil { if err != nil {
ErrorAndExit(cmd, err) ErrorAndExit(cmd, err)
} }
cmd.Printf("All %d tickets successfully published in jira\n", count) cmd.Printf("\nAll %d tickets successfully published in jira\n", count)
} else { } else {
if err := a.PublishBatchInJira(batch, dryRun); err != nil { if err := a.PublishBatchInJira(cmd.OutOrStdout(), batch, dryRun); err != nil {
ErrorAndExit(cmd, err) ErrorAndExit(cmd, err)
} }
cmd.Printf("Batch of %d tickets successfully published in jira\n", batch) cmd.Printf("\nBatch of %d tickets successfully published in jira\n", batch)
} }
return nil return nil
@ -88,16 +88,16 @@ func githubPublishCmdF(a *app.App, cmd *cobra.Command, _ []string) error {
} }
if all { if all {
count, err := a.PublishAllInGithub(dryRun) count, err := a.PublishAllInGithub(cmd.OutOrStdout(), dryRun)
if err != nil { if err != nil {
ErrorAndExit(cmd, err) ErrorAndExit(cmd, err)
} }
cmd.Printf("All %d tickets successfully published in github\n", count) cmd.Printf("\nAll %d tickets successfully published in github\n", count)
} else { } else {
if err := a.PublishBatchInGithub(batch, dryRun); err != nil { if err := a.PublishBatchInGithub(cmd.OutOrStdout(), batch, dryRun); err != nil {
ErrorAndExit(cmd, err) ErrorAndExit(cmd, err)
} }
cmd.Printf("Batch of %d tickets successfully published in github\n", batch) cmd.Printf("\nBatch of %d tickets successfully published in github\n", batch)
} }
return nil return nil