Skip to content

Commit 376cf83

Browse files
Apply suggetstions from code review
Co-authored-by: Misha Kav <[email protected]>
1 parent a8e2c28 commit 376cf83

File tree

1 file changed

+54
-8
lines changed

1 file changed

+54
-8
lines changed

docs/filter-functions.md

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,15 @@ Return `true` for each element in the list that match the search term.
235235

236236
</div>
237237

238-
For example, to check if all code changes are in the `tests` directory:
238+
Examples:
239+
240+
Check if all code changes are in the `tests` directory:
239241

240242
```yaml+jinja
241243
{{ files | match(regex=r/tests\//) | every }}
242244
```
243245

244-
For example, to check if there are code changes with specific function call:
246+
Check if there are code changes with specific function call:
245247

246248
```yaml+jinja
247249
{{ source.diff.files | match(attr='diff', term='myFunction') | some }}
@@ -281,13 +283,15 @@ Creates a shallow copy of a portion of a given list, filtered down to just the e
281283

282284
</div>
283285

284-
For example, check if all changes, but JavaScript files are in tests directory:
286+
Examples:
287+
288+
Check if all changes, but JavaScript files are in tests directory:
285289

286290
```yaml+jinja
287291
{{ files | reject(regex=r/\.js$/) | match(regex=r/tests\//') | every }}
288292
```
289293

290-
For example, check if all changes except for `config.json` files are formatting:
294+
Check if all changes except for `config.json` files are formatting:
291295

292296
```yaml+jinja
293297
{{ source.diff.files | reject(attr='new_file', regex=r/config\.json$/) | isFormattingChange }}
@@ -922,11 +926,13 @@ Reads the contents of a file from the current branch or the `cm` repo and return
922926
| Argument | Usage | Type | Description |
923927
| -------- | ------ | ------ | ------------------------------------------------------------------- |
924928
| - | Input | String | The relative file path in the current repo. Prepend `../cm/` to get files from the `cm` repo |
925-
| `output` | Input | String | The content type. Optional, `txt` by default. Allowed options are `txt` or `json`. When using `json`, the output will be returned as an Object |
926-
| - | Output | String/ Object | The contents of the file as a String or Object |
929+
| `output` | Input | String | The content type. Optional, `txt` by default. Allowed options are `txt` or `json`. When using `json`, the output will be returned as a stringified Object |
930+
| - | Output | String | The contents of the file as a String. In case of `json` output, the result will be `JSON.stringified` |
927931
</div>
928932

929-
For example, add a comment with a file's content:
933+
Examples:
934+
935+
Add a comment with a file's content:
930936

931937
```yaml+jinja
932938
automations:
@@ -939,5 +945,45 @@ automations:
939945
comment: |
940946
{{ README_CONTENT }}
941947
942-
README_CONTENT: {{ "./README.md" | readFile(output="txt") }}
948+
README_CONTENT: {{ "./README.md" | readFile() }}
943949
```
950+
951+
Read JSON configuration file from the `cm` repo and use some of the properties in a comment:
952+
```
953+
automations:
954+
describe_teams:
955+
if:
956+
- {{ true }}
957+
run:
958+
- action: add-comment@v1
959+
args:
960+
comment: |
961+
We have {{ TEAMS | length }} teams with {{ TEAMS.front.members | length + TEAMS.back.members | length }} members in total:
962+
FrontEnd: include {{ TEAMS.front.members | length }} members
963+
BackEnd: include {{ TEAMS.back.members | length }} members
964+
965+
966+
TEAMS: {{ "../cm/.TEAMS.json" | readFile(output="json") }}
967+
```
968+
969+
Configuration file example:
970+
``` JSON
971+
{
972+
"front": {
973+
"name": "Frontend",
974+
"description": "Frontend team",
975+
"members": [
976+
"John",
977+
"Jane"
978+
]
979+
},
980+
"back": {
981+
"name": "Backend",
982+
"description": "Backend team",
983+
"members": [
984+
"Alice",
985+
"Bob"
986+
]
987+
}
988+
}
989+
```

0 commit comments

Comments
 (0)