Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/dev/newsletter/.snapshots/TestRenderMarkdownLong.json

Large diffs are not rendered by default.

35 changes: 21 additions & 14 deletions cmd/dev/newsletter/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"strings"

"github.com/pkg/errors"

"github.com/spf13/cobra"
"golang.org/x/text/cases"
"golang.org/x/text/language"
Expand Down Expand Up @@ -61,7 +63,7 @@ If you want to send only to a segment within that list, add the Segment ID as we
changelogRaw, err := os.ReadFile(changelogPath)
pkg.Check(err)

chimpCampaign, err := Draft(listID, flagx.MustGetInt(cmd, "segment"), tagMessageRaw, changelogRaw)
chimpCampaign, err := Draft(listID, flagx.MustGetInt(cmd, "segment"), tagMessageRaw, changelogRaw, flagx.MustGetBool(cmd, "dry"))
pkg.Check(err)

fmt.Printf(`Created campaign "%s" (%s)`, chimpCampaign.Settings.Title, chimpCampaign.ID)
Expand All @@ -71,7 +73,7 @@ If you want to send only to a segment within that list, add the Segment ID as we
},
}

func Draft(listID string, segmentID int, tagMessageRaw, changelogRaw []byte) (*gochimp3.CampaignResponse, error) {
func Draft(listID string, segmentID int, tagMessageRaw, changelogRaw []byte, dry bool) (*gochimp3.CampaignResponse, error) {
tag := pkg.GitHubTag()

var repoName string
Expand All @@ -88,17 +90,6 @@ func Draft(listID string, segmentID int, tagMessageRaw, changelogRaw []byte) (*g
changelog := renderMarkdown(changelogRaw)
tagMessage := renderMarkdown(tagMessageRaw)

chimpKey := pkg.MustGetEnv("MAILCHIMP_API_KEY")
var segmentOptions *gochimp3.CampaignCreationSegmentOptions
if segmentID > 0 {
var payload struct {
Options gochimp3.CampaignCreationSegmentOptions `json:"options"`
}
newMailchimpRequest(chimpKey, fmt.Sprintf("/lists/%s/segments/%d", listID, segmentID), &payload)
segmentOptions = &payload.Options
segmentOptions.SavedSegmentId = segmentID
}

brandColor := "#5528FF"
switch strings.ToLower(repoName) {
case "oathkeeper":
Expand All @@ -112,7 +103,6 @@ func Draft(listID string, segmentID int, tagMessageRaw, changelogRaw []byte) (*g
}

var body bytes.Buffer

t, err := template.New("mail-body.html").Parse(string(view.MailBody))
pkg.Check(err)

Expand All @@ -134,6 +124,22 @@ func Draft(listID string, segmentID int, tagMessageRaw, changelogRaw []byte) (*g
BrandColor: brandColor,
}))

if dry {
fmt.Printf("%s", body.String())
return nil, errors.New("dry run")
}

chimpKey := pkg.MustGetEnv("MAILCHIMP_API_KEY")
var segmentOptions *gochimp3.CampaignCreationSegmentOptions
if segmentID > 0 {
var payload struct {
Options gochimp3.CampaignCreationSegmentOptions `json:"options"`
}
newMailchimpRequest(chimpKey, fmt.Sprintf("/lists/%s/segments/%d", listID, segmentID), &payload)
segmentOptions = &payload.Options
segmentOptions.SavedSegmentId = segmentID
}

chimp := gochimp3.New(chimpKey)
chimpTemplate, err := chimp.CreateTemplate(&gochimp3.TemplateCreationRequest{
Name: substr(fmt.Sprintf("%s %s Announcement", projectName, tag), 0, 49),
Expand Down Expand Up @@ -171,4 +177,5 @@ func Draft(listID string, segmentID int, tagMessageRaw, changelogRaw []byte) (*g
func init() {
Main.AddCommand(draft)
draft.Flags().Int("segment", 0, "The Mailchimp Segment ID")
draft.Flags().Bool("dry", false, "Dry run")
}
6 changes: 3 additions & 3 deletions cmd/dev/newsletter/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strings"
"testing"

"github.com/ory/x/snapshotx"

"github.com/stretchr/testify/require"

"github.com/stretchr/testify/assert"
Expand All @@ -28,8 +30,6 @@ func TestRenderMarkdown(t *testing.T) {
func TestRenderMarkdownLong(t *testing.T) {
cl, err := os.ReadFile("stub/changelog.md.expected")
require.NoError(t, err)
expected, err := os.ReadFile("stub/changelog.html.expected")
require.NoError(t, err)

tmplRaw, err := os.ReadFile("../../../view/mail-body.html")
require.NoError(t, err)
Expand All @@ -55,5 +55,5 @@ func TestRenderMarkdownLong(t *testing.T) {
}))

require.NoError(t, os.WriteFile("stub/changelog.html.tmp", body.Bytes(), 0644))
assert.EqualValues(t, strings.TrimSpace(string(expected)), strings.TrimSpace(body.String()))
snapshotx.SnapshotT(t, body.String())
}
1 change: 1 addition & 0 deletions cmd/dev/release/notify/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var draft = &cobra.Command{
flagx.MustGetInt(cmd, "segment"),
[]byte(tagMessage),
changelog,
false,
)
pkg.Check(err)
fmt.Printf(`Created campaign "%s" (%s)`, campaign.Settings.Title, campaign.ID)
Expand Down
34 changes: 21 additions & 13 deletions view/mail-body.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
#outlook a {
padding: 0;
}
pre {
background-color: #f5f5f5;
padding: 8px;
}
code {
background-color: #f5f5f5;
padding: 2px 4px;
}
body {
margin: 0;
padding: 0;
Expand Down Expand Up @@ -56,8 +64,8 @@
max-width: 3.389830508474576%;
}
.xc600 {
width: 600px !important;
max-width: 600px;
width: 1200px !important;
max-width: 1200px;
}
.xc32 {
width: 32px !important;
Expand All @@ -68,8 +76,8 @@
max-width: 16px;
}
.xc440 {
width: 440px !important;
max-width: 440px;
/*width: 440px !important;*/
/*max-width: 440px;*/
}
}
</style>
Expand All @@ -87,8 +95,8 @@
max-width: 3.389830508474576%;
}
.moz-text-html .xc600 {
width: 600px !important;
max-width: 600px;
width: 1200px !important;
max-width: 1200px;
}
.moz-text-html .xc32 {
width: 32px !important;
Expand All @@ -99,8 +107,8 @@
max-width: 16px;
}
.moz-text-html .xc440 {
width: 440px !important;
max-width: 440px;
/*width: 440px !important;*/
/*max-width: 440px;*/
}
</style>
<style type="text/css">
Expand Down Expand Up @@ -245,7 +253,7 @@
background-color: #fffffe;
margin: 0px auto;
border-radius: 0;
max-width: 600px;
max-width: 1200px;
"
>
<table
Expand Down Expand Up @@ -468,7 +476,7 @@
background-color: #fcfcfc;
margin: 0px auto;
border-radius: 0;
max-width: 600px;
max-width: 1200px;
"
>
<table
Expand Down Expand Up @@ -1081,7 +1089,7 @@
background-color: #eeeeee;
margin: 0px auto;
border-radius: 0;
max-width: 600px;
max-width: 1200px;
"
>
<table
Expand Down Expand Up @@ -1535,7 +1543,7 @@
background-color: #171717;
margin: 0px auto;
border-radius: 0;
max-width: 600px;
max-width: 1200px;
"
>
<table
Expand Down Expand Up @@ -1687,7 +1695,7 @@
Want to change how you receive these emails?<br>
You can <a href="*|UPDATE_PROFILE|*">update your preferences</a> or <a href="*|UNSUB|*">unsubscribe from this list</a>.*|END:IF|*<br>
<br>*|IF:REWARDS|* *|HTML:REWARDS|* *|END:IF|*</span
>
>
</p>
</p>
<p style="margin: 0">
Expand Down