Skip to content

feat(RELEASE-2475): add extract_index_image.py script#865

Draft
johnbieren wants to merge 1 commit into
konflux-ci:mainfrom
johnbieren:release2490
Draft

feat(RELEASE-2475): add extract_index_image.py script#865
johnbieren wants to merge 1 commit into
konflux-ci:mainfrom
johnbieren:release2490

Conversation

@johnbieren

Copy link
Copy Markdown
Collaborator

This commit adds a python script to replicate the functionality of the inline bash script in the extract-index-images managed task in the catalog repo. The task will be updated to use this python module instead.

Assisted-By: Cursor

@codecov-commenter

codecov-commenter commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.68%. Comparing base (86975a4) to head (9eb4e25).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #865      +/-   ##
==========================================
+ Coverage   95.65%   95.68%   +0.02%     
==========================================
  Files          72       73       +1     
  Lines        7118     7159      +41     
==========================================
+ Hits         6809     6850      +41     
  Misses        309      309              
Flag Coverage Δ
unit-tests 95.68% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...cripts/python/tasks/managed/extract_index_image.py 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86975a4...9eb4e25. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@johnbieren

Copy link
Copy Markdown
Collaborator Author

/agentic_review

@qodo-app-for-konflux-ci

qodo-app-for-konflux-ci Bot commented Jul 2, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 25 rules

Grey Divider


Action required

1. test_main_success line too long ✗ Dismissed 📘 Rule violation ⚙ Maintainability ⭐ New
Description
The new test file contains a line that exceeds the required 95-character Black/Flake8 line length,
which will cause formatting/lint checks to fail in CI. Reformat the affected statements to comply
with the configured line length.
Code

scripts/python/tasks/managed/test_extract_index_image.py[R222-225]

+    input_path.write_text(
+        json.dumps({"components": [_component("v4.12", "img:1", "img@sha256:1")]}) + "\n",
+        encoding="utf-8",
+    )
Relevance

⭐⭐⭐ High

Likely required to pass enforced Black/Flake8 CI; no evidence team tolerates E501/overlength lines.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Black/Flake8 are configured to enforce a 95-character maximum line length, and the added
input_path.write_text(...) call includes a json.dumps(...) + "\n" argument on a single long line
that exceeds this limit.

Rule 920: Enforce Black formatting with 95-character line length
Rule 916: Enforce Flake8 with custom configuration (line length 95, ignore E203)
scripts/python/tasks/managed/test_extract_index_image.py[222-225]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A newly added test line exceeds the required 95-character line length, likely failing `black --check --line-length 95` and/or Flake8.

## Issue Context
This repository enforces Black formatting with a 95-character line length and Flake8 with the same limit. The `json.dumps(...) + "\n"` expression in `test_main_success` should be wrapped the way Black expects.

## Fix Focus Areas
- scripts/python/tasks/managed/test_extract_index_image.py[222-225]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Sort crashes on null version ✓ Resolved 🐞 Bug ≡ Correctness
Description
In extract_index_image_results(), sorting by row.get('ocp_version') will raise TypeError when
some components have ocp_version missing/null and others have string versions, crashing the task
before any output is written. This is especially likely because the function later explicitly
handles ocp_version is None, indicating null/missing values are expected.
Code

scripts/python/tasks/managed/extract_index_image.py[R31-45]

+    dict_components = [row for row in raw_components if isinstance(row, dict)]
+    sorted_components = sorted(
+        dict_components,
+        key=lambda row: row.get("ocp_version"),
+    )
+
+    index_image: dict[str, dict[str, Any]] = {}
+    for ocp_version, group in groupby(
+        sorted_components,
+        key=lambda row: row.get("ocp_version"),
+    ):
+        last = list(group)[-1]
+        key = "" if ocp_version is None else str(ocp_version)
+        index_image[key] = {
+            "index_image": last.get("index_image"),
Relevance

⭐⭐⭐ High

Team fixes crashy None-handling in tasks (e.g., guard missing data to avoid task failure in PR
#840).

PR-#840

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The code explicitly expects ocp_version may be None (it converts None to an empty-string key),
but it sorts on the raw ocp_version values first; this will throw when a None key must be
ordered against a string key during sorting.

scripts/python/tasks/managed/extract_index_image.py[26-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`extract_index_image_results()` sorts component dicts using `key=lambda row: row.get("ocp_version")`. If any row has `ocp_version=None` (missing or JSON null) and another row has a string version, Python cannot order `None` vs `str`, so `sorted()` raises `TypeError` and the task fails.

### Issue Context
The function already anticipates `ocp_version` being `None` later (`key = "" if ocp_version is None else str(ocp_version)`), so the sort needs to be made safe for null/missing versions.

### Fix Focus Areas
- scripts/python/tasks/managed/extract_index_image.py[26-47]

### Suggested fix
Prefer removing the sort/groupby entirely and just iterate in original order, overwriting the per-version entry (this naturally keeps the last component per version without any ordering comparisons):

- Initialize `index_image = {}`
- For each `row` in `dict_components`:
 - `ocp_version = row.get("ocp_version")`
 - `key = "" if ocp_version is None else str(ocp_version)`
 - `index_image[key] = {"index_image": row.get(...), "index_image_resolved": row.get(...)}`

If you need deterministic key ordering, sort **after** normalization (e.g., sort by `(key == "", key)` or similar), but avoid directly sorting raw `None`/`str` keys.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Non-imperative module docstring ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The new test module docstring starts with Tests, which is not an imperative verb form as required.
This reduces docstring consistency and violates the project docstring style requirement.
Code

scripts/python/tasks/managed/test_extract_index_image.py[1]

+"""Tests for extract_index_image."""
Relevance

⭐⭐⭐ High

Docstring imperative-mood enforced; merged tests use “Test …” module docstring in PR #837.

PR-#837

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 914 requires module docstrings to be triple-double-quoted and begin with a verb in
imperative mood. The added module docstring """Tests for extract_index_image.""" starts with
Tests rather than an imperative verb like Test.

Rule 914: Require docstrings for modules and public functions in triple-double-quote imperative format
scripts/python/tasks/managed/test_extract_index_image.py[1-1]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The module-level docstring in `test_extract_index_image.py` is not written in imperative mood (it starts with `Tests ...`). The project requires module and public-function docstrings to begin with an imperative verb.

## Issue Context
Update the module docstring to start with an imperative verb (e.g., `Test`, `Validate`, `Verify`).

## Fix Focus Areas
- scripts/python/tasks/managed/test_extract_index_image.py[1-1]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Previous review results

Review updated until commit 9eb4e25

Results up to commit ab72f2b


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. Non-imperative module docstring ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The new test module docstring starts with Tests, which is not an imperative verb form as required.
This reduces docstring consistency and violates the project docstring style requirement.
Code

scripts/python/tasks/managed/test_extract_index_image.py[1]

+"""Tests for extract_index_image."""
Relevance

⭐⭐⭐ High

Docstring imperative-mood enforced; merged tests use “Test …” module docstring in PR #837.

PR-#837

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 914 requires module docstrings to be triple-double-quoted and begin with a verb in
imperative mood. The added module docstring """Tests for extract_index_image.""" starts with
Tests rather than an imperative verb like Test.

Rule 914: Require docstrings for modules and public functions in triple-double-quote imperative format
scripts/python/tasks/managed/test_extract_index_image.py[1-1]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The module-level docstring in `test_extract_index_image.py` is not written in imperative mood (it starts with `Tests ...`). The project requires module and public-function docstrings to begin with an imperative verb.

## Issue Context
Update the module docstring to start with an imperative verb (e.g., `Test`, `Validate`, `Verify`).

## Fix Focus Areas
- scripts/python/tasks/managed/test_extract_index_image.py[1-1]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Sort crashes on null version ✓ Resolved 🐞 Bug ≡ Correctness
Description
In extract_index_image_results(), sorting by row.get('ocp_version') will raise TypeError when
some components have ocp_version missing/null and others have string versions, crashing the task
before any output is written. This is especially likely because the function later explicitly
handles ocp_version is None, indicating null/missing values are expected.
Code

scripts/python/tasks/managed/extract_index_image.py[R31-45]

+    dict_components = [row for row in raw_components if isinstance(row, dict)]
+    sorted_components = sorted(
+        dict_components,
+        key=lambda row: row.get("ocp_version"),
+    )
+
+    index_image: dict[str, dict[str, Any]] = {}
+    for ocp_version, group in groupby(
+        sorted_components,
+        key=lambda row: row.get("ocp_version"),
+    ):
+        last = list(group)[-1]
+        key = "" if ocp_version is None else str(ocp_version)
+        index_image[key] = {
+            "index_image": last.get("index_image"),
Relevance

⭐⭐⭐ High

Team fixes crashy None-handling in tasks (e.g., guard missing data to avoid task failure in PR
#840).

PR-#840

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The code explicitly expects ocp_version may be None (it converts None to an empty-string key),
but it sorts on the raw ocp_version values first; this will throw when a None key must be
ordered against a string key during sorting.

scripts/python/tasks/managed/extract_index_image.py[26-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`extract_index_image_results()` sorts component dicts using `key=lambda row: row.get("ocp_version")`. If any row has `ocp_version=None` (missing or JSON null) and another row has a string version, Python cannot order `None` vs `str`, so `sorted()` raises `TypeError` and the task fails.

### Issue Context
The function already anticipates `ocp_version` being `None` later (`key = "" if ocp_version is None else str(ocp_version)`), so the sort needs to be made safe for null/missing versions.

### Fix Focus Areas
- scripts/python/tasks/managed/extract_index_image.py[26-47]

### Suggested fix
Prefer removing the sort/groupby entirely and just iterate in original order, overwriting the per-version entry (this naturally keeps the last component per version without any ordering comparisons):

- Initialize `index_image = {}`
- For each `row` in `dict_components`:
 - `ocp_version = row.get("ocp_version")`
 - `key = "" if ocp_version is None else str(ocp_version)`
 - `index_image[key] = {"index_image": row.get(...), "index_image_resolved": row.get(...)}`

If you need deterministic key ordering, sort **after** normalization (e.g., sort by `(key == "", key)` or similar), but avoid directly sorting raw `None`/`str` keys.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

Comment thread scripts/python/tasks/managed/test_extract_index_image.py Outdated
Comment thread scripts/python/tasks/managed/extract_index_image.py Outdated
This commit adds a python script to replicate the functionality of the
inline bash script in the extract-index-images managed task in the
catalog repo. The task will be updated to use this python module
instead.

Assisted-By: Cursor

Signed-off-by: Johnny Bieren <jbieren@redhat.com>
@johnbieren

Copy link
Copy Markdown
Collaborator Author

/agentic_review

Comment thread scripts/python/tasks/managed/test_extract_index_image.py
@qodo-app-for-konflux-ci

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 9eb4e25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants