refactor: decompose shared.ts and extract URL utils from generators.ts#1658
refactor: decompose shared.ts and extract URL utils from generators.ts#1658
Conversation
🏷️ Automatic Labeling SummaryThis PR has been automatically labeled based on the files changed and PR metadata. Applied Labels: size-xs Label Categories
For more information, see |
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
…move deprecated code
- Split scripts/data-transformers/content-generators/shared.ts (1125 lines → 527 lines)
into focused sub-modules:
- doc-type-helpers.ts: DOC_TYPE_DISPLAY, localizeDocType, TITLE_SUFFIX_TEMPLATES
- event-helpers.ts: findRelatedDocuments, findRelatedQuestions, extractMinister
- impact-helpers.ts: generateImpactAnalysis, generateConsequencesAnalysis
- framework-renderers.ts: stub types/functions + PESTLE/stakeholder/risk/implementation
HTML renderers
- ai-marker-helpers.ts: detectBannedPatterns + BANNED_PATTERNS
- shared.ts kept as barrel that re-exports all previously-exported symbols for
full backward compatibility; no existing imports were broken
- Extract URL/text utilities from generators.ts (2234 → 2109 lines) to
url-utils.ts: extractDocIdFromUrl, isGovernmentUrl, isGitHubUrl,
toGitHubRawUrl, hashPathSuffix, sanitizePlainText; re-exported for BC
- Types review: scripts/data-transformers/types.ts and
scripts/generate-news-enhanced/types.ts have no duplicates with
scripts/types/ — no consolidation needed
- All 4097 tests pass, ESLint clean (no new errors)
Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
…mework-renderers.ts Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
There was a problem hiding this comment.
Pull request overview
Refactors the news/content generation scripts by extracting URL/text utility functions from the large generate-news-enhanced/generators.ts file and decomposing the monolithic data-transformers/content-generators/shared.ts into focused sub-modules while keeping existing import paths working via barrel re-exports.
Changes:
- Added
scripts/generate-news-enhanced/url-utils.tsand re-exported URL/text helpers fromgenerators.ts. - Split
scripts/data-transformers/content-generators/shared.tsinto multiple helper modules (doc types, events, impact stubs, framework renderers, AI marker detection) and convertedshared.tsinto a barrel + deep-analysis host. - Moved framework “stub types/functions” and HTML renderers into
framework-renderers.ts.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/generate-news-enhanced/url-utils.ts | New home for URL parsing + sanitization helpers used by deep-inspection generator. |
| scripts/generate-news-enhanced/generators.ts | Removes inline URL helper implementations and re-exports them from url-utils. |
| scripts/data-transformers/content-generators/shared.ts | Becomes a barrel re-exporter for extracted helpers while still hosting deep-analysis assembly. |
| scripts/data-transformers/content-generators/impact-helpers.ts | Extracts political impact & consequences AI_MUST_REPLACE stub generation. |
| scripts/data-transformers/content-generators/framework-renderers.ts | Extracts framework stub types/functions and HTML renderers for analysis sections. |
| scripts/data-transformers/content-generators/event-helpers.ts | Extracts keyword/event matching and minister extraction helpers. |
| scripts/data-transformers/content-generators/doc-type-helpers.ts | Extracts doc type localization table and title suffix templates. |
| scripts/data-transformers/content-generators/ai-marker-helpers.ts | Extracts banned-pattern detection used by quality gates. |
| // --------------------------------------------------------------------------- | ||
| // URL & text utilities — implementation extracted to url-utils.ts | ||
| // Re-exported here for backward compatibility. | ||
| // --------------------------------------------------------------------------- | ||
| export { | ||
| extractDocIdFromUrl, | ||
| isGovernmentUrl, | ||
| isGitHubUrl, | ||
| toGitHubRawUrl, | ||
| hashPathSuffix, | ||
| sanitizePlainText, | ||
| } from './url-utils.js'; |
There was a problem hiding this comment.
The functions re-exported from ./url-utils.js (e.g. extractDocIdFromUrl, isGovernmentUrl, etc.) are still referenced within this module, but an export { … } from … re-export does not create local bindings in the current file. This will cause TypeScript compile errors where these identifiers are used later in generators.ts. Import them explicitly (and then re-export if you want to keep the existing public API).
| plural: { | ||
| en: 'External References', sv: 'Externa referenser', da: 'Eksterne referencer', no: 'Eksterne referanser', | ||
| fi: 'Ulkoiset viitteet', de: 'Externe Referenzen', fr: 'Références externes', es: 'Referencias externas', | ||
| nl: 'Externe referenties', ar: 'مراجع خارجية', he: 'הפניות חיצוניות', ja: '外部参照', ko: '외부 참照', zh: '外部参考', |
There was a problem hiding this comment.
Korean plural translation for ext uses 외부 참照, which is a typo/inconsistent with the singular form (외부 참조). This will show incorrect text in the UI for Korean when pluralizing “External References”.
| nl: 'Externe referenties', ar: 'مراجع خارجية', he: 'הפניות חיצוניות', ja: '外部参照', ko: '외부 참照', zh: '外部参考', | |
| nl: 'Externe referenties', ar: 'مراجع خارجية', he: 'הפניות חיצוניות', ja: '外部参照', ko: '외부 참조', zh: '外部参考', |
|
@copilot apply changes based on the comments in this thread and fix TypeScript & JavaScript Testing / Unit Tests (Vitest) (pull_request) |
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
… doc-type-helpers.ts Agent-Logs-Url: https://github.com/Hack23/riksdagsmonitor/sessions/dff320eb-d844-4f76-8ec0-f968ed2780c5 Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Fixed both review comments in ae267a9:
All 4,097 tests pass, ESLint clean. |
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
| plural: { | ||
| en: 'External References', sv: 'Externa referenser', da: 'Eksterne referencer', no: 'Eksterne referanser', | ||
| fi: 'Ulkoiset viitteet', de: 'Externe Referenzen', fr: 'Références externes', es: 'Referencias externas', | ||
| nl: 'Externe referenties', ar: 'مراجع خارجية', he: 'הפניות חיצוניות', ja: '外部参照', ko: '외부 참조', zh: '외부参考', |
There was a problem hiding this comment.
The Chinese (zh) plural translation for document type ext is inconsistent/mistyped: it is set to 외부参考 (mix of Korean+Chinese). It should match the singular zh translation 外部参考 (or an appropriate Chinese plural form) to avoid user-facing i18n errors.
| nl: 'Externe referenties', ar: 'مراجع خارجية', he: 'הפניות חיצוניות', ja: '外部参照', ko: '외부 참조', zh: '외부参考', | |
| nl: 'Externe referenties', ar: 'مراجع خارجية', he: 'הפניות חיצוניות', ja: '外部参照', ko: '외부 참조', zh: '外部参考', |
| const segments = parsed.pathname.split('/').filter(Boolean); | ||
| if (segments.length < 4) return null; | ||
|
|
||
| const [owner, repo, refType, ...rest] = segments; | ||
| if (refType !== 'blob' && refType !== 'raw') return null; |
There was a problem hiding this comment.
The JSDoc says this converts "blob/tree" GitHub URLs, but the implementation only accepts blob and raw (and returns null for /tree/ URLs). Either update the documentation to remove tree, or extend the implementation to handle tree/{branch}/{path} if that's intended.
| const segments = parsed.pathname.split('/').filter(Boolean); | |
| if (segments.length < 4) return null; | |
| const [owner, repo, refType, ...rest] = segments; | |
| if (refType !== 'blob' && refType !== 'raw') return null; | |
| // or: /{owner}/{repo}/tree/{branch}/{...path} | |
| const segments = parsed.pathname.split('/').filter(Boolean); | |
| if (segments.length < 4) return null; | |
| const [owner, repo, refType, ...rest] = segments; | |
| if (refType !== 'blob' && refType !== 'raw' && refType !== 'tree') return null; |
|
@copilot apply changes based on the comments in this thread |
…tree URLs Agent-Logs-Url: https://github.com/Hack23/riksdagsmonitor/sessions/4ac9d786-f068-4ebc-9b61-40abb31e209f Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Fixed both review comments in 1b86b31:
All 4,097 tests pass, ESLint clean. |
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
외부 참照→외부 참조in doc-type-helpers.ts외부参考→外部参考in doc-type-helpers.ts (was mixed Korean+Chinese)toGitHubRawUrlto handle/tree/URLs, matching JSDoc