Skip to content

Comments

feat(heroes): Add hero background images support#377

Merged
TeKrop merged 1 commit intomainfrom
376-get-hero-background-image
Feb 21, 2026
Merged

feat(heroes): Add hero background images support#377
TeKrop merged 1 commit intomainfrom
376-get-hero-background-image

Conversation

@TeKrop
Copy link
Owner

@TeKrop TeKrop commented Feb 21, 2026

Summary by Sourcery

Add structured support for hero background images across models and Blizzard hero parsing.

New Features:

  • Introduce a BackgroundImageSize enum to represent responsive breakpoint sizes for hero background images.
  • Add a HeroBackground model and a backgrounds field on the Hero model to store hero background images and their responsive size groups.
  • Parse hero background images and their breakpoint sizes from the Blizzard hero overview section into the hero summary data.

@TeKrop TeKrop self-assigned this Feb 21, 2026
@TeKrop TeKrop added the enhancement New feature or request label Feb 21, 2026
@TeKrop TeKrop linked an issue Feb 21, 2026 that may be closed by this pull request
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 21, 2026

Reviewer's Guide

Adds support for hero background images by introducing a new BackgroundImageSize enum and HeroBackground model, wiring them into the Hero schema, and extending the Blizzard hero parser to extract background images and their responsive breakpoints.

Class diagram for new hero background image support

classDiagram
    class BaseModel
    class Role

    class BackgroundImageSize {
        <<enum>>
        MIN
        XS
        SM
        MD
        LG
        XL_PLUS
    }

    class HeroBackground {
        +HttpUrl url
        +list~BackgroundImageSize~ sizes
    }

    class Hero {
        +str name
        +str description
        +list~HeroBackground~ backgrounds
        +Role role
        +list~str~ images
    }

    Hero *-- HeroBackground : backgrounds
    HeroBackground --> BackgroundImageSize : sizes
    Hero --> Role : role
    HeroBackground ..> BaseModel
    Hero ..> BaseModel
Loading

Flow diagram for updated hero summary parsing with backgrounds

flowchart TD
    A[overview_section input] --> B[Extract header_section and extra_list_items]
    B --> C[Extract icon_element and icon_url]
    B --> D[Select blz-image elements with slot=background]
    D --> E[Filter images with src attribute]
    E --> F[For each image, read src as url]
    F --> G[Read bp attribute, split into sizes list]
    G --> H[Build list of background dicts url and sizes]
    B --> I[Extract name and description]
    B --> J[Extract location and birthday]
    C --> K[Derive role from icon_url]
    I --> L[Assemble hero summary dict]
    J --> L
    K --> L
    H --> L
    L[Return hero summary with name, description, backgrounds, role, location, birthday]
Loading

File-Level Changes

Change Details Files
Introduce a model for hero background images and attach it to the Hero schema.
  • Add HeroBackground Pydantic model with url and sizes fields for background images.
  • Extend Hero model with a backgrounds field containing a list of HeroBackground entries, including rich examples for API documentation.
  • Import the new BackgroundImageSize enum into the heroes models module for type-safe background sizes.
app/heroes/models.py
Define an enum for responsive background image sizes.
  • Create BackgroundImageSize StrEnum representing responsive breakpoints (min, xs, sm, md, lg, xl+).
  • Document the enum as the canonical source of allowed hero background size values.
app/heroes/enums.py
Parse hero background images and their responsive sizes from the Blizzard HTML into the hero summary payload.
  • Select blz-image elements with slot=background from the overview section and collect their src and bp attributes.
  • Normalize the bp attribute into a list of size tokens for the sizes field.
  • Include the parsed backgrounds list in the dictionary returned by _parse_hero_summary so downstream layers can populate Hero.backgrounds.
app/adapters/blizzard/parsers/hero.py

Assessment against linked issues

Issue Objective Addressed Explanation
#376 Add data model/schema support to represent hero background images (including URL and responsive breakpoint sizes) on the hero resource returned by the API.
#376 Parse the hero background images and their breakpoint sizes from the Overwatch hero page (blz-page-header / blz-image elements) and populate the hero model with this data.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sonarqubecloud
Copy link

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `app/heroes/models.py:10-17` </location>
<code_context>
+from .enums import BackgroundImageSize, HeroGamemode, HeroKey, MediaType
+
+
+class HeroBackground(BaseModel):
+    url: HttpUrl = Field(
+        ...,
+        description="URL of the background image",
+        examples=[
+            "https://blz-contentstack-images.akamaized.net/v3/assets/blt2477dcaf4ebd440c/blt242e79efb1e27251/631a8b791566e20e82f30288/1600_Cassidy.jpg",
+        ],
+    )
+    sizes: list[BackgroundImageSize] = Field(
+        ...,
</code_context>

<issue_to_address>
**suggestion:** Consider enforcing at least one breakpoint size per HeroBackground entry.

As defined, `sizes: list[BackgroundImageSize]` allows an empty list, so a background may not be usable at any breakpoint. Consider enforcing `min_items=1` (or equivalent) so each `HeroBackground` is guaranteed to apply to at least one size.
</issue_to_address>

### Comment 2
<location> `app/adapters/blizzard/parsers/hero.py:102-109` </location>
<code_context>
     icon_element = extra_list_items[0].css_first("blz-icon")
     icon_url = safe_get_attribute(icon_element, "src")

+    backgrounds = [
+        {
+            "url": img.attributes["src"],
+            "sizes": (img.attributes.get("bp") or "").split(),
+        }
+        for img in overview_section.css("blz-image[slot=background]")
+        if img.attributes.get("src")
+    ]
+
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Skip background images that have no breakpoint sizes instead of returning entries with an empty sizes list.

This will add backgrounds for any `blz-image[slot=background]` with a `src`, even when `bp` is missing, producing entries with `sizes: []`. If every background is expected to have at least one breakpoint, consider also requiring a non-empty `bp` in the comprehension (e.g. `if img.attributes.get("src") and img.attributes.get("bp")`) or filtering out entries whose computed `sizes` is empty so unusable background objects aren’t created.

```suggestion
    backgrounds = [
        {
            "url": img.attributes["src"],
            "sizes": (img.attributes.get("bp") or "").split(),
        }
        for img in overview_section.css("blz-image[slot=background]")
        if img.attributes.get("src") and img.attributes.get("bp")
    ]
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@TeKrop TeKrop merged commit 9d0c147 into main Feb 21, 2026
5 checks passed
@TeKrop TeKrop deleted the 376-get-hero-background-image branch February 21, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get hero background image

1 participant