Skip to content

Commit

Permalink
Move unassignable and unremovable labels from constants to settings
Browse files Browse the repository at this point in the history
These values really belong to the manageiq organization and the bot is
intended to be reusable by people in other organizations.  Prefer settings
for these types of values rather than hard-coded constants.
  • Loading branch information
bdunne committed Mar 12, 2020
1 parent fdec13a commit c071dd0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ bugzilla:
product:
grafana:
url:
labels:
unassignable: {}
unremovable: []

# Worker settings
diff_content_checker:
Expand Down
6 changes: 6 additions & 0 deletions config/settings/test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
:labels:
:unassignable:
jansa/yes: jansa/yes?
:unremovable:
- jansa/no
- jansa/yes
# In test, turn everything on by default
# NOTE: Using empty string is a HACK until we can get
# https://github.com/danielsdeleo/deep_merge/pull/33 released via the
Expand Down
8 changes: 4 additions & 4 deletions lib/github_service/commands/add_label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module Commands
class AddLabel < Base
include IsTeamMember

UNASSIGNABLE = {
"jansa/yes" => "jansa/yes?"
}.freeze
def unassignable_labels
@unassignable_labels ||= Settings.labels.unassignable.to_h.stringify_keys
end

private

Expand Down Expand Up @@ -57,7 +57,7 @@ def correct_invalid_labels(valid_labels, invalid_labels)

def handle_unassignable_labels(valid_labels)
valid_labels.map! do |label|
UNASSIGNABLE.key?(label) ? UNASSIGNABLE[label] : label
unassignable_labels.key?(label) ? unassignable_labels[label] : label
end
end

Expand Down
6 changes: 4 additions & 2 deletions lib/github_service/commands/remove_label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module Commands
class RemoveLabel < Base
include IsTeamMember

UNREMOVABLE = %w[jansa/yes jansa/no].freeze
def unremovable_labels
@unremovable_labels ||= Settings.labels.unremovable
end

alias_as 'rm_label'

Expand Down Expand Up @@ -40,7 +42,7 @@ def extract_label_names(value)

def process_extracted_labels(issuer, valid_labels, _invalid_labels, unremovable)
unless triage_member?(issuer)
valid_labels.each { |label| unremovable << label if UNREMOVABLE.include?(label) }
valid_labels.each { |label| unremovable << label if unremovable_labels.include?(label) }
unremovable.each { |label| valid_labels.delete(label) }
end
end
Expand Down

0 comments on commit c071dd0

Please sign in to comment.