Skip to content

Commit ea3d6a3

Browse files
committed
docs: document dynamic pull request reviewers
Signed-off-by: sahil-sharma <sahil.sharma@protonmail.com>
1 parent 4c128e9 commit ea3d6a3

3 files changed

Lines changed: 83 additions & 2 deletions

File tree

‎docs/advanced-usage/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ Advanced configuration topics for GitOps Promoter:
22

33
* [Using a Custom Hydrator](custom-hydrator.md)
44
* [Dynamic Pull Request Labels](pull-request-labels.md)
5+
* [Dynamic Pull Request Reviewers](pull-request-reviewers.md)
56
* [Configuring Multi-Tenancy](multi-tenancy.md)
67
* [Dashboard Aggregation API](dashboard-apiserver.md)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.

‎docs/monitoring/metrics.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Labels:
4242
* `api`: The SCM API being called (CommitStatus, PullRequest)
4343
* `operation`: The type of SCM operation.
4444
* For CommitStatus, this is always create.
45-
* For PullRequest, this is create, update, merge, close, list, get, create-label, add-labels, or remove-labels.
45+
* For PullRequest, this is create, update, merge, close, list, get, create-label, add-labels, remove-labels, add-reviewers, or remove-reviewers.
4646
* `response_code`: The HTTP response code.
4747

4848
## scm_calls_duration_seconds
@@ -57,7 +57,7 @@ Labels:
5757
* `api`: The SCM API being called (CommitStatus, PullRequest)
5858
* `operation`: The type of SCM operation.
5959
* For CommitStatus, this is always create.
60-
* For PullRequest, this is create, update, merge, close, list, get, create-label, add-labels, or remove-labels.
60+
* For PullRequest, this is create, update, merge, close, list, get, create-label, add-labels, remove-labels, add-reviewers, or remove-reviewers.
6161
* `response_code`: The HTTP response code.
6262

6363
## webrequest_commit_status_http_requests_total

0 commit comments

Comments
 (0)