Allow to add a footer to the github issues
This commit is contained in:
parent
5f80e21364
commit
9dd34b5a1b
4 changed files with 43 additions and 13 deletions
15
cmd/init.go
15
cmd/init.go
|
@ -27,7 +27,9 @@ func InitCmd() *cobra.Command {
|
||||||
--repository johndoe/awesomeproject \
|
--repository johndoe/awesomeproject \
|
||||||
-l 'Area/API' -l 'Tech/Go' \
|
-l 'Area/API' -l 'Tech/Go' \
|
||||||
--summary 'Refactor {{.function}} to inject the configuration service' \
|
--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,
|
Args: cobra.NoArgs,
|
||||||
Run: initCmdF,
|
Run: initCmdF,
|
||||||
}
|
}
|
||||||
|
@ -40,7 +42,8 @@ func InitCmd() *cobra.Command {
|
||||||
cmd.Flags().StringP("repository", "r", "", "the github repository")
|
cmd.Flags().StringP("repository", "r", "", "the github repository")
|
||||||
cmd.Flags().StringSliceP("label", "l", []string{}, "the labels to add to the Github issues")
|
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("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")
|
cmd.Flags().StringP("issue-type", "i", "Story", "the issue type to create the tickets as")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -68,7 +71,8 @@ func initCmdF(cmd *cobra.Command, _ []string) {
|
||||||
epic := getStringFlagOrAskIfEmpty("epic", "JIRA epic:")
|
epic := getStringFlagOrAskIfEmpty("epic", "JIRA epic:")
|
||||||
repo := getStringFlagOrAskIfEmpty("repository", "GitHub repository:")
|
repo := getStringFlagOrAskIfEmpty("repository", "GitHub repository:")
|
||||||
summary := getStringFlagOrAskIfEmpty("summary", "Ticket summary template:")
|
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")
|
issueType, _ := cmd.Flags().GetString("issue-type")
|
||||||
labels, _ := cmd.Flags().GetStringSlice("label")
|
labels, _ := cmd.Flags().GetStringSlice("label")
|
||||||
|
|
||||||
|
@ -88,8 +92,9 @@ func initCmdF(cmd *cobra.Command, _ []string) {
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
},
|
},
|
||||||
Summary: summary,
|
Summary: summary,
|
||||||
Template: template,
|
IssueTemplate: issueTemplate,
|
||||||
|
FooterTemplate: footerTemplate,
|
||||||
}
|
}
|
||||||
if err := campaign.Save(cmp); err != nil {
|
if err := campaign.Save(cmp); err != nil {
|
||||||
ErrorAndExit(cmd, err)
|
ErrorAndExit(cmd, err)
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package github
|
package github
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
"git.ctrlz.es/mgdelacroix/campaigner/campaign"
|
"git.ctrlz.es/mgdelacroix/campaigner/campaign"
|
||||||
"git.ctrlz.es/mgdelacroix/campaigner/model"
|
"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) {
|
func (c *GithubClient) PublishTicket(ticket *model.Ticket, cmp *model.Campaign, dryRun bool) (*github.Issue, error) {
|
||||||
mdDescription := j2m.JiraToMD(ticket.Description)
|
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{
|
issueRequest := &github.IssueRequest{
|
||||||
Title: &ticket.Summary,
|
Title: &ticket.Summary,
|
||||||
Body: &mdDescription,
|
Body: &mdDescription,
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (c *JiraClient) GetIssueFromTicket(ticket *model.Ticket, cmp *model.Campaig
|
||||||
}
|
}
|
||||||
summary := summaryBytes.String()
|
summary := summaryBytes.String()
|
||||||
|
|
||||||
descriptionTemplate, err := template.ParseFiles(cmp.Template)
|
descriptionTemplate, err := template.ParseFiles(cmp.IssueTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ func (c *JiraClient) PublishNextTicket(cmp *model.Campaign, dryRun bool) (bool,
|
||||||
return false, err
|
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.Summary = issue.Fields.Summary
|
||||||
ticket.Description = issue.Fields.Description
|
ticket.Description = issue.Fields.Description
|
||||||
// ToDo: sync JiraStatus
|
// ToDo: sync JiraStatus
|
||||||
|
|
|
@ -26,11 +26,12 @@ type ConfigGithub struct {
|
||||||
|
|
||||||
// ToDo: add key-value extra params as a map to allow for customfield_whatever = team
|
// ToDo: add key-value extra params as a map to allow for customfield_whatever = team
|
||||||
type Campaign struct {
|
type Campaign struct {
|
||||||
Jira ConfigJira `json:"jira"`
|
Jira ConfigJira `json:"jira"`
|
||||||
Github ConfigGithub `json:"github"`
|
Github ConfigGithub `json:"github"`
|
||||||
Summary string `json:"summary"`
|
Summary string `json:"summary"`
|
||||||
Template string `json:"template"`
|
IssueTemplate string `json:"issue_template"`
|
||||||
Tickets []*Ticket `json:"tickets,omitempty"`
|
FooterTemplate string `json:"footer_template"`
|
||||||
|
Tickets []*Ticket `json:"tickets,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Campaign) NextJiraUnpublishedTicket() *Ticket {
|
func (c *Campaign) NextJiraUnpublishedTicket() *Ticket {
|
||||||
|
@ -81,7 +82,7 @@ func (c *Campaign) FillTicket(t *Ticket) error {
|
||||||
}
|
}
|
||||||
t.Summary = summaryBytes.String()
|
t.Summary = summaryBytes.String()
|
||||||
|
|
||||||
descriptionTemplate, err := template.ParseFiles(c.Template)
|
descriptionTemplate, err := template.ParseFiles(c.IssueTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue