Repository navigation
feat: filter subscriptions by build type - #86
Conversation
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]>
Reviewer's GuideAPIDefine the public build-type fields, validation contract, and notification behavior in the OpenAPI specification, together with the 400 problem response for undeclared types.
ImplementationAdd repository build-type declaration and update behavior, plus shared validation and atomic declaration filters used when recording builds and subscriptions.
Centralize subscription/build matching so build-type filters affect notification delivery while preserving the existing commit-type and value checks.
DocumentationExplain how to declare, publish, and subscribe to build types, and document the deployment compatibility and repository-update behavior.
TestsCover end-to-end build-type declaration, validation, filtering, repository updates, and races where types are removed before recording.
Test repository build-type validation and confirm repository registration returns only its identifier and access token.
Test build-type matching for typed, untyped, and non-list stored subscription values, alongside existing match constraints.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
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]>
Summary
Lets subscribers get only builds of specific types (option A of #7):
build_types(at registration, or later withPUT /repositories/{id}).build_type; it must be one the repository declares, otherwise400.build_types(unique, at most 50); each must be declared by the repository, otherwise400. Empty or missing means all builds, as before.build_typesdon't match untyped builds; the notification of such a subscription isskipped.docs/deployment.md).POST /repositoriesnow returns exactly{id, access_token}, built explicitly.Matching lives in one helper (
matches()inpubgrade/modules/endpoints/subscriptions.py); undeclared types raiseUndeclaredBuildType(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; newtests/integration/test_build_types.pyand unit tests forcheck_build_typesandmatchesruff check,ruff format --check,mypy: cleanmkdocs build --strict: cleanDeclined review findings
Treat non-list
build_typesin 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.pywithtests/integration/test_api.py: the new ones take extra fields; merging them would change many existing tests for little gain.Sourcery: add
build_typeto theBuildresponse schema: it already has it, viaallOfBuildRegister.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:
Enhancements:
Documentation:
Tests: