Skip to content

Follow-up fixes for the GitHub rulesets feature - #93

Merged
Humbedooh merged 10 commits into
apache:mainfrom
ppkarwasz:fix/rulesets-error-handling
May 3, 2026
Merged

Humbedooh merged 10 commits into
apache:mainfrom
ppkarwasz:fix/rulesets-error-handling

Conversation

@ppkarwasz

Copy link
Copy Markdown
Member

This PR hardens the rulesets implementation introduced in #89, focusing on correctness and error reporting:

  • App slug resolution: the previous implementation called the REST API directly and parsed the wrong field from the response, so app slug resolution always silently failed. Switched to Github.get_app() for correct resolution.
  • Team slug resolution: unresolvable bypass team slugs now raise a clear error with exception chaining instead of a bare UnknownObjectException.
  • REST API error handling: all direct REST API calls are now wrapped in dedicated helpers (list_rulesets, add_ruleset, update_ruleset, delete_ruleset) that check the HTTP status and raise descriptive exceptions.
  • Ref pattern prefixing: when using the convenience branches key, bare patterns are automatically prefixed with refs/heads/ (branch rulesets) or refs/tags/ (tag rulesets), so users don't need to use the internal ref format.

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.
@ppkarwasz

Copy link
Copy Markdown
Member Author

@kaxil, can you take a look at this?

Comment thread asfyaml/feature/github/rulesets.py Resolved

@kaxil kaxil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread asfyaml/feature/github/rulesets.py Resolved
Comment thread asfyaml/feature/github/rulesets.py Resolved
Comment thread tests/github_rulesets.py Resolved
@ppkarwasz

Copy link
Copy Markdown
Member Author

@Humbedooh,

With the current version, I was successfully able to create rulesets for logging-parent: https://github.com/apache/logging-parent/rules

However, since list_rulesets doesn't find any existing rules, it is impossible to either modify nor remove the rules previously added. It is not a problem for us, since by experience we tested on a dummy branch, but could be a problem for other testers.

Yicong-Huang added a commit to apache/texera that referenced this pull request May 1, 2026
### 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)
@potiuk

potiuk commented May 3, 2026

Copy link
Copy Markdown
Member

Nice One !

@Humbedooh
Humbedooh merged commit ca2dc58 into apache:main May 3, 2026
5 checks passed
@ppkarwasz
ppkarwasz deleted the fix/rulesets-error-handling branch May 3, 2026 13:06
@ppkarwasz

Copy link
Copy Markdown
Member Author

@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.

@potiuk

potiuk commented May 3, 2026

Copy link
Copy Markdown
Member

@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.

@potiuk

potiuk commented May 3, 2026

Copy link
Copy Markdown
Member

(Unless @kaxil will beat me to it of course - I see he liked your response @ppkarwasz !)

@kaxil

kaxil commented May 3, 2026

Copy link
Copy Markdown
Member

(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.

SarahAsad23 pushed a commit to SarahAsad23/texera that referenced this pull request May 4, 2026
…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)
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…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)
ppkarwasz added a commit to apache/logging-parent that referenced this pull request Aug 16, 2026
* 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.
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.

4 participants