|
| 1 | +# Script Functions |
| 2 | + |
| 3 | +!!! tip "The [Expr Language Definition](https://expr-lang.org/docs/language-definition) is a great resource to learn more about the language" |
| 4 | + |
| 5 | +## pull_request |
| 6 | + |
| 7 | +### `pull_request.state_is(string...) -> boolean` {: #pull_request.state_is data-toc-label="state_is"} |
| 8 | + |
| 9 | +Check if the `pull_request` state is any of the provided states |
| 10 | + |
| 11 | +**Valid options**: |
| 12 | + |
| 13 | +- `CLOSED` - In closed state |
| 14 | +- `MERGED` - Pull Request has been merged |
| 15 | +- `OPEN` - Opened Pull Request |
| 16 | + |
| 17 | +```css |
| 18 | +pull_request.state_is("MERGED") |
| 19 | +pull_request.state_is("CLOSED", "MERGED") |
| 20 | +``` |
| 21 | + |
| 22 | +### `pull_request.modified_files(string...) -> boolean` {: #pull_request.modified_files data-toc-label="modified_files"} |
| 23 | + |
| 24 | +Returns wether any of the provided files patterns have been modified in the Pull Request. |
| 25 | + |
| 26 | +The file patterns use the [`.gitignore` format](https://git-scm.com/docs/gitignore#_pattern_format). |
| 27 | + |
| 28 | +```css |
| 29 | +pull_request.modified_files("*.go", "docs/") == true |
| 30 | +``` |
| 31 | + |
| 32 | +### `pull_request.modified_files_list(string...) -> []string` {: #pull_request.modified_files_list data-toc-label="modified_files_list"} |
| 33 | + |
| 34 | +Returns an array of files matching the provided (optional) pattern thas has been modified in the Pull Request. |
| 35 | + |
| 36 | +The file patterns use the [`.gitignore` format](https://git-scm.com/docs/gitignore#_pattern_format). |
| 37 | + |
| 38 | +```css |
| 39 | +pull_request.modified_files_list("*.go", "docs/") == ["example/file.go", "docs/index.md"] |
| 40 | +``` |
| 41 | + |
| 42 | +### `pull_request.has_label(string) -> boolean` {: #pull_request.has_label data-toc-label="has_label"} |
| 43 | + |
| 44 | +Returns wether any of the provided label exist on the Pull Request. |
| 45 | + |
| 46 | +```css |
| 47 | +pull_request.labels = ["hello"] |
| 48 | +pull_request.has_label("hello") == true |
| 49 | +pull_request.has_label("world") == false |
| 50 | +``` |
| 51 | + |
| 52 | +### `pull_request.has_no_label(string) -> boolean` {: #pull_request.has_no_label data-toc-label="has_no_label"} |
| 53 | + |
| 54 | +Returns wether the Pull Request has the provided label or not. |
| 55 | + |
| 56 | +```css |
| 57 | +pull_request.labels = ["hello"] |
| 58 | +pull_request.has_no_label("hello") == false |
| 59 | +pull_request.has_no_label("world") == true |
| 60 | +``` |
| 61 | + |
| 62 | +## Global |
| 63 | + |
| 64 | +### `duration(string) -> duration` {: #duration data-toc-label="duration"} |
| 65 | + |
| 66 | +Returns the [`time.Duration`](https://pkg.go.dev/time#Duration) value of the given string str. |
| 67 | + |
| 68 | +Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d" and "w". |
| 69 | + |
| 70 | +```css |
| 71 | +duration("1h").Seconds() == 3600 |
| 72 | +``` |
| 73 | + |
| 74 | +### `uniq([]string) -> []string` {: #uniq data-toc-label="uniq"} |
| 75 | + |
| 76 | +Returns a new array where all duplicate values has been removed. |
| 77 | + |
| 78 | +```css |
| 79 | +(["hello", "world", "world"] | uniq) == ["hello", "world"] |
| 80 | +``` |
| 81 | + |
| 82 | +### `filepath_dir` {: #filepath_dir data-toc-label="filepath_dir"} |
| 83 | + |
| 84 | +`filepath_dir` returns all but the last element of path, typically the path's directory. After dropping the final element, |
| 85 | + |
| 86 | +Dir calls [Clean](https://pkg.go.dev/path/filepath#Clean) on the path and trailing slashes are removed. |
| 87 | + |
| 88 | +If the path is empty, `filepath_dir` returns ".". If the path consists entirely of separators, `filepath_dir` returns a single separator. |
| 89 | + |
| 90 | +The returned path does not end in a separator unless it is the root directory. |
| 91 | + |
| 92 | +```css |
| 93 | +filepath_dir("example/directory/file.go") == "example/directory" |
| 94 | +``` |
| 95 | + |
| 96 | +### `limit_path_depth_to` {: #limit_path_depth_to data-toc-label="limit_path_depth_to"} |
| 97 | + |
| 98 | +`limit_path_depth_to` takes a path structure, and limits it to the configured maximum depth. Particularly useful when using `generated` labels from a directory structure, and want to to have a label naming scheme that only uses path of the path. |
| 99 | + |
| 100 | +```css |
| 101 | +limit_path_depth_to("path1/path2/path3/path4", 2), == "path1/path2" |
| 102 | +limit_path_depth_to("path1/path2", 3), == "path1/path2" |
| 103 | +``` |
0 commit comments