Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This is a GitHub Action created for complex pull request approval scenarios whic
- [Rules syntax](#rules-syntax)
- [Basic Rule syntax](#basic-rule-syntax)
- [AND Rule syntax](#and-rule-syntax)
- [AND DISTINCT Rule syntax](#and-distinct-rule-syntax)
- [OR Rule syntax](#or-rule-syntax)
- [Workflow configuration](#workflow-configuration)
- [GitHub repository configuration](#github-repository-configuration)
Expand Down Expand Up @@ -137,7 +138,9 @@ rules:
#### AND Rule syntax <a name="and-rule-syntax"></a>

AND Rules will only match if **all** subconditions listed in `all` are
fulfilled.
fulfilled. Note that each subcondition is treated independently and therefore a
single approval can count towards multiple subconditions; for an alternative,
check [AND DISTINCT rules](#and-distinct-rule-syntax).

```yaml
rules:
Expand All @@ -158,6 +161,45 @@ rules:
Visit [Basic Rule syntax](#basic-rule-syntax) for the full explanation of each
field.

#### AND DISTINCT Rule syntax <a name="and-distinct-rule-syntax"></a>

AND DISTINCT Rules work like [AND Rules](#and-rule-syntax) in the sense that all
subconditions have to be fulfilled, except that each approval contributes at
most **once** for a single subcondition, i.e. all approvals throughout all
subconditions have to come from different users (hence the name DISTINCT).

```yaml
rules:
- name: Rule name
condition: .*
check_type: diff
all_distinct:
- min_approvals: 1
teams:
- Team 1
- min_approvals: 1
teams:
- Team 2
```

The common use-case for this rule is requiring that approvals come from
different teams even if one of the teams is a subset of another. Suppose the
following structure:

```
── Team1 (one approval required)
└── User1
── Team2 (one approval required)
├── User1
└── User2
```

For AND Rules, if User1 would approve the pull request, since they belong to
*both* Team1 and Team2, *both* subconditions would be fulfilled. By comparison,
for AND DISTINCT Rules the second subcondition would not be fulfilled with
User1's approval alone because his approval already counted towards the first
subcondition.

#### OR Rule syntax <a name="or-rule-syntax"></a>

OR Rules will match if **any** subconditions listed in `any` are fulfilled.
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ export const rulesConfigurations: RulesConfigurations = {
basic: {
kind: "BasicRule",
uniqueFields: ["min_approvals", "teams", "users"],
invalidFields: ["any", "all"],
invalidFields: ["any", "all", "all_distinct"],
},
and: {
kind: "AndRule",
uniqueFields: ["all"],
invalidFields: ["min_approvals", "teams", "users", "any"],
invalidFields: ["min_approvals", "teams", "users", "any", "all_distinct"],
},
or: {
kind: "OrRule",
uniqueFields: ["any"],
invalidFields: ["min_approvals", "teams", "users", "all"],
invalidFields: ["min_approvals", "teams", "users", "all", "all_distinct"],
},
and_distinct: {
kind: "AndDistinctRule",
uniqueFields: ["all_distinct"],
invalidFields: ["min_approvals", "teams", "users", "all", "any"],
},
}

Expand Down
Loading