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

feat: maxPendingReviews condition #1170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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