Skip to content

refactor: decompose shared.ts and extract URL utils from generators.ts#1658

Merged
pethers merged 7 commits intomainfrom
copilot/refactor-news-generation-modules
Apr 10, 2026
Merged

refactor: decompose shared.ts and extract URL utils from generators.ts#1658
pethers merged 7 commits intomainfrom
copilot/refactor-news-generation-modules

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

  • Split shared.ts (1,125 → 527 lines, -53%) into focused helper files
  • Extract URL utility functions from generators.ts into url-utils.ts
  • Maintain full backward compatibility via re-exports
  • Fix: import URL utils locally in generators.ts (re-export alone doesn't create local bindings)
  • Fix: Korean typo 외부 참照외부 참조 in doc-type-helpers.ts
  • Fix: Chinese (zh) translation 외부参考外部参考 in doc-type-helpers.ts (was mixed Korean+Chinese)
  • Fix: extend toGitHubRawUrl to handle /tree/ URLs, matching JSDoc
  • All 4,097 tests pass ✅
  • ESLint clean ✅

@github-actions
Copy link
Copy Markdown
Contributor

🏷️ Automatic Labeling Summary

This PR has been automatically labeled based on the files changed and PR metadata.

Applied Labels: size-xs

Label Categories

  • 🗳️ Content: news, dashboard, visualization, intelligence
  • 💻 Technology: html-css, javascript, workflow, security
  • 📊 Data: cia-data, riksdag-data, data-pipeline, schema
  • 🌍 I18n: i18n, translation, rtl
  • 🔒 ISMS: isms, iso-27001, nist-csf, cis-controls
  • 🏗️ Infrastructure: ci-cd, deployment, performance, monitoring
  • 🔄 Quality: testing, accessibility, documentation, refactor
  • 🤖 AI: agent, skill, agentic-workflow

For more information, see .github/labeler.yml.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copilot AI and others added 2 commits April 10, 2026 09:33
…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>
@github-actions github-actions bot added refactor Code refactoring size-xl Extra large change (> 1000 lines) labels Apr 10, 2026
Copilot AI changed the title [WIP] Refactor news generation modules to reduce complexity refactor: decompose shared.ts and extract URL utils from generators.ts Apr 10, 2026
Copilot AI requested a review from pethers April 10, 2026 09:40
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@pethers pethers marked this pull request as ready for review April 10, 2026 09:56
Copilot AI review requested due to automatic review settings April 10, 2026 09:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts and re-exported URL/text helpers from generators.ts.
  • Split scripts/data-transformers/content-generators/shared.ts into multiple helper modules (doc types, events, impact stubs, framework renderers, AI marker detection) and converted shared.ts into 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.

Comment on lines +665 to +676
// ---------------------------------------------------------------------------
// 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';
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
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: '外部参考',
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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”.

Suggested change
nl: 'Externe referenties', ar: 'مراجع خارجية', he: 'הפניות חיצוניות', ja: '外部参照', ko: '외부 참照', zh: '外部参考',
nl: 'Externe referenties', ar: 'مراجع خارجية', he: 'הפניות חיצוניות', ja: '外部参照', ko: '외부 참조', zh: '外部参考',

Copilot uses AI. Check for mistakes.
@pethers
Copy link
Copy Markdown
Member

pethers commented Apr 10, 2026

@copilot apply changes based on the comments in this thread and fix TypeScript & JavaScript Testing / Unit Tests (Vitest) (pull_request)
TypeScript & JavaScript Testing / Unit Tests (Vitest) (pull_request)Failing after 38s

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

… 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>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 10, 2026

@copilot apply changes based on the comments in this thread and fix [TypeScript & JavaScript Testing...

Fixed both review comments in ae267a9:

  1. generators.ts: Changed the export { … } from './url-utils.js' re-export to a proper import + separate export, so the URL utility functions are available as local bindings for use within the file.
  2. doc-type-helpers.ts: Fixed Korean typo 외부 참照외부 참조.

All 4,097 tests pass, ESLint clean.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

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: '외부参考',
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
nl: 'Externe referenties', ar: 'مراجع خارجية', he: 'הפניות חיצוניות', ja: '外部参照', ko: '외부 참조', zh: '외부参考',
nl: 'Externe referenties', ar: 'مراجع خارجية', he: 'הפניות חיצוניות', ja: '外部参照', ko: '외부 참조', zh: '外部参考',

Copilot uses AI. Check for mistakes.
Comment on lines +102 to +106
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;
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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 uses AI. Check for mistakes.
@pethers
Copy link
Copy Markdown
Member

pethers commented Apr 10, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 10, 2026

@copilot apply changes based on the comments in this thread

Fixed both review comments in 1b86b31:

  1. doc-type-helpers.ts: Fixed Chinese (zh) plural translation from 외부参考 (Korean+Chinese mix) to 外部参考 (correct Chinese).
  2. url-utils.ts: Extended toGitHubRawUrl to accept /tree/ URLs in addition to /blob/ and /raw/, matching the JSDoc.

All 4,097 tests pass, ESLint clean.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@pethers pethers requested a review from Copilot April 10, 2026 13:40
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@pethers pethers merged commit 497fde6 into main Apr 10, 2026
19 checks passed
@pethers pethers deleted the copilot/refactor-news-generation-modules branch April 10, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code refactoring size-xl Extra large change (> 1000 lines) size-xs Extra small change (< 10 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Code Architecture — Consolidate News Generation Modules & Reduce Complexity (scripts/ restructuring)

3 participants