Class: Danger::LabelsChecker
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::LabelsChecker
- Defined in:
- lib/dangermattic/plugins/labels_checker.rb
Overview
Plugin for checking labels associated with a pull request.
Instance Method Summary collapse
-
#check(do_not_merge_labels: [], required_labels: [], required_labels_error: nil, recommended_labels: [], recommended_labels_warning: nil) ⇒ void
Checks if a PR is missing labels or is marked with labels for not merging.
Instance Method Details
#check(do_not_merge_labels: [], required_labels: [], required_labels_error: nil, recommended_labels: [], recommended_labels_warning: nil) ⇒ void
Note:
Tip: if you want to require or recommend "at least one label", you can use
an array of a single empty regex [//] to match "a label with any name".
This method returns an undefined value.
Checks if a PR is missing labels or is marked with labels for not merging. If recommended labels are missing, the plugin will emit a warning. If a required label is missing, or the PR has a label indicating that the PR should not be merged, an error will be emitted, preventing the final merge.
with a warning if it doesn't (e.g. [/^feature:/,/^type:/]orbug|bugfix-exemption`).
Defaults to an empty array if not provided.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dangermattic/plugins/labels_checker.rb', line 38 def check(do_not_merge_labels: [], required_labels: [], required_labels_error: nil, recommended_labels: [], recommended_labels_warning: nil) github_labels = danger.github.pr_labels # A PR shouldn't be merged with the 'DO NOT MERGE' label found_do_not_merge_labels = github_labels.select do |github_label| do_not_merge_labels&.any? { |label| github_label.casecmp?(label) } end failure("This PR is tagged with #{markdown_list_string(found_do_not_merge_labels)} label(s).") unless found_do_not_merge_labels.empty? # fail if a PR is missing any of the required labels check_missing_labels(labels: github_labels, expected_labels: required_labels, report_on_missing: :error, custom_message: required_labels_error) # warn if a PR is missing any of the recommended labels check_missing_labels(labels: github_labels, expected_labels: recommended_labels, report_on_missing: :warning, custom_message: recommended_labels_warning) end |