|
| 1 | +# Automation actions |
| 2 | + |
| 3 | +Actions are the end results of the automation described in your `.cm` file. |
| 4 | + |
| 5 | +!!! note |
| 6 | + |
| 7 | + Items marked with :octicons-beaker-24: are under development and are not available yet. |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +gitStream executes actions in the order they are listed. If an action result fails, following actions will not be executed. |
| 12 | + |
| 13 | +- [`add-comment`](#add-comment) |
| 14 | +- [`add-label`](#add-label) |
| 15 | +- [`add-labels`](#add-labels) |
| 16 | +- [`add-reviewers`](#add-reviewers) |
| 17 | +- [`approve`](#approve) |
| 18 | +- [`close`](#close) |
| 19 | +- [`merge`](#merge) |
| 20 | +- [`set-required-approvals`](#set-required-approvals) |
| 21 | +- [`require-reviewers`](#require-reviewers) |
| 22 | +- [`request-changes`](#request-changes) |
| 23 | + |
| 24 | +!!! note |
| 25 | + |
| 26 | + Multiple actions can be listed in a single automation. The actions are invoked one by one. |
| 27 | + |
| 28 | +#### Dynamic actions arguments |
| 29 | + |
| 30 | +Arguments values a dynamic value is supported using expressions based on Jinja2 syntax, and includes gitStream context variables, for example: |
| 31 | + |
| 32 | +```yaml+jinja |
| 33 | +automations: |
| 34 | + pr_complexity: |
| 35 | + if: |
| 36 | + - true |
| 37 | + run: |
| 38 | + - action: add-comment@v1 |
| 39 | + args: |
| 40 | + comment: "Estimated {{ branch | estimatedReviewTime }} minutes to review" |
| 41 | +``` |
| 42 | + |
| 43 | + |
| 44 | +## Reference |
| 45 | + |
| 46 | +#### `add-comment` |
| 47 | + |
| 48 | +This action, once triggered, adds a comment to the PR. |
| 49 | + |
| 50 | +<div class="filter-details" markdown=1> |
| 51 | + |
| 52 | +| Args | Usage | Type | Description | |
| 53 | +| -----------|------|-----|------------------------------------------------ | |
| 54 | +| `comment` | Required | String | Sets the comment, markdown is supported | |
| 55 | + |
| 56 | +</div> |
| 57 | + |
| 58 | +```yaml+jinja title="example" |
| 59 | +automations: |
| 60 | + senior_review: |
| 61 | + if: |
| 62 | + - {{ files | match(term='core/') | some }} |
| 63 | + run: |
| 64 | + - action: add-comment@v1 |
| 65 | + args: |
| 66 | + comment: | |
| 67 | + Core service update |
| 68 | + (Updates API) |
| 69 | +``` |
| 70 | + |
| 71 | + |
| 72 | +#### `add-label` |
| 73 | + |
| 74 | +This action, once triggered, adds a label to the PR. |
| 75 | + |
| 76 | +This is a manged action, when a PR updates existing labels that were added by gitStream are re-evaluated and those that are not applicable are removed. |
| 77 | + |
| 78 | +<div class="filter-details" markdown=1> |
| 79 | + |
| 80 | +| Args | Usage | Type | Description | |
| 81 | +| -----------|------|-----|------------------------------------------------ | |
| 82 | +| `label` | Required |String | The label text any string can work | |
| 83 | +| `color` | Optional |String | The color in hexa, for exmaple: `'FEFEFE'` (you can also add `#` prefix `#FEFEFE`) | |
| 84 | + |
| 85 | +</div> |
| 86 | + |
| 87 | +```yaml+jinja title="example" |
| 88 | +automations: |
| 89 | + senior_review: |
| 90 | + if: |
| 91 | + - {{ files | match(term='api/') | some }} |
| 92 | + run: |
| 93 | + - action: add-label@v1 |
| 94 | + args: |
| 95 | + label: api-change |
| 96 | +``` |
| 97 | + |
| 98 | +#### `add-labels` |
| 99 | + |
| 100 | +This action, once triggered, adds a list of labels to the PR. |
| 101 | + |
| 102 | +This is a manged action, when a PR updates existing labels that were added by gitStream are re-evaluated and those that are not applicable are removed. |
| 103 | + |
| 104 | +<div class="filter-details" markdown=1> |
| 105 | + |
| 106 | +| Args | Usage | Type | Description | |
| 107 | +| -----------|------|-----|------------------------------------------------ | |
| 108 | +| `labels` | Required |[String] | The list of text labels| |
| 109 | + |
| 110 | +</div> |
| 111 | + |
| 112 | + |
| 113 | +#### `add-reviewers` |
| 114 | + |
| 115 | +This action, once triggered, sets a specific reviewer. |
| 116 | + |
| 117 | +<div class="filter-details" markdown=1> |
| 118 | + |
| 119 | +| Args | Usage | Type | Description | |
| 120 | +| -----------|------|-----|------------------------------------------------ | |
| 121 | +| `reviewers` | Required or `team_reviewers` | [String] | Sets reviewers user name | |
| 122 | +| `team_reviewers` | Required or `reviewers` | [String] | Sets reviewers teams name, without the `@` prefix | |
| 123 | + |
| 124 | +</div> |
| 125 | + |
| 126 | +```yaml+jinja title="example" |
| 127 | +automations: |
| 128 | + senior_review: |
| 129 | + if: |
| 130 | + - {{ files | match(term='src/ui/') }} |
| 131 | + run: |
| 132 | + - action: add-reviewers@v1 |
| 133 | + args: |
| 134 | + reviewers: [popeye, olive] |
| 135 | +``` |
| 136 | + |
| 137 | + |
| 138 | +#### `approve` |
| 139 | + |
| 140 | +This action, once triggered, approves the PR for merge. |
| 141 | + |
| 142 | +This is a manged action, when a PR updates existing approval by gitStream is re-evaluated and removed if no longer applicable. |
| 143 | + |
| 144 | +```yaml+jinja title="example" |
| 145 | +automations: |
| 146 | + small_change: |
| 147 | + if: |
| 148 | + - {{ source.diff.files | isFormattingChange }} |
| 149 | + run: |
| 150 | + - action: approve@v1 |
| 151 | +``` |
| 152 | + |
| 153 | +#### `close` |
| 154 | + |
| 155 | +This action, once triggered, close the PR without merging. |
| 156 | + |
| 157 | +```yaml+jinja title="example" |
| 158 | +automations: |
| 159 | + close_ui_changes_by_non_ui: |
| 160 | + if: |
| 161 | + - {{ files | match(regex=r/src\/views/) | some }} |
| 162 | + - {{ pr.author_teams | match(term='ui-team') | nope }} |
| 163 | + run: |
| 164 | + - action: add-comment@v1 |
| 165 | + args: |
| 166 | + comment: | |
| 167 | + Please contact a member of `ui-team` team if you need to make changes to files in `src/views` |
| 168 | + - action: close@v1 |
| 169 | +``` |
| 170 | + |
| 171 | +#### `merge` |
| 172 | + |
| 173 | +Once triggered, merge the PR if possible. It can set to wait for required checks to pass or ignore checks. |
| 174 | + |
| 175 | +<div class="filter-details" markdown=1> |
| 176 | + |
| 177 | +| Args | Usage | Type | Description | |
| 178 | +| -----------|------|-----|------------------------------------------------ | |
| 179 | +| `wait_for_all_checks`| Optional | Boolean | By default `false`, so only Required checks can block merge, when `true` the action won't merrge even if non-Required check fail | |
| 180 | +| `rebase_on_merge`| Optional | Boolean | By default `false`, when merging use rebase mode | |
| 181 | +| `squash_on_merge`| Optional | Boolean | By default `false`, when merging use squash mode | |
| 182 | + |
| 183 | +</div> |
| 184 | + |
| 185 | +```yaml+jinja title="example" |
| 186 | +automations: |
| 187 | + small_change: |
| 188 | + if: |
| 189 | + - {{ files | allDocs }} |
| 190 | + run: |
| 191 | + - action: merge@v1 |
| 192 | + args: |
| 193 | + rebase_on_merge: true |
| 194 | +``` |
| 195 | + |
| 196 | + |
| 197 | +#### `set-required-approvals` |
| 198 | + |
| 199 | +This action, once triggered, blocks PR merge till the desired reviewers approved the PR. The actions fail the check to prevent the PR for merge. |
| 200 | + |
| 201 | +!!! note |
| 202 | + |
| 203 | + You should enable branch protection, so GitHub will prevent merging unless the gitStream action check pass successfully. |
| 204 | + |
| 205 | +<div class="filter-details" markdown=1> |
| 206 | + |
| 207 | +| Args | Usage | Type | Description | |
| 208 | +| -----------|-----|------|------------------------------------------------ | |
| 209 | +| `approvals`| Required | Integer | Sets the number of required reviewer approvals for merge for that PR| |
| 210 | + |
| 211 | +</div> |
| 212 | + |
| 213 | +```yaml+jinja title="example" |
| 214 | +automations: |
| 215 | + double_review: |
| 216 | + if: |
| 217 | + - {{ files | match(regex=r/agent\//) | some }} |
| 218 | + run: |
| 219 | + - action: set-required-approvals@v1 |
| 220 | + args: |
| 221 | + approvals: 2 |
| 222 | +``` |
| 223 | + |
| 224 | + |
| 225 | +#### `request-changes` |
| 226 | + |
| 227 | +This action, once triggered, request changes on the PR. As long as request change is set, gitStream will block the PR merge. |
| 228 | + |
| 229 | +This is a manged action, when a PR updates existing change request by gitStream is re-evaluated and removed if no longer applicable. |
| 230 | + |
| 231 | +<div class="filter-details" markdown=1> |
| 232 | + |
| 233 | +| Args | Usage | Type | Description | |
| 234 | +| -----------|-----|------|------------------------------------------------ | |
| 235 | +| `comment` | Required | [String] | The desired request changes comment | |
| 236 | + |
| 237 | +</div> |
| 238 | + |
| 239 | +```yaml+jinja title="example" |
| 240 | +automations: |
| 241 | + catch_deprecated: |
| 242 | + if: |
| 243 | + - {{ source.diff.files | matchDiffLines(regex=r/^[+].*oldFetch\(/') | some }} |
| 244 | + run: |
| 245 | + - action: request-changes@v1 |
| 246 | + args: |
| 247 | + comment: | |
| 248 | + You have used deprected API `oldFetch`, use `newFetch` instead. |
| 249 | +``` |
| 250 | + |
| 251 | +#### `require-reviewers` |
| 252 | + |
| 253 | +This action, once triggered, requires a specific reviewer approval. |
| 254 | + |
| 255 | +<div class="filter-details" markdown=1> |
| 256 | + |
| 257 | +| Args | Usage | Type | Description | |
| 258 | +| -----------|----|-------|------------------------------------------------ | |
| 259 | +| `reviewers` | Required | [String] | Sets reviewers user name, merge is blocked till approved by any of the listed users | |
| 260 | +| :octicons-beaker-24: `also_assign` | Optional | Bool | `true` by default, also assign the specified users as reviewers | |
| 261 | + |
| 262 | +</div> |
| 263 | + |
| 264 | +```yaml+jinja title="example" |
| 265 | +automations: |
| 266 | + senior_review: |
| 267 | + if: |
| 268 | + - {{ files | match(regex=r/src\/ui\//) | some }} |
| 269 | + run: |
| 270 | + - action: require-reviewers@v1 |
| 271 | + args: |
| 272 | + reviewers: ['popeye', 'olive'] |
| 273 | +``` |
0 commit comments