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

@ -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,