|
| 1 | +# Dynamic Pull Request Reviewers |
| 2 | + |
| 3 | +GitOps Promoter can request **SCM reviews** on promotion pull requests, using an [expr](https://github.com/expr-lang/expr) expression to decide who is asked. This puts the people responsible for approving a promotion on the pull request as soon as it is opened, and lets them find promotion PRs with their SCM's native "review requested" filters. |
| 4 | + |
| 5 | +## Configure on PromotionStrategy |
| 6 | + |
| 7 | +Configure reviewers at the top level of `PromotionStrategy`. The PromotionStrategy controller copies `spec.pullRequest` onto each generated `ChangeTransferPolicy`. |
| 8 | + |
| 9 | +```yaml |
| 10 | +apiVersion: promoter.argoproj.io/v1alpha1 |
| 11 | +kind: PromotionStrategy |
| 12 | +metadata: |
| 13 | + name: my-app |
| 14 | +spec: |
| 15 | + gitRepositoryRef: |
| 16 | + name: my-repo |
| 17 | + pullRequest: |
| 18 | + reviewers: |
| 19 | + expression: | |
| 20 | + let autoMerge = Spec.AutoMerge ?? true; |
| 21 | + autoMerge ? [] : |
| 22 | + Spec.ActiveBranch == 'environment/production' |
| 23 | + ? ['alice', {group: 'release-managers'}] |
| 24 | + : ['charlie'] |
| 25 | + environments: |
| 26 | + - branch: environment/development |
| 27 | + autoMerge: true |
| 28 | + - branch: environment/staging |
| 29 | + autoMerge: false |
| 30 | + - branch: environment/production |
| 31 | + autoMerge: false |
| 32 | +``` |
| 33 | +
|
| 34 | +> [!NOTE] |
| 35 | +> There is no per-environment `reviewers` field. Reviewers are made environment-specific through the |
| 36 | +> `Spec.ActiveBranch` expression variable, which is always the branch name for the environment under |
| 37 | +> evaluation. |
| 38 | + |
| 39 | +## Reviewer values |
| 40 | + |
| 41 | +Each item the expression returns is either: |
| 42 | + |
| 43 | +| Form | Meaning | |
| 44 | +|------|---------| |
| 45 | +| `'alice'` | a username; shorthand for `{user: 'alice'}` | |
| 46 | +| `{user: 'alice'}` | a username | |
| 47 | +| `{group: 'release-managers'}` | a group or team; on GitHub, an organization team slug | |
| 48 | + |
| 49 | +The object form exists so other identifier kinds (numeric IDs, emails, UUIDs) can be added for providers that cannot resolve plain names. At most 10 reviewers may be returned, and each must be non-empty, at most 100 characters, and free of whitespace. |
| 50 | + |
| 51 | +## autoMerge |
| 52 | + |
| 53 | +Reviewers are not skipped automatically for auto-merged environments. Gate them in the expression, as above: `Spec.AutoMerge` is the `autoMerge` value for the environment being promoted, and is unset when the field is omitted (which defaults to `true`). |
| 54 | + |
| 55 | +## How it works |
| 56 | + |
| 57 | +1. **PromotionStrategy → ChangeTransferPolicy**: `spec.pullRequest` is copied to each CTP. |
| 58 | +2. **ChangeTransferPolicy → PullRequest**: The CTP controller evaluates `pullRequest.reviewers.expression`, validates the result, and writes `PullRequest.spec.reviewers`. |
| 59 | +3. **PullRequest → SCM**: The PullRequest controller compares `spec.reviewers` with `status.appliedReviewers`, requests reviews for anything added, withdraws requests for anything removed, and records the result in `status.appliedReviewers`. |
| 60 | + |
| 61 | +Reviewers are kept in sync with the expression's result: dropping a reviewer withdraws the request. Only reviewers recorded in `status.appliedReviewers` are candidates for removal, so reviewers added out of band on the SCM are left alone. Whatever the SCM does by default when a reviewer is re-added applies unchanged — GitOps Promoter does not inspect or manipulate review state. |
| 62 | + |
| 63 | +Because reviewers are re-evaluated on every reconcile, prefer expressions keyed on stable inputs such as `Spec.ActiveBranch` over ones keyed on commit status phases, which flip as gates run. |
| 64 | + |
| 65 | +## Expression context |
| 66 | + |
| 67 | +The expression is evaluated with the same variables as [pull request labels](pull-request-labels.md#expression-context): `Status`, `Spec`, and `PromotionStrategy`. |
| 68 | + |
| 69 | +## Provider support |
| 70 | + |
| 71 | +| Provider | Reviewers | |
| 72 | +|----------|-----------| |
| 73 | +| GitHub | supported; users and organization teams | |
| 74 | +| GitLab | not yet implemented | |
| 75 | +| Gitea | not yet implemented | |
| 76 | +| Forgejo | not yet implemented | |
| 77 | +| Azure DevOps | not yet implemented | |
| 78 | +| Bitbucket Cloud | not yet implemented | |
| 79 | + |
| 80 | +Configuring reviewers for a repository on a provider that does not implement them fails the PullRequest reconcile with a clear error rather than being silently ignored; the `Ready` condition on the `PullRequest` carries the message. |
0 commit comments