Skip to content

Adding workflow for downloading postcode registry#274

Merged
tjololo merged 3 commits intoAltinn:masterfrom
olemartinorg:feat/postcode-registry
Jan 15, 2026
Merged

Adding workflow for downloading postcode registry#274
tjololo merged 3 commits intoAltinn:masterfrom
olemartinorg:feat/postcode-registry

Conversation

@olemartinorg
Copy link
Contributor

@olemartinorg olemartinorg commented Jan 15, 2026

Description

This adds a workflow that downloads the latest postcode changes from Posten/Bring and creates a pull request when there are changes. By serving a static file on CDN instead of relying on the Posten/Bring API, we reduce the risk of breaking apps like what happened yesterday and the day before when this API stopped working.

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Summary by CodeRabbit

  • Chores
    • Added automated weekly (and manual) updates for the Norwegian postal code registry to keep location data current.
    • Produces an optimized, indexed postal-code-to-place registry for faster lookups and smaller payloads.
    • Automatically opens pull requests with the updated registry when changes are detected to streamline maintenance and review.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

Adds a Node.js script to download, parse, and index the Norwegian postal code registry into postcodes/registry.json, and a GitHub Actions workflow that runs the script weekly or on demand and opens a pull request when the registry file changes.

Changes

Cohort / File(s) Summary
Postal code download script
'.github/scripts/download-postcodes.js'
New Node.js script that downloads ANSI-encoded postal data, decodes and parses tab-separated lines, extracts 4-digit ZIPs and place names, deduplicates places, builds a ZIP→place-index mapping (1-based indices, index 0 unused), writes postcodes/registry.json, and logs success/failure.
Postal code update workflow
'.github/workflows/update-postcodes.yml'
New GitHub Actions workflow triggered weekly (Tue 09:00 UTC) and on workflow_dispatch. Checks out the repo, sets up Node.js v22, runs the download script, and uses peter-evans/create-pull-request@v8 to open a PR to automated/update-postcodes when postcodes/registry.json changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately reflects the main change: introducing a GitHub Actions workflow for downloading and managing the postcode registry, which is the primary addition.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 872662a and a341810.

📒 Files selected for processing (1)
  • .github/workflows/update-postcodes.yml
🔇 Additional comments (4)
.github/workflows/update-postcodes.yml (4)

1-7: LGTM!

The workflow triggers are well-configured with both a weekly schedule and manual dispatch capability. The cron syntax 0 9 * * 2 correctly targets Tuesdays at 09:00 UTC.


9-14: LGTM!

Permissions are appropriately scoped to the minimum required (contents: write for commits, pull-requests: write for PR creation), following the principle of least privilege.


16-26: LGTM!

The checkout and Node.js setup steps use current action versions. Node.js 22 is an appropriate choice as it's the current LTS release.


28-40: LGTM!

The peter-evans/create-pull-request action is well-configured. As noted in previous review discussions, this action automatically handles change detection and only creates a PR when changes exist, so no explicit check is needed. The delete-branch: true option ensures clean branch management after merge.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.github/workflows/update-postcodes.yml:
- Around line 28-37: The "Check for changes" step (id: changes) uses git diff
--quiet which returns no change for an untracked/new postcodes/registry.json;
update the run logic to detect new or modified files by checking git status
--porcelain for postcodes/registry.json (or use git ls-files --error-unmatch to
detect tracked vs untracked) and write "changed=true" to GITHUB_OUTPUT when git
status returns a non-empty result, otherwise write "changed=false".
🧹 Nitpick comments (2)
.github/scripts/download-postcodes.js (1)

16-21: Consider adding a timeout for fetch reliability.

The external API could hang or respond slowly, causing the CI job to wait indefinitely. Consider adding a timeout using AbortSignal.timeout():

♻️ Suggested improvement
 async function downloadData() {
   console.log(`Downloading from ${DATA_URL}...`);
-  const response = await fetch(DATA_URL);
+  const response = await fetch(DATA_URL, {
+    signal: AbortSignal.timeout(30000), // 30 second timeout
+  });
   if (!response.ok) {
     throw new Error(`Failed to download: ${response.status} ${response.statusText}`);
   }
.github/workflows/update-postcodes.yml (1)

39-52: LGTM! Well-configured automated PR creation.

The PR action is properly configured with appropriate commit message, descriptive body, and branch cleanup. The conditional execution based on change detection ensures PRs are only created when needed.

Optional enhancement: Consider adding labels (e.g., automated, dependencies) to help filter/identify automated PRs:

          labels: automated, postcodes
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36ce225 and a05e657.

📒 Files selected for processing (2)
  • .github/scripts/download-postcodes.js
  • .github/workflows/update-postcodes.yml
🔇 Additional comments (5)
.github/scripts/download-postcodes.js (4)

16-26: LGTM! Proper error handling and encoding support.

The download function correctly handles HTTP errors and uses the appropriate windows-1252 decoder for ANSI-encoded Norwegian text, which will properly handle special characters like Ø, Æ, and Å.


28-45: LGTM! Robust parsing with proper validation.

Good defensive coding: validates tab-separated format, trims whitespace, and enforces 4-digit zip code format with regex. This handles malformed lines gracefully.


47-64: LGTM! Efficient indexed storage design.

The approach of deduplicating place names with 1-based indexing and using a fixed 10000-element mapping array for direct zip-to-index lookup is space-efficient and provides O(1) lookup time. The design is well-suited for serving as a static CDN asset.


66-90: LGTM! Clean orchestration and error handling.

The main function properly orchestrates the workflow with appropriate logging, and the entry point handles both success and failure cases with correct exit codes for CI integration.

.github/workflows/update-postcodes.yml (1)

1-14: LGTM! Appropriate workflow configuration.

The schedule, manual dispatch trigger, and permissions are well-configured. The contents: write and pull-requests: write permissions follow least-privilege principles for this use case.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.github/workflows/update-postcodes.yml:
- Around line 28-37: The step with id "changes" has inverted logic: the test if
[ -n "$(git status --porcelain postcodes/registry.json)" ] is true when there
ARE changes, but the script currently sets changed=false; swap the outputs so
that when the test is true you echo "changed=true" and when false you echo
"changed=false" (update the two echo lines inside the if/else in the "Check for
changes" step that call "$GITHUB_OUTPUT" and the corresponding user messages).
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a05e657 and 872662a.

📒 Files selected for processing (1)
  • .github/workflows/update-postcodes.yml
🔇 Additional comments (1)
.github/workflows/update-postcodes.yml (1)

39-52: PR creation configuration looks good.

The step correctly gates on the change detection output and uses appropriate settings for automated PRs (descriptive branch name, auto-delete branch, clear commit message and body).

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
Member

@tjololo tjololo left a comment

Choose a reason for hiding this comment

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

Don't know to much about the wanted format and can't do a full review of the js code but all in all LGTM.
One comment to eval on the action side

@tjololo tjololo merged commit 7457079 into Altinn:master Jan 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants