From bdc0861e724d42f52a2b8a0f1fefdee238bd65da Mon Sep 17 00:00:00 2001 From: "mr.exz" Date: Wed, 1 Nov 2023 17:59:16 +0300 Subject: [PATCH] added merge --- CHANGELOG.md | 3 +-- app/models/label.rb | 1 - bot/commands/channel_labels_merge.rb | 26 ++++++++++++++++++++++++++ bot/commands/main.rb | 1 + bot/whoisondutytodayslackbot.rb | 4 ++++ 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 bot/commands/channel_labels_merge.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f5fcb9..074f2cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,7 @@ # Changelog ## 0.10.1 ### Improvements -- Deleting no needed code - +- Added `channel labels merge` ## 0.10.0 ### Improvements diff --git a/app/models/label.rb b/app/models/label.rb index 4a73f90..fa2bcdf 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -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 diff --git a/bot/commands/channel_labels_merge.rb b/bot/commands/channel_labels_merge.rb new file mode 100644 index 0000000..f325420 --- /dev/null +++ b/bot/commands/channel_labels_merge.rb @@ -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 diff --git a/bot/commands/main.rb b/bot/commands/main.rb index 48c721e..5e30043 100644 --- a/bot/commands/main.rb +++ b/bot/commands/main.rb @@ -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" diff --git a/bot/whoisondutytodayslackbot.rb b/bot/whoisondutytodayslackbot.rb index d649cc8..02e461a 100644 --- a/bot/whoisondutytodayslackbot.rb +++ b/bot/whoisondutytodayslackbot.rb @@ -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