Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for approval conditions #752

Merged
merged 2 commits into from
Apr 9, 2024
Merged

Add support for approval conditions #752

merged 2 commits into from
Apr 9, 2024

Conversation

bluekeyes
Copy link
Member

Many users try to use Policy Bot as a general purpose rule engine, constructing policies that enforce things about status checks, labels, and other conditions. This was poorly supported because predicates skip rules when the conditions don't match, whereas users working in this model expect the rule to apply, but remain in the pending state.

This commit introduces the concept of "conditions", which are predicates that count toward approval. All of the existing predicates tests are available, but when used as a condition they control whether the rule is pending or approved, instead of active or skipped.

Conditions can combine with regular approval requirements, but I expect most uses will either use predicates and regular approval or conditions without additional approval.

Due to limitations in how predicates work internally, the details UI shows limited information about conditions. I hope to fix this in a follow-up, but I wanted to separate the main change from the predicate refactoring.

Finally, this adds a new README section explaining how to design a policy and what all the different terms mean.

I'm open to a different name for this new feature, since it's easy to accidentally say "condition" when talking about predicates, but I couldn't think of anything else that fit better.

This is an alternative to #750, which only works for status checks. See also #627.

Many users try to use Policy Bot as a general purpose rule engine,
constructing policies that enforce things about status checks, labels,
and other conditions. This was poorly supported because predicates skip
rules when the conditions don't match, whereas users working in this
model expect the rule to apply, but remain in the pending state.

This commit introduces the concept of "conditions", which are predicates
that count toward approval. All of the existing predicates tests are
available, but when used as a condition they control whether the rule is
pending or approved, instead of active or skipped.

Conditions can combine with regular approval requirements, but I expect
most uses will either use predicates and regular approval or conditions
without additional approval.

Due to limitations in how predicates work internally, the details UI
shows limited information about conditions. I hope to fix this in a
follow-up, but I wanted to separate the main change from the predicate
refactoring.

Finally, this adds a new README section explaining how to design a
policy and what all the different terms mean.
README.md Outdated Show resolved Hide resolved
@Andrei-Predoiu
Copy link

I think this is a good solution.

asvoboda
asvoboda previously approved these changes Apr 8, 2024
Copy link
Member

@asvoboda asvoboda left a comment

Choose a reason for hiding this comment

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

This seems like a pretty straightforward approach to including conditions.

I'm less certain about how we'd want to use this internally, but it seems like a relatively friendly feature to include for oss.

@@ -213,6 +221,11 @@

{{define "result-reviews-count"}}This rule requires at least {{.Count}} approval{{if gt .Count 1}}s{{end}}{{end}}

{{define "result-conditions-details"}}
{{/* TODO(bkeyes): this is a placeholder until I can refactor predicate rendering */}}
Copy link
Member

Choose a reason for hiding this comment

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

If this something you want to do in a follow up PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, trying to refactor the predicate display in this PR was going to overwhelm the actual changes.

@policy-bot policy-bot bot dismissed asvoboda’s stale review April 8, 2024 18:18

Invalidated by push of 03d3388

@bluekeyes bluekeyes marked this pull request as ready for review April 8, 2024 18:21
@bluekeyes bluekeyes requested a review from a team April 8, 2024 18:27
@bluekeyes bluekeyes merged commit c6fa07d into develop Apr 9, 2024
7 checks passed
@bluekeyes bluekeyes deleted the bkeyes/conditions branch April 9, 2024 03:39
@bluekeyes
Copy link
Member Author

If you are able to deploy snapshot versions, this feature is now available in the palantirtechnologies/policy-bot:snapshot image for testing.

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.

5 participants