Skip to content

Commit

Permalink
added merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-exz committed Nov 1, 2023
1 parent bd54444 commit bdc0861
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Changelog
## 0.10.1
### Improvements
- Deleting no needed code

- Added `channel labels merge`

## 0.10.0
### Improvements
Expand Down
1 change: 0 additions & 1 deletion app/models/label.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Label < ApplicationRecord
has_many :slack_thread_labels, dependent: :destroy
has_many :messages, through: :slack_thread_labels
validates_uniqueness_of :label
end
26 changes: 26 additions & 0 deletions bot/commands/channel_labels_merge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module WhoIsOnDutyTodaySlackBotModule
module Commands
class ChannelLabelsMerge
def self.call(client:, data:, match:)
label_from = match["expression"][/from:(.*) action:/, 1]
label_to = match["expression"][/ to:(.*)$/, 1]
label_to_id = Label.where(label: label_to).ids[0]

if (label_from != nil?) || (label_to_id != nil?)
m = SlackThreadLabel.joins(:label, :slack_thread).where(slack_thread: {channel_id: data.channel}, label: {label: label_from})
m.update_all(label_id: label_to_id)
message = "label_from label_to merged"
else
message = "Sorry, label_from or label_to not found, merge not possible."
end
client.web_client.chat_postMessage(
channel: data.channel,
text: message,
thread_ts: data.thread_ts || data.ts,
as_user: true
)

end
end
end
end
1 change: 1 addition & 0 deletions bot/commands/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
require_relative "who_is_on_duty"
require_relative "channel_labels_statistic"
require_relative "channel_labels_list"
require_relative "channel_labels_merge"
require_relative "thread_labels_clean"
require_relative "thread_labels"

Expand Down
4 changes: 4 additions & 0 deletions bot/whoisondutytodayslackbot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class WhoIsOnDutyTodaySlackBot < SlackRubyBot::Bot
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelLabelsList.call(client: client, data: data, match: match)
end

command "channel labels merge" do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelLabelsMerge.call(client: client, data: data, match: match)
end

command(/.*/) do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::Unknown.call(client: client, data: data)
end
Expand Down

0 comments on commit bdc0861

Please sign in to comment.