Skip to content

feat: filter subscriptions by build type - #86

Merged
uniqueg merged 5 commits into
devfrom
feat/7-build-types
Nov 7, 2026
Merged

uniqueg merged 5 commits into
devfrom
feat/7-build-types

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Lets subscribers get only builds of specific types (option A of #7):

  • A repository may declare build_types (at registration, or later with PUT /repositories/{id}).
  • A build may have a build_type; it must be one the repository declares, otherwise 400.
  • A subscription may have build_types (unique, at most 50); each must be declared by the repository, otherwise 400. Empty or missing means all builds, as before.
  • Subscriptions with build_types don't match untyped builds; the notification of such a subscription is skipped.
  • Nothing needs migrating: stored repositories, builds and subscriptions have no types, so subscriptions keep getting all builds. Responses carry the new fields where they are set, so strict clients need to accept them (upgrade note in docs/deployment.md).
  • POST /repositories now returns exactly {id, access_token}, built explicitly.

Matching lives in one helper (matches() in pubgrade/modules/endpoints/subscriptions.py); undeclared types raise UndeclaredBuildType (problem details, fixed detail).

Docs: docs/usage.md (declaring types, typed builds, filtered subscriptions, untyped builds not matching filtered subscriptions), docs/deployment.md (upgrade note), OpenAPI descriptions.

Closes #7

Verification

  • pytest --cov (unit + integration): 619 passed, 100% coverage; new tests/integration/test_build_types.py and unit tests for check_build_types and matches
  • ruff check, ruff format --check, mypy: clean
  • mkdocs build --strict: clean
  • pre-commit hooks that need network for installs not run locally; they run in CI
  • Review: two rounds of adversarial and quality reviewer subagents; no high or medium findings
  • CI on 9f1a11b: all checks passed
  • Sourcery: 4 findings; 3 fixed in 00d7202 (types checked atomically when a build or subscription is listed in its repository, so a concurrent PUT can't leave undeclared types; non-empty filter and registration response clarified), 1 declined (below)

Declined review findings

  • Treat non-list build_types in stored subscriptions as an error instead of "no filter": Pubgrade never writes such values (the schema requires a list); the guard keeps old or hand-edited records from breaking notifications, and the docstring says so.

  • Old records with unexpected values: accepted under "nothing needs migrating"; matching is guarded as above.

  • Share the request helpers of tests/integration/test_build_types.py with tests/integration/test_api.py: the new ones take extra fields; merging them would change many existing tests for little gain.

  • Sourcery: add build_type to the Build response schema: it already has it, via allOf BuildRegister.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Add optional build-type declarations and subscription filtering while maintaining backward compatibility for existing untyped data.

New Features:

  • Allow repositories to declare build types, builds to use declared types, and subscriptions to filter notifications by selected types.
  • Expose build type information in repository, subscription, and build responses with validation and clear errors for undeclared types.

Enhancements:

  • Preserve existing behavior for untyped repositories, builds, and subscriptions while preventing filtered subscriptions from matching untyped builds.
  • Return only the repository identifier and access token when registering a repository.

Documentation:

  • Document build type declaration, publishing, subscription filtering, notification behavior, and upgrade compatibility.

Tests:

  • Add integration and unit coverage for build type validation, filtering, repository updates, and notification matching.

uniqueg and others added 3 commits November 7, 2026 21:42
Repositories may declare build_types, builds may name one of them as
build_type, and subscriptions may list build_types to get only builds
of these types. Missing or empty build_types match all builds, as
before; with them, builds without a type do not match. Types that the
repository does not declare get a 400. PUT /repositories changes the
build types only if it gives them. Stored data needs no migration.

Closes #7

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Move the matching of subscriptions and builds into matches(), which
treats build_types that are not a list as no filter, and test it
directly. Build the registration response of repositories explicitly.
Mention build_types in the notification callback, the responses that
show build types, and the limit of 50 per subscription.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The response holds only the identifier and the access token, also
when the repository declares build types.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Define the public build-type fields, validation contract, and notification behavior in the OpenAPI specification, together with the 400 problem response for undeclared types.

  • pubgrade/api/pubgrade.yaml L1186-1192, L1267-1278, L1298-1316 (+3 small edits)
  • pubgrade/errors/exceptions.py L90-95, L269-276

Implementation

Add repository build-type declaration and update behavior, plus shared validation and atomic declaration filters used when recording builds and subscriptions.

  • pubgrade/modules/endpoints/builds.py L201-209 (+4 small edits)
  • pubgrade/modules/endpoints/repositories.py L94-98, L186-189, L229-259 (+5 small edits)
  • pubgrade/modules/endpoints/subscriptions.py L21-31, L130-135, L143-149 (+2 small edits)

Centralize subscription/build matching so build-type filters affect notification delivery while preserving the existing commit-type and value checks.

  • pubgrade/modules/endpoints/subscriptions.py L275-277, L303, L344-370

Documentation

Explain how to declare, publish, and subscribe to build types, and document the deployment compatibility and repository-update behavior.

  • docs/deployment.md L191-193, L200-207
  • docs/usage.md L19-27, L73-81, L96-100 (+2 small edits)

Tests

Cover end-to-end build-type declaration, validation, filtering, repository updates, and races where types are removed before recording.

  • tests/integration/test_build_types.py L1-233

Test repository build-type validation and confirm repository registration returns only its identifier and access token.

  • tests/pubgrade/endpoints/test_repositories.py L92-97, L882-905 (+2 small edits)

Test build-type matching for typed, untyped, and non-list stored subscription values, alongside existing match constraints.

  • tests/pubgrade/endpoints/test_subscriptions.py L29, L974-1008

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

@read-the-docs-community

read-the-docs-community Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (579c4f0) to head (aae99b8).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev       #86   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines         1471      1497   +26     
=========================================
+ Hits          1471      1497   +26     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@uniqueg
uniqueg marked this pull request as ready for review November 7, 2026 21:26
@uniqueg
uniqueg requested a review from akash2237778 as a code owner November 7, 2026 21:26

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 4 issues

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

## Individual Comments

### Comment 1
<location path="pubgrade/modules/endpoints/repositories.py" line_range="222" />
<code_context>
+    changes: dict[str, Any] = {"url": url}
+    if "build_types" in data:
+        changes["build_types"] = data["build_types"]
+    result = db_collection_repository.update_one({"id": repo_id}, {"$set": changes})
     if result.matched_count == 0:
         raise RepositoryNotFound
</code_context>
<issue_to_address>
**Undeclared types get registered**

When a concurrent PUT removes a type after a build or subscription registration reads the repository but before it writes, `register_builds` and `register_subscription` validate against the earlier repository snapshot, then write without checking that the declared types are unchanged. The registration stores a build or subscription with a type the repository no longer declares.

Make the type check and registration atomic with changes to the repository’s declared types.

Also at `pubgrade/modules/endpoints/builds.py:188-189`, `pubgrade/modules/endpoints/subscriptions.py:92`.
</issue_to_address>

### Comment 2
<location path="pubgrade/api/pubgrade.yaml" line_range="1179-1185" />
<code_context>
            commit hash in it (4 to 64 hexadecimal digits); otherwise the
            request gets a 400."
           example: {"branch": "dev", "commit_sha": "4714900" }
+        build_type:
+          allOf:
+            - $ref: '#/components/schemas/BuildType'
+          description: Type of the build, one of the repository's
+            `build_types` (otherwise the request gets a 400). Subscriptions
+            with `build_types` get only builds of these types; builds without
+            a type go only to subscriptions without `build_types`.
       required:
           - images
</code_context>
<issue_to_address>
**Build responses omit the new field**

When a client relies on the OpenAPI `Build` schema for build-list or build-detail responses, the new `build_type` property is added to `BuildRegister`, but the build-list and build-detail responses reference the separate `Build` schema, which does not gain this property. Generated clients and response validators using the published schema therefore reject or hide `build_type` returned by those endpoints.

Add the optional `build_type` property to the `Build` response schema as well as `BuildRegister`.
</issue_to_address>

### Comment 3
<location path="docs/deployment.md" line_range="206" />
<code_context>
+  [Usage](usage.md#subscribe-to-a-repository)). Nothing needs to change:
+  stored repositories, builds and subscriptions have none, so subscriptions
+  get all builds, as before. Responses have these fields where they are
+  set: clients that reject unknown fields need to accept them.
 - **Builds:** `DELETE /repositories/{id}/builds/{build_id}` cancels a build
   (see [Usage](usage.md#cancel-a-build)), and the status of builds has the
</code_context>
<issue_to_address>
**Registration response omits declared types**

Clients following “Responses have these fields where they are set” expect the newly declared `build_types` in the repository registration response, but `register_repository` returns only `id` and `access_token`; callers must make a separate GET request to learn the declared types.

Clarify that registration responses omit `build_types` and that clients can retrieve them with `GET /repositories/{id}`.

Also at `pubgrade/modules/endpoints/repositories.py:95-98`.
</issue_to_address>

### Comment 4
<location path="docs/usage.md" line_range="99" />
<code_context>
+If the repository declares build types, the build may name one of them with
+`"build_type": "<build type>"`; a type that the repository doesn't declare
+gets a 400. A build without a type reaches only subscriptions without
+`build_types`.
+
 ## Notifications
</code_context>
<issue_to_address>
**Empty filters described as active**

When a subscription sends `build_types: []`, an empty `build_types` list is valid and matches all builds, but these descriptions imply that merely having the field filters out untyped builds. Callers following the usage guide or OpenAPI descriptions expect those builds to be skipped even though `matches()` delivers them.

Clarify in the usage guide and OpenAPI descriptions that only a nonempty `build_types` list filters builds.

Also at `pubgrade/api/pubgrade.yaml:587-588`, `pubgrade/api/pubgrade.yaml:1184-1185`.
</issue_to_address>

Linked issues

#7 How a subscription can listen to just specific updates? · 2 of 2 met

# Requirement Status Notes
1 The developer can provide the available build types. ✅ Met Repositories accept build_types at registration and update, and expose them in repository details.
2 The administrator can specify build types for a subscription from the developer's available types. ✅ Met Subscriptions accept build_types and reject any type not declared by the repository.

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and if the build-type match is wrong, Pubgrade can send a notification to a subscription callback that should not receive it; once the HTTP request is sent, reverting cannot recall it. Reverting does stop future notifications using the new filter.

Blocking findings: pubgrade/modules/endpoints/repositories.py:222, pubgrade/api/pubgrade.yaml:1185


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread pubgrade/api/pubgrade.yaml Resolved
Comment thread docs/deployment.md Resolved
Comment thread docs/usage.md Resolved
uniqueg and others added 2 commits November 7, 2026 22:46
The update that lists a build or a subscription in its repository now
requires the repository to declare their types, so that types removed
by a concurrent PUT after the check aren't stored; such requests get a
400. Docs: only a non-empty build_types filters, and the registration
response stays id and access_token.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 3f501b7 into dev Nov 7, 2026
33 checks passed
@uniqueg
uniqueg deleted the feat/7-build-types branch November 7, 2026 21:57
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.

How a subscription can listen to just specific updates?

1 participant