README.md in gitlab-triage-1.0.1 vs README.md in gitlab-triage-1.1.0

- old
+ new

@@ -890,10 +890,11 @@ -s, --source [type] The source type between [ projects or groups ], default value: projects -i, --source-id [string] Source ID or path -p, --project-id [string] [Deprecated] A project ID or path, please use `--source-id` -t, --token [string] A valid API token -H, --host-url [string] A valid host url + -r, --require [string] Require a file before performing -d, --debug Print debug information -h, --help Print help message --init Initialize the project with a policy file --init-ci Initialize the project with a .gitlab-ci.yml file ``` @@ -941,9 +942,55 @@ ##### Policy file ```yml host_url: https://gitlab.host.com resource_rules: +``` + +#### Can I customize? + +You can take the advantage of command line option `-r` or `--require` to +load a Ruby file before performing the actions. This allows you to do +whatever you want. For example, you can put this in a file like `my_plugin.rb`: + +```ruby +module MyPlugin + def has_severity_label? + labels.grep(/^S\d+$/).any? + end + + def has_priority_label? + labels.grep(/^P\d+$/).any? + end + + def labels + resource[:labels] + end +end + +Gitlab::Triage::Resource::Context.include MyPlugin +``` + +And then run it with: + +```shell +gitlab-triage -r ./my_plugin.rb --token $API_TOKEN --source-id gitlab-org/triage +``` + +This allows you to use `has_severity_label?` in the Ruby condition: + +```yml +resource_rules: + issues: + rules: + - name: Apply default severity or priority labels + conditions: + ruby: | + !has_severity_label? || !has_priority_label? + actions: + comment: | + #{'/label ~S3' unless has_severity_label?} + #{'/label ~P3' unless has_priority_label?} ``` ### Contributing Please refer to the [Contributing Guide](CONTRIBUTING.md).