Allow to add a footer to the github issues

This commit is contained in:
Miguel de la Cruz 2020-04-28 11:21:31 +02:00
parent 5f80e21364
commit 9dd34b5a1b
4 changed files with 43 additions and 13 deletions

View file

@ -27,7 +27,9 @@ func InitCmd() *cobra.Command {
--repository johndoe/awesomeproject \
-l 'Area/API' -l 'Tech/Go' \
--summary 'Refactor {{.function}} to inject the configuration service' \
--template ./refactor-config.tmpl`,
--issue-template ./refactor-config.tmpl \
--footer-template ./github-footer.tmpl
`,
Args: cobra.NoArgs,
Run: initCmdF,
}
@ -40,7 +42,8 @@ func InitCmd() *cobra.Command {
cmd.Flags().StringP("repository", "r", "", "the github repository")
cmd.Flags().StringSliceP("label", "l", []string{}, "the labels to add to the Github issues")
cmd.Flags().StringP("summary", "s", "", "the summary of the tickets")
cmd.Flags().StringP("template", "t", "", "the template path for the description of the tickets")
cmd.Flags().StringP("issue-template", "t", "", "the template path for the description of the tickets")
cmd.Flags().StringP("footer-template", "f", "", "the template path to append to the github issues as a footer")
cmd.Flags().StringP("issue-type", "i", "Story", "the issue type to create the tickets as")
return cmd
@ -68,7 +71,8 @@ func initCmdF(cmd *cobra.Command, _ []string) {
epic := getStringFlagOrAskIfEmpty("epic", "JIRA epic:")
repo := getStringFlagOrAskIfEmpty("repository", "GitHub repository:")
summary := getStringFlagOrAskIfEmpty("summary", "Ticket summary template:")
template := getStringFlagOrAskIfEmpty("template", "Ticket description template path:")
issueTemplate := getStringFlagOrAskIfEmpty("issue-template", "Ticket description template path:")
footerTemplate := getStringFlagOrAskIfEmpty("footer-template", "Github issue footer template path:")
issueType, _ := cmd.Flags().GetString("issue-type")
labels, _ := cmd.Flags().GetStringSlice("label")
@ -88,8 +92,9 @@ func initCmdF(cmd *cobra.Command, _ []string) {
Repo: repo,
Labels: labels,
},
Summary: summary,
Template: template,
Summary: summary,
IssueTemplate: issueTemplate,
FooterTemplate: footerTemplate,
}
if err := campaign.Save(cmp); err != nil {
ErrorAndExit(cmd, err)

View file

@ -1,9 +1,11 @@
package github
import (
"bytes"
"context"
"encoding/json"
"fmt"
"text/template"
"git.ctrlz.es/mgdelacroix/campaigner/campaign"
"git.ctrlz.es/mgdelacroix/campaigner/model"
@ -30,8 +32,30 @@ func NewClient(repo, token string) *GithubClient {
}
}
func getFooterTemplate(ticket *model.Ticket, templatePath string) (string, error) {
footerTmpl, err := template.ParseFiles(templatePath)
if err != nil {
return "", err
}
var footerBytes bytes.Buffer
if err := footerTmpl.Execute(&footerBytes, ticket); err != nil {
return "", err
}
return footerBytes.String(), nil
}
func (c *GithubClient) PublishTicket(ticket *model.Ticket, cmp *model.Campaign, dryRun bool) (*github.Issue, error) {
mdDescription := j2m.JiraToMD(ticket.Description)
if cmp.FooterTemplate != "" {
footer, err := getFooterTemplate(ticket, cmp.FooterTemplate)
if err != nil {
return nil, err
}
mdDescription += "\n" + footer
}
issueRequest := &github.IssueRequest{
Title: &ticket.Summary,
Body: &mdDescription,

View file

@ -42,7 +42,7 @@ func (c *JiraClient) GetIssueFromTicket(ticket *model.Ticket, cmp *model.Campaig
}
summary := summaryBytes.String()
descriptionTemplate, err := template.ParseFiles(cmp.Template)
descriptionTemplate, err := template.ParseFiles(cmp.IssueTemplate)
if err != nil {
return nil, err
}
@ -132,7 +132,7 @@ func (c *JiraClient) PublishNextTicket(cmp *model.Campaign, dryRun bool) (bool,
return false, err
}
ticket.JiraLink = issue.Key
ticket.JiraLink = fmt.Sprintf("%s/browse/%s", cmp.Jira.Url, issue.Key)
ticket.Summary = issue.Fields.Summary
ticket.Description = issue.Fields.Description
// ToDo: sync JiraStatus

View file

@ -26,11 +26,12 @@ type ConfigGithub struct {
// ToDo: add key-value extra params as a map to allow for customfield_whatever = team
type Campaign struct {
Jira ConfigJira `json:"jira"`
Github ConfigGithub `json:"github"`
Summary string `json:"summary"`
Template string `json:"template"`
Tickets []*Ticket `json:"tickets,omitempty"`
Jira ConfigJira `json:"jira"`
Github ConfigGithub `json:"github"`
Summary string `json:"summary"`
IssueTemplate string `json:"issue_template"`
FooterTemplate string `json:"footer_template"`
Tickets []*Ticket `json:"tickets,omitempty"`
}
func (c *Campaign) NextJiraUnpublishedTicket() *Ticket {
@ -81,7 +82,7 @@ func (c *Campaign) FillTicket(t *Ticket) error {
}
t.Summary = summaryBytes.String()
descriptionTemplate, err := template.ParseFiles(c.Template)
descriptionTemplate, err := template.ParseFiles(c.IssueTemplate)
if err != nil {
return err
}