Improved analytics CSV exports to include the site name#28308
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (10)
🚧 Files skipped from review as they are similar to previous changes (10)
WalkthroughAdds site-title-aware filenames for analytics CSV exports. Introduces the Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
c5f6ef1 to
36ef301
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ghost/core/core/server/api/endpoints/utils/serializers/output/posts.js`:
- Line 62: The Content-Disposition header is being set using models.filename
without guarding for missing values; update the code around the
res.setHeader('Content-Disposition', ...) call to check models.filename (or the
variable name used in this scope) and only include filename when it is a
non-empty string, otherwise use a safe default filename (e.g., 'export.csv') or
omit the filename parameter; ensure you reference the existing models.filename
symbol and the res.setHeader call so the header is never set to
filename="undefined".
In `@ghost/core/test/e2e-api/admin/post-analytics-export.test.js`:
- Around line 30-33: The current matcher in matchExportHeaders over-constrains
the filename by requiring a slug prefix; update the stringMatching regex used
for 'content-disposition' so the slug+dot is optional (e.g. allow either
"ghost.analytics.YYYY-MM-DD.csv" or "slug.ghost.analytics.YYYY-MM-DD.csv"). Edit
the regex in the matchExportHeaders constant (the stringMatching(...) entry) to
make the initial [a-z0-9-]+\. portion optional (while keeping the rest of the
pattern and anchors intact) so tests cover the empty-site-title fallback.
In `@ghost/core/test/e2e-api/admin/posts.test.js`:
- Around line 144-145: The test's 'content-disposition' assertion is too strict
and requires a slug prefix though getPostAnalyticsExportFileName() can return
the fallback "ghost.analytics.YYYY-MM-DD.csv" when site title is falsy; update
the matcher used in the tests (the 'content-disposition' stringMatching
assertions) to accept either the slug-prefixed form or the fallback by using a
regex that makes the "<slug>." prefix optional (so both
"<slug>.ghost.analytics.YYYY-MM-DD.csv" and "ghost.analytics.YYYY-MM-DD.csv"
match); apply this change to the occurrences referenced (the current assertion
and the ones at the other noted locations).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e5ef2cf2-5832-46c3-8edc-66bc4cc4fae3
⛔ Files ignored due to path filters (3)
ghost/core/test/e2e-api/admin/__snapshots__/post-analytics-export.test.js.snapis excluded by!**/*.snapghost/core/test/e2e-api/admin/__snapshots__/posts.test.js.snapis excluded by!**/*.snappnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
apps/admin-x-settings/package.jsonapps/admin-x-settings/src/components/settings/advanced/migration-tools/migration-tools-export.tsxapps/admin-x-settings/src/typings.d.tsapps/admin-x-settings/test/unit/utils/post-analytics-export-filename.test.tsghost/core/core/server/api/endpoints/posts.jsghost/core/core/server/api/endpoints/utils/serializers/output/posts.jsghost/core/test/e2e-api/admin/post-analytics-export.test.jsghost/core/test/e2e-api/admin/posts.test.jsghost/core/test/unit/api/canary/utils/serializers/output/posts-export-csv.test.ts
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #28308 +/- ##
==========================================
- Coverage 73.62% 73.62% -0.01%
==========================================
Files 1536 1536
Lines 130847 130863 +16
Branches 15651 15654 +3
==========================================
+ Hits 96341 96350 +9
- Misses 33519 33524 +5
- Partials 987 989 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
closes [ONC-1782](https://linear.app/ghost/issue/ONC-1782/oss-issue-analytics-csv-export-should-include-site-name-in-filename) Analytics downloads used a generic filename, which made exports from multiple sites hard to identify and inconsistent with content exports.
Guarded the CSV serializer against missing filenames, relaxed export header matchers to cover the no-title fallback, and exposed the existing `@tryghost/string` module type to the admin build that imports admin-x-settings source.
11d0fe3 to
2ab7fe9
Compare
closes ONC-1782
Closes #28227
Why
Post analytics CSV exports were downloaded with a generic
post-analytics.YYYY-MM-DD.csvfilename. That made exports from multiple Ghost sites harder to identify and was inconsistent with content exports, which already include the site name in the filename.How
This updates the Admin settings export flow to build the analytics CSV filename from the current site title, using Ghost's existing
@tryghost/string.slugifyhelper so the title formatting matches Ghost's established safe filename behavior. The direct Admin API/posts/export/response now uses the samesite-name.ghost.analytics.YYYY-MM-DD.csvfilename inContent-Disposition, so browser-triggered and direct downloads stay consistent.Impact
Users managing exports across multiple publications can tell which site an analytics CSV came from without manually renaming files, and repeated exports are less likely to collide in downloads folders.
Testing
git diff --checkpassed before committing.