Skip to content

Commit

Permalink
Prereleae 0.10.1 (#166)
Browse files Browse the repository at this point in the history
## 0.10.1
### Improvements
- Deleting no needed code
- Improved statistic output.
- Added `channel labels merge`
  • Loading branch information
mr-exz authored Nov 2, 2023
1 parent 58829eb commit d8abffa
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
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
3 changes: 1 addition & 2 deletions app/models/message.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class Message < ApplicationRecord
has_many :message_labels, dependent: :destroy
has_many :labels, through: :message_labels

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:(.*) 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
2 changes: 1 addition & 1 deletion bot/commands/channel_labels_statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
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
11 changes: 9 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ en:
text: "Sorry i don't understand you. Use `<@%{name}> help`"
help:
text: |
Version: %{version}
running version: %{version} | <https://github.com/mr-exz/whoisondutytoday|github> | <https://github.com/mr-exz/whoisondutytoday/blob/master/CHANGELOG.md|changelog>
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.
Expand All @@ -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."
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions config/locales/hr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ hr:
action:
failed:
text: ""
channel:
labels:
merged:
error:
text: ""
success:
text: ""
reply:
non-working-time:
subject: "Nešto se dogodilo"
Expand Down
7 changes: 7 additions & 0 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ ru:
action:
failed:
text: ""
channel:
labels:
merged:
error:
text: ""
success:
text: ""
reply:
non-working-time:
subject: "Что то случилось"
Expand Down

0 comments on commit d8abffa

Please sign in to comment.