diff --git a/CHANGELOG.md b/CHANGELOG.md index 920e839..434243d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ # Changelog +## 0.10.1 +### Improvements +- Deleting no needed code +- Improved statistic output. +- Added `channel labels merge` + ## 0.10.0 ### Improvements - Added MIT license 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/app/models/message.rb b/app/models/message.rb index c247b15..5022173 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -1,4 +1,3 @@ class Message < ApplicationRecord - has_many :message_labels, dependent: :destroy - has_many :labels, through: :message_labels + end diff --git a/bot/commands/channel_labels_merge.rb b/bot/commands/channel_labels_merge.rb new file mode 100644 index 0000000..12696a4 --- /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:(.*) to:/, 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}) + records_count=m.update_all(label_id: label_to_id) + message = I18n.t("commands.channel.labels.merged.success.text",label_from:label_from,label_to:label_to,records_count:records_count) + else + message = I18n.t("commands.channel.labels.merged.error.text",label_from:label_from,label_to:label_to) + 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/channel_labels_statistic.rb b/bot/commands/channel_labels_statistic.rb index 3f62471..f647261 100644 --- a/bot/commands/channel_labels_statistic.rb +++ b/bot/commands/channel_labels_statistic.rb @@ -7,7 +7,7 @@ def self.call(client:, data:, match:) start_date = (Time.now - x.week).beginning_of_week end_date = (Time.now - x.week).end_of_week m = SlackThread.joins(:labels).where(channel_id: data.channel).where('thread_ts BETWEEN ? AND ?', start_date.to_time.to_i, end_date.to_time.to_i).group(:label) - message.concat(I18n.t("commands.thread.statistic",start_date:start_date.strftime("%d.%m.%Y %H:%M"),end_date:end_date.strftime("%d.%m.%Y %H:%M"),labels:m.count.to_s)) + message.concat(I18n.t("commands.thread.statistic",start_date:start_date.strftime("%d.%m.%Y %H:%M"),end_date:end_date.strftime("%d.%m.%Y %H:%M"),labels:JSON.pretty_generate(m.count).gsub(":", " =>"))) end client.web_client.chat_postMessage( 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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 92edba6..7e07046 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4,7 +4,7 @@ en: text: "Sorry i don't understand you. Use `<@%{name}> help`" help: text: | - Version: %{version} + running version: %{version} | | Commands in channel: -- `call duty person` - will send alert message to duty person. -- `i am on duty` - will set you as duty person in channel. @@ -27,10 +27,17 @@ en: -- `thread labels clean` - will remove all labels from thread where you write it. -- `channel labels list` - will display all labels in this channel. -- `channel labels statistic` - will show labels count in channel for last week. + -- `channel labels merge` - will migrate existing threads in channel from one label to another, example `channel labels merge from:label1 to:label2` Commands in direct messages: -- `my status *` - set any status when you cannot provide support in channel, bot will reply instead of you. -- `my status work` - bot will stop telling your status, use it when you came back. channel: + labels: + merged: + success: + text: "Labels merged %{label_from} -> %{label_to} records affected %{records_count}" + error: + text: "Merge %{label_from} -> %{label_to} failed, check label names" reminder: enabled: text: "Reminder in channel successfully enabled." @@ -83,7 +90,7 @@ en: error: "Something was wrong" statistic: | Period: %{start_date} - %{end_date} - labels: %{labels} + %{labels} labels: cleaned: "Labels removed from thread" action: diff --git a/config/locales/hr.yml b/config/locales/hr.yml index 2777845..79a068d 100644 --- a/config/locales/hr.yml +++ b/config/locales/hr.yml @@ -43,6 +43,13 @@ hr: action: failed: text: "" + channel: + labels: + merged: + error: + text: "" + success: + text: "" reply: non-working-time: subject: "Nešto se dogodilo" diff --git a/config/locales/ru.yml b/config/locales/ru.yml index c5d5877..d0a7847 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -43,6 +43,13 @@ ru: action: failed: text: "" + channel: + labels: + merged: + error: + text: "" + success: + text: "" reply: non-working-time: subject: "Что то случилось"