Skip to content

Pick worksheet title when extended_header has multiple keys#265

Merged
soimkim merged 1 commit into
mainfrom
check
Apr 15, 2026
Merged

Pick worksheet title when extended_header has multiple keys#265
soimkim merged 1 commit into
mainfrom
check

Conversation

@soimkim
Copy link
Copy Markdown
Contributor

@soimkim soimkim commented Apr 15, 2026

Description

  • Improved worksheet naming and header row selection when writing result files containing multiple data categories.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

📝 Walkthrough

Walkthrough

Modified constant dictionary formatting with a trailing comma in the SHEET_NAME_FOR_SCANNER entry. Introduced a new helper function _sheet_name_from_extended_header() that intelligently selects sheet names from extended headers using token matching and scoring logic, replacing simple first-key selection in CSV and Excel output functions.

Changes

Cohort / File(s) Summary
Constant Configuration
src/fosslight_util/constant.py
Added trailing comma formatting to FOSSLIGHT_DEPENDENCY entry in SHEET_NAME_FOR_SCANNER dictionary.
Extended Header Selection Logic
src/fosslight_util/write_excel.py
Introduced _sheet_name_from_extended_header() helper function that selects optimal sheet names by scoring candidates based on scanner-name token matching and special BIN_FL/DEP_FL handling. Replaced naive first-key selection with this new logic in both write_result_to_csv() and write_result_to_excel(). Includes deterministic tie-break rules and edge-case handling for empty/single-key extended headers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.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
Title check ✅ Passed The title accurately describes the main change: selecting an appropriate worksheet title when extended_header has multiple keys.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch check

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.

🧹 Nitpick comments (2)
src/fosslight_util/write_excel.py (2)

106-106: Avoid mutable default argument.

Using {} as a default argument is a Python anti-pattern. Although the function uses extended_header read-only, the safer pattern is to use None and initialize inside.

♻️ Proposed fix
-def get_header_row(sheet_name, extended_header={}):
+def get_header_row(sheet_name, extended_header=None):
+    if extended_header is None:
+        extended_header = {}
     merged_headers = merge(_HEADER, extended_header)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fosslight_util/write_excel.py` at line 106, The function get_header_row
uses a mutable default argument extended_header={} which is unsafe; change the
signature to use extended_header=None and inside get_header_row initialize
extended_header to an empty dict when None (e.g., if extended_header is None:
extended_header = {}), then proceed using extended_header as before to avoid
shared mutable state across calls.

46-103: Well-structured scoring logic for sheet name selection.

The function effectively addresses the PR objective of selecting appropriate worksheet titles when extended_header has multiple keys. The token matching and tie-breaking logic is sensible.

Minor observation: Line 74's condition "dependency" in sn or sn.endswith("_dependency") has redundancy—if sn.endswith("_dependency"), then "dependency" in sn is already true. This doesn't affect correctness but could be simplified.

♻️ Optional simplification
-        if "dependency" in sn or sn.endswith("_dependency"):
+        if "dependency" in sn:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fosslight_util/write_excel.py` around lines 46 - 103, The condition in
_sheet_name_from_extended_header redundantly checks "dependency" in sn or
sn.endswith("_dependency"); simplify it by removing the endswith check and use a
single check (e.g., if "dependency" in sn) within the scoring block so the
dependency-related scoring branch is clearer and not duplicated.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/fosslight_util/write_excel.py`:
- Line 106: The function get_header_row uses a mutable default argument
extended_header={} which is unsafe; change the signature to use
extended_header=None and inside get_header_row initialize extended_header to an
empty dict when None (e.g., if extended_header is None: extended_header = {}),
then proceed using extended_header as before to avoid shared mutable state
across calls.
- Around line 46-103: The condition in _sheet_name_from_extended_header
redundantly checks "dependency" in sn or sn.endswith("_dependency"); simplify it
by removing the endswith check and use a single check (e.g., if "dependency" in
sn) within the scoring block so the dependency-related scoring branch is clearer
and not duplicated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7cb069ef-2f3f-4d85-b12a-13f46c33ffcc

📥 Commits

Reviewing files that changed from the base of the PR and between 9e5d905 and 90f8997.

📒 Files selected for processing (2)
  • src/fosslight_util/constant.py
  • src/fosslight_util/write_excel.py

@soimkim soimkim changed the title fix(excel): pick worksheet title when extended_header has multiple keys Pick worksheet title when extended_header has multiple keys Apr 15, 2026
@soimkim soimkim self-assigned this Apr 15, 2026
@soimkim soimkim added the chore [PR/Issue] Refactoring, maintenance the code label Apr 15, 2026
@soimkim soimkim merged commit d7d0e89 into main Apr 15, 2026
9 checks passed
@soimkim soimkim deleted the check branch April 15, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore [PR/Issue] Refactoring, maintenance the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant