Skip to content

support refactored json format#33

Merged
igorpecovnik merged 1 commit intomasterfrom
json-format-v2
Dec 20, 2025
Merged

support refactored json format#33
igorpecovnik merged 1 commit intomasterfrom
json-format-v2

Conversation

@efectn
Copy link
Copy Markdown
Member

@efectn efectn commented Dec 20, 2025

No description provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 20, 2025

Walkthrough

The changes refactor the file extension mapping logic in map.go by replacing explicit per-extension handling with a data-driven loop over a predefined extensionFormats variable containing [".asc", ".sha", ".torrent"]. For each file processed, the code now generates additional map entries by iterating through these extensions. Correspondingly, map_test.go removes several asset entries from the test JSON data, reducing the coverage of extension-specific mappings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • The refactoring from explicit per-extension handling to loop-based generation requires careful verification that all mappings are correctly preserved
  • The logic for filtering which extensions to apply (when file extension does not match) needs scrutiny to ensure correctness
  • The removal of test assets (khadas-vim1, khadas-vim4, and uefi-arm64 entries) requires understanding the rationale and verifying test coverage remains adequate
  • The two files are interdependent—understanding the logic change and its test impact requires examining both files together

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive No description was provided by the author, making it impossible to evaluate whether it relates to the changeset. Add a pull request description explaining the changes made and why the refactoring was necessary.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'support refactored json format' is related to the changeset, which modifies the JSON parsing logic in map.go and adjusts test data in map_test.go to support a new format.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch json-format-v2

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
Copy Markdown

@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

🧹 Nitpick comments (2)
map.go (2)

21-21: Consider making this immutable or documenting its mutability.

Since extensionFormats contains static values that shouldn't change at runtime, consider either:

  • Using a constant with a compile-time array, or
  • Adding a comment explaining why it's a variable if runtime modification is intended
Alternative: Use a constant-like pattern

If Go version supports it, or add a comment:

+// extensionFormats defines auxiliary file extensions that should be mapped for each main asset.
+// These files are expected to exist alongside the main asset file.
 var extensionFormats = []string{".asc", ".sha", ".torrent"}

141-144: Consider edge case: empty file extension.

The code appends "." unconditionally at line 141 before appending file.Extension at line 142. If file.Extension is empty or unexpected, this could create malformed keys like "board/distro.".

While the JSON structure likely ensures Extension is always populated, consider adding defensive validation earlier in the loop for robustness.

Optional: Add validation for empty extension
 	for _, file := range data.Assets {
+		if file.Extension == "" {
+			log.WithFields(log.Fields{
+				"board": file.BoardSlug,
+			}).Warning("Missing file extension; skipping entry")
+			continue
+		}
+
 		// Because download mapping a full URL, redirecting, and finding a server again is redundant,
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2376dbb and 52ba36c.

📒 Files selected for processing (2)
  • map.go (2 hunks)
  • map_test.go (0 hunks)
💤 Files with no reviewable changes (1)
  • map_test.go
🔇 Additional comments (1)
map.go (1)

132-144: Document JSON format changes and add file existence validation.

This refactoring auto-generates auxiliary file mappings (.asc, .sha, .torrent) instead of including them in the JSON source, but lacks documentation and validation:

  1. JSON format undocumented: The README does not document the expected JSON structure or that auxiliary files should be excluded. The code references GitHub issue #129 but provides no user-facing documentation of this breaking change.

  2. No file existence validation: The code assumes all auxiliary files exist at path + ext (e.g., file.img.xz.sha) without validation. Missing files will cause 404 errors for users requesting auxiliary mappings.

  3. No migration guidance: If existing JSON producers still include auxiliary entries, they create incorrect duplicate mappings. No backwards compatibility or migration strategy is documented.

Comment thread map.go
Comment on lines +132 to 139
// Also add entries for .asc .sha and .torrent
for _, ext := range extensionFormats {
if strings.HasSuffix(file.Extension, ext) {
continue
}

if strings.HasSuffix(file.Extension, ".sha") {
sb.WriteString("sha")
} else if strings.HasSuffix(file.Extension, ".asc") {
sb.WriteString("asc")
} else if strings.HasSuffix(file.Extension, ".torrent") {
sb.WriteString("torrent")
} else {
sb.WriteString(file.Extension)
m[sb.String()+ext] = u.Path + ext
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Validate or document that JSON should exclude auxiliary file entries.

The refactored logic assumes the input JSON contains only main asset files (e.g., img.xz), not auxiliary files (e.g., img.xz.asc, img.xz.sha). It then auto-generates mappings for the auxiliary extensions.

However, if auxiliary file entries are present in the JSON, this creates incorrect mappings. For example, processing an entry with extension="img.xz.asc" would generate mappings to non-existent paths like .../file.img.xz.asc.sha and .../file.img.xz.asc.torrent.

The continue at line 134 only partially mitigates this by skipping the matching extension.

Consider adding validation to warn or skip entries whose extensions end with any value in extensionFormats, as these should no longer appear in the refactored JSON format.

🔎 Suggested validation to detect auxiliary files in JSON
 	for _, file := range data.Assets {
+		// Validate that auxiliary files are not included in the JSON
+		for _, ext := range extensionFormats {
+			if strings.HasSuffix(file.Extension, ext) {
+				log.WithFields(log.Fields{
+					"extension": file.Extension,
+					"board":     file.BoardSlug,
+				}).Warning("Auxiliary file entry detected in JSON; skipping to avoid incorrect mappings")
+				continue
+			}
+		}
+
 		// Because download mapping a full URL, redirecting, and finding a server again is redundant,

Note: You'll need to adjust the control flow to skip to the next file in the outer loop, possibly using a labeled continue or a validation function.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In map.go around lines 132 to 139, the code auto-generates auxiliary mappings
(.asc, .sha, .torrent) but doesn’t guard against input JSON entries that are
already auxiliary files (e.g., extension="img.xz.asc"), which causes incorrect
mappings; add validation at the start of processing each file to detect if
file.Extension ends with any value in extensionFormats and, if so, log a warning
(including file path/extension) and skip that file (use a labeled continue or a
small helper that returns a bool to skip the outer loop iteration), so only
primary asset entries are used to generate auxiliary mappings.

@igorpecovnik igorpecovnik merged commit 902370f into master Dec 20, 2025
2 of 3 checks passed
This was referenced Dec 20, 2025
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