Repository navigation
Follow-up fixes for the GitHub rulesets feature - #93
Conversation
The previous implementation parsed the wrong field from the REST API response, causing app slug resolution to always fail. Switch to Github.get_app() for correct and stable resolution.
Unpack the (status, headers, body) tuple from requestJson directly instead of using the broken _extract_json_payload heuristic, which returned the headers dict instead of the body. Raise distinct exceptions for the documented error codes (404, 500) and for unexpected response formats.
Add add_ruleset, update_ruleset and delete_ruleset helpers that check the return status of each REST call and raise descriptive exceptions. Error responses include the GitHub errors array for field-level detail.
…efs/tags/ When using the convenience 'branches' key, bare patterns are now automatically prefixed so users do not need to know the internal ref format. The 'refs' key still passes patterns through unchanged.
|
@kaxil, can you take a look at this? |
kaxil
left a comment
There was a problem hiding this comment.
Nice follow-up. The error handling and get_app() switch are solid improvements. Confirmed that requestJson returns (int, dict, str) so the json.loads(body) approach is correct. Exception chaining, API status codes, and ref prefixing test coverage all look good. Four findings inline.
|
With the current version, I was successfully able to create rulesets for However, since |
### What changes were proposed in this PR? Reverts #4582 (commit `1045997b0e8f6bee850a27af53e65ae406d70481`), which added a `release/*` ruleset to `.asf.yaml`. ASF infra's support for the `rulesets` directive is still incomplete (see also #4607 / apache/infrastructure-asfyaml#93). We'll protect release branches via a different mechanism in a follow-up; reverting for now to keep `.asf.yaml` clean and to unblock #4600. ### Any related issues, documentation, discussions? Reopens #4579. Unblocks #4600. ### How was this PR tested? Verified the ruleset never actually took effect — `GET /repos/apache/texera/rulesets` returns `[]` and `GET /repos/apache/texera/rules/branches/release/v1.1.0-incubating` returns `[]`. So this revert is effectively a no-op against live GitHub state and only cleans up `.asf.yaml`. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 4.7)
|
Nice One ! |
|
@Humbedooh, thanks a lot! We'll test Rulesets again in apache/logging-parent#477 and if the works, we'll switch the other repos to Rulesets too. |
Cool. I am going to try it too. |
|
(Unless @kaxil will beat me to it of course - I see he liked your response @ppkarwasz !) |
Haha you go for it, I will be out and mostly AFK for about 2 weeks. |
…e#4616) ### What changes were proposed in this PR? Reverts apache#4582 (commit `cfed1392322c9415b20f2d66542c42570235b618`), which added a `release/*` ruleset to `.asf.yaml`. ASF infra's support for the `rulesets` directive is still incomplete (see also apache#4607 / apache/infrastructure-asfyaml#93). We'll protect release branches via a different mechanism in a follow-up; reverting for now to keep `.asf.yaml` clean and to unblock apache#4600. ### Any related issues, documentation, discussions? Reopens apache#4579. Unblocks apache#4600. ### How was this PR tested? Verified the ruleset never actually took effect — `GET /repos/apache/texera/rulesets` returns `[]` and `GET /repos/apache/texera/rules/branches/release/v1.1.0-incubating` returns `[]`. So this revert is effectively a no-op against live GitHub state and only cleans up `.asf.yaml`. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 4.7)
…e#4616) ### What changes were proposed in this PR? Reverts apache#4582 (commit `1045997b0e8f6bee850a27af53e65ae406d70481`), which added a `release/*` ruleset to `.asf.yaml`. ASF infra's support for the `rulesets` directive is still incomplete (see also apache#4607 / apache/infrastructure-asfyaml#93). We'll protect release branches via a different mechanism in a follow-up; reverting for now to keep `.asf.yaml` clean and to unblock apache#4600. ### Any related issues, documentation, discussions? Reopens apache#4579. Unblocks apache#4600. ### How was this PR tested? Verified the ruleset never actually took effect — `GET /repos/apache/texera/rulesets` returns `[]` and `GET /repos/apache/texera/rules/branches/release/v1.1.0-incubating` returns `[]`. So this revert is effectively a no-op against live GitHub state and only cleans up `.asf.yaml`. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Opus 4.7)
* Switch to GitHub Rulesets (second attempt) The first attempt (#456) had to be reverted in #471 because a bug in ASFYaml made the resulting rulesets impossible to modify or remove through `.asf.yaml`. We rolled back to the legacy `protected_branches` configuration. apache/infrastructure-asfyaml#93 has now landed and addresses the underlying issues (broken `app_slug` resolution, silent REST API failures, missing `refs/heads/` / `refs/tags/` prefixing), so we can move back to Rulesets. The benefits over `protected_branches` remain: - Tag references can also be protected (see the new `rel/*` ruleset). - A single ruleset can target a glob of refs (e.g. `gha/*`) instead of one branch at a time. - Rules are publicly visible at https://github.com/apache/logging-parent/rules, so we can verify that the effective rules are those configured and third parties can audit the project's protection policy too. * fix: use raw syntax for tags * fix: remove `protected_branches` No longer needed since apache/infrastructure-asfyaml#121 was merged.
This PR hardens the rulesets implementation introduced in #89, focusing on correctness and error reporting:
Github.get_app()for correct resolution.UnknownObjectException.list_rulesets,add_ruleset,update_ruleset,delete_ruleset) that check the HTTP status and raise descriptive exceptions.brancheskey, bare patterns are automatically prefixed withrefs/heads/(branch rulesets) orrefs/tags/(tag rulesets), so users don't need to use the internal ref format.