Phase 4 part 6: the dashboard, CSV exports and an open metrics page
The MRR page adds churn, CLV, CAC and CLV:CAC. Eight tables download as CSV (MRR, NRR and revenue cohorts, CAC by month and channel, spend, products, customers). Metrics → Publish builds an open metrics page from chosen totals only (never a customer) and opens a pull request that adds or updates it on the site, checked with a Hugo build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/api/gitea"
|
||||
"supermarket/internal/db"
|
||||
"supermarket/internal/hugorepo"
|
||||
)
|
||||
@@ -265,3 +266,48 @@ func (ap *Applier) setupSite(ctx context.Context, site, key string, st *Setup) e
|
||||
st.PRNumber, st.PRURL, st.Note = pr.Number, pr.HTMLURL, note
|
||||
return nil
|
||||
}
|
||||
|
||||
// PublishPage opens a pull request that adds a page to the site, or
|
||||
// updates it if it's there: used for the open metrics page. The build
|
||||
// checks the page comes out.
|
||||
func (ap *Applier) PublishPage(ctx context.Context, pagePath, title, description, body, why string) (*gitea.Pull, string, error) {
|
||||
wc, full, branch, err := ap.workingCopy(ctx)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
canBuild, note := buildCheck(ctx, wc)
|
||||
pagePath = "/" + strings.Trim(pagePath, "/") + "/"
|
||||
work := "supermarket/page" + strings.TrimSuffix(strings.ReplaceAll(pagePath, "/", "-"), "-")
|
||||
if err := wc.NewBranch(ctx, work); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
file, err := wc.FindContent(pagePath)
|
||||
if err != nil {
|
||||
file = "content" + strings.TrimSuffix(pagePath, "/") + ".md"
|
||||
}
|
||||
fields := []hugorepo.Field{{Key: "title", Value: title}, {Key: "description", Value: description}, {Key: "date", Value: time.Now().Format("2006-01-02")}}
|
||||
if err := wc.UpsertPage(file, fields, body); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
if canBuild {
|
||||
out, err := wc.Build(ctx)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("after the change, %w", err)
|
||||
}
|
||||
_, _, err = hugorepo.BuiltHead(out, pagePath)
|
||||
os.RemoveAll(out)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("the site builds, but %w", err)
|
||||
}
|
||||
note = "Checked with a build: the page is at " + pagePath + "."
|
||||
}
|
||||
subject := "Update " + pagePath + ": " + title
|
||||
if err := wc.CommitAndPush(ctx, work, subject); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
pr, err := ap.Gitea.OpenPull(ctx, full, work, branch, subject, why+"\n\n"+note+"\n\nMerging publishes it.")
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
return pr, file, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user