Skip to content

Commit

Permalink
Add maxPendingReviews condition
Browse files Browse the repository at this point in the history
Closes #853
  • Loading branch information
tvuotila committed May 5, 2022
1 parent 3da1900 commit 84519d3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ maxRequestedChanges:
NONE: 0
```

### `maxPendingReviews` (condition, default: .inf)

Similar to `maxRequestedChanges`, maxPendingReviews determines the maximum number of
non-completed reviews before a pull request will be blocked from being automatically
merged.

In the example below, automatic merges will be blocked when one of the owners, members
or collaborators has not completed the requested review.

```yaml
maxPendingReviews:
COLLABORATOR: 0
```

### `blockingBaseBranches` (condition, default: none)

Whenever blocking base branches are configured, pull requests will only be automatically
Expand Down
8 changes: 8 additions & 0 deletions auto-merge.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ requiredReviewers:
maxRequestedChanges:
COLLABORATOR: 0

# The maximum number of pending reviews from each association.
# Setting this number to 0 will prevent automatic merging while not all reviewers have either
# approved or requested changes..
# Pending reviews from associations not defined in this list are ignored for automatic merging.
# Dismissed reviews are ignored for automatic merging.
maxPendingReviews:
COLLABORATOR: 0

# Whether an out-of-date pull request is automatically updated.
# It does so by merging its base on top of the head of the pull request.
# This is the equivalent of clicking the 'Update branch' button.
Expand Down
2 changes: 2 additions & 0 deletions src/conditions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import blockingChecks from './blockingChecks'
import blockingLabels from './blockingLabels'
import blockingTitle from './blockingTitle'
import maximumChangesRequested from './maximumChangesRequested'
import maximumPendingReviews from './maximumPendingReviews'
import mergeable from './mergeable'
import minimumApprovals from './minimumApprovals'
import requiredAuthorRole from './requiredAuthorRole'
Expand All @@ -24,6 +25,7 @@ export const conditions = {
blockingLabels,
blockingTitle,
maximumChangesRequested,
maximumPendingReviews,
mergeable,
minimumApprovals,
requiredAuthorRole,
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type ConditionConfig = {
minApprovals: { [key in CommentAuthorAssociation]?: number },
requiredReviewers: string[],
maxRequestedChanges: { [key in CommentAuthorAssociation]?: number },
maxPendingReviews: { [key in CommentAuthorAssociation]?: number },
requiredBaseBranches: Pattern[],
blockingBaseBranches: Pattern[],
requiredLabels: Pattern[],
Expand Down Expand Up @@ -57,6 +58,8 @@ export const defaultRuleConfig: ConditionConfig = {
maxRequestedChanges: {
NONE: 0
},
maxPendingReviews: {
},
blockingBaseBranches: [],
requiredBaseBranches: [],
blockingLabels: [],
Expand Down Expand Up @@ -101,6 +104,7 @@ const conditionConfigDecoder: Decoder<ConditionConfig> = object({
minApprovals: reviewConfigDecover,
requiredReviewers: array(string()),
maxRequestedChanges: reviewConfigDecover,
maxPendingReviews: reviewConfigDecover,
requiredBaseBranches: array(patternDecoder),
blockingBaseBranches: array(patternDecoder),
requiredLabels: array(patternDecoder),
Expand All @@ -117,6 +121,7 @@ const configDecoder: Decoder<Config> = object({
minApprovals: reviewConfigDecover,
requiredReviewers: array(string()),
maxRequestedChanges: reviewConfigDecover,
maxPendingReviews: reviewConfigDecover,
requiredBaseBranches: array(patternDecoder),
blockingBaseBranches: array(patternDecoder),
requiredLabels: array(patternDecoder),
Expand Down
10 changes: 10 additions & 0 deletions test/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ export function review (options: Partial<Review> & { state: PullRequestReviewSta
}
}

export const pendingReview = (options?: Partial<Review>) =>
review({
state: PullRequestReviewState.PENDING,
...options
})
export const dismissedReview = (options?: Partial<Review>) =>
review({
state: PullRequestReviewState.DISMISSED,
...options
})
export const approvedReview = (options?: Partial<Review>) =>
review({
state: PullRequestReviewState.APPROVED,
Expand Down

0 comments on commit 84519d3

Please sign in to comment.