diff --git a/CHANGELOG.md b/CHANGELOG.md index fcd3b6e..f3da983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Changelog +## 0.18.0 +### Improvements +- Added command to display known problems for channel [#169](/../../issues/169) +- Added command to display solution for substring of known problem [#169](/../../issues/169) + ## 0.17.1 ### Bugfixes - DB migration fixes diff --git a/bot/commands/action_show_action.rb b/bot/commands/action_show_action.rb new file mode 100644 index 0000000..9da082b --- /dev/null +++ b/bot/commands/action_show_action.rb @@ -0,0 +1,48 @@ +module WhoIsOnDutyTodaySlackBotModule + module Commands + class ActionShowAction + DESCRIPTION = 'Will display action for mentioned problem'.freeze + EXAMPLE = 'Usage: `action show action for problem:MyProblem`'.freeze + def self.call(client:, data:, match:) + problem_text = match['expression'][/problem:(.*)$/, 1] + problems = Action.where('channel = ? AND problem LIKE ?', data.channel, "%#{problem_text}%") + + if problems.any? + attachments = problems.map do |problem| + { + fallback: "Problem: #{problem.problem}", + color: '#36a64f', + fields: [ + { + title: 'Problem', + value: problem.problem, + short: false + }, + { + title: 'Action', + value: problem.action, + short: false + } + ] + } + end + + client.web_client.chat_postMessage( + channel: data.channel, + text: 'Here are the problems and their actions:', + attachments: attachments, + thread_ts: data.thread_ts || data.ts, + as_user: true + ) + else + client.web_client.chat_postMessage( + channel: data.channel, + text: 'No problems with actions found for this channel.', + thread_ts: data.thread_ts || data.ts, + as_user: true + ) + end + end + end + end +end diff --git a/bot/commands/action_show_problems.rb b/bot/commands/action_show_problems.rb new file mode 100644 index 0000000..b4d6017 --- /dev/null +++ b/bot/commands/action_show_problems.rb @@ -0,0 +1,47 @@ +module WhoIsOnDutyTodaySlackBotModule + module Commands + class ActionShowProblems + DESCRIPTION = 'Will display problems for this channel'.freeze + EXAMPLE = 'Usage: `action show problems`'.freeze + def self.call(client:, data:) + problems = Action.where(channel: data.channel).where.not(action: nil) + + if problems.any? + attachments = problems.map do |problem| + { + fallback: "Problem: #{problem.problem}", + color: '#36a64f', + fields: [ + { + title: 'Problem', + value: problem.problem, + short: false + }, + { + title: 'Solution', + value: problem.action, + short: false + } + ] + } + end + + client.web_client.chat_postMessage( + channel: data.channel, + text: 'Here are the problems and their solutions:', + attachments: attachments, + thread_ts: data.thread_ts || data.ts, + as_user: true + ) + else + client.web_client.chat_postMessage( + channel: data.channel, + text: 'No problems with solutions found for this channel.', + thread_ts: data.thread_ts || data.ts, + as_user: true + ) + end + end + end + end +end diff --git a/bot/commands/help.rb b/bot/commands/help.rb index 0acf5e3..afea85b 100644 --- a/bot/commands/help.rb +++ b/bot/commands/help.rb @@ -46,6 +46,8 @@ def self.generate_help_text AnswerEnableHideReason, ActionCreate, ActionDelete, + ActionShowProblems, + ActionShowAction, ThreadLabelsClean, ThreadLabels, UserCommits, @@ -57,8 +59,7 @@ def self.generate_help_text color: '#36a64f', fields: [ { - title: command::EXAMPLE, - value: command::DESCRIPTION, + value: "#{command::EXAMPLE}\n#{command::DESCRIPTION}", short: false } ] diff --git a/bot/commands/main.rb b/bot/commands/main.rb index 2f9b993..bf2ef1e 100644 --- a/bot/commands/main.rb +++ b/bot/commands/main.rb @@ -1,5 +1,7 @@ require_relative 'action_create' require_relative 'action_delete' +require_relative 'action_show_problems' +require_relative 'action_show_action' require_relative 'answer_delete_custom_text' require_relative 'answer_disable_hide_reason' require_relative 'answer_enable_hide_reason' diff --git a/bot/whoisondutytodayslackbot.rb b/bot/whoisondutytodayslackbot.rb index fba6093..512da73 100644 --- a/bot/whoisondutytodayslackbot.rb +++ b/bot/whoisondutytodayslackbot.rb @@ -108,6 +108,14 @@ class WhoIsOnDutyTodaySlackBot < SlackRubyBot::Bot WhoIsOnDutyTodaySlackBotModule::Commands::ActionDelete.call(client: client, data: data, match: match) end + command 'action show problems' do |client, data| + WhoIsOnDutyTodaySlackBotModule::Commands::ActionShowProblems.call(client: client, data: data) + end + + command 'action show action for' do |client, data, match| + WhoIsOnDutyTodaySlackBotModule::Commands::ActionShowAction.call(client: client, data: data, match: match) + end + command 'thread labels clean' do |client, data, match| WhoIsOnDutyTodaySlackBotModule::Commands::ThreadLabelsClean.call(client: client, data: data, match: match) end diff --git a/db/schema.rb b/db/schema.rb index fdd94a8..ec39706 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,113 +11,113 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema[7.0].define(version: 2024_12_15_201550) do - create_table "actions", force: :cascade do |t| - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - t.string "problem" - t.string "action" - t.string "channel" + create_table 'actions', force: :cascade do |t| + t.datetime 'created_at', precision: nil, null: false + t.datetime 'updated_at', precision: nil, null: false + t.string 'problem' + t.string 'action' + t.string 'channel' end - create_table "answers", force: :cascade do |t| - t.text "body" - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - t.string "channel_id" - t.boolean "hide_reason" - t.string "answer_type" + create_table 'answers', force: :cascade do |t| + t.text 'body' + t.datetime 'created_at', precision: nil, null: false + t.datetime 'updated_at', precision: nil, null: false + t.string 'channel_id' + t.boolean 'hide_reason' + t.string 'answer_type' end - create_table "bitbucket_commits", force: :cascade do |t| - t.string "commit_id" - t.string "author" - t.text "message" - t.datetime "date", precision: nil - t.string "project_key" - t.string "repo_slug" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["project_key", "repo_slug", "commit_id"], name: "index_bitbucket_commits_on_project_repo_commit", unique: true + create_table 'bitbucket_commits', force: :cascade do |t| + t.string 'commit_id' + t.string 'author' + t.text 'message' + t.datetime 'date', precision: nil + t.string 'project_key' + t.string 'repo_slug' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['project_key', 'repo_slug', 'commit_id'], name: 'index_bitbucket_commits_on_project_repo_commit', unique: true end - create_table "channels", id: false, force: :cascade do |t| - t.string "slack_channel_id" - t.string "name" - t.text "description" - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - t.json "settings" - t.index ["slack_channel_id"], name: "index_channels_on_slack_channel_id", unique: true + create_table 'channels', id: false, force: :cascade do |t| + t.string 'slack_channel_id' + t.string 'name' + t.text 'description' + t.datetime 'created_at', precision: nil, null: false + t.datetime 'updated_at', precision: nil, null: false + t.json 'settings' + t.index ['slack_channel_id'], name: 'index_channels_on_slack_channel_id', unique: true end - create_table "duties", force: :cascade do |t| - t.datetime "duty_from", precision: nil, null: false - t.datetime "duty_to", precision: nil, null: false - t.string "duty_days", default: "1,2,3,4,5" - t.string "channel_id", null: false - t.string "user_id", null: false - t.boolean "enabled" - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - t.string "opsgenie_schedule_name" - t.string "opsgenie_escalation_name" + create_table 'duties', force: :cascade do |t| + t.datetime 'duty_from', precision: nil, null: false + t.datetime 'duty_to', precision: nil, null: false + t.string 'duty_days', default: '1,2,3,4,5' + t.string 'channel_id', null: false + t.string 'user_id', null: false + t.boolean 'enabled' + t.datetime 'created_at', precision: nil, null: false + t.datetime 'updated_at', precision: nil, null: false + t.string 'opsgenie_schedule_name' + t.string 'opsgenie_escalation_name' end - create_table "labels", force: :cascade do |t| - t.string "label", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'labels', force: :cascade do |t| + t.string 'label', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - create_table "messages", force: :cascade do |t| - t.string "message_id", null: false - t.string "ts" - t.string "thread_ts" - t.string "event_ts" - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - t.integer "reply_counter" - t.integer "#" - t.boolean "remind_needed" - t.string "channel_id" + create_table 'messages', force: :cascade do |t| + t.string 'message_id', null: false + t.string 'ts' + t.string 'thread_ts' + t.string 'event_ts' + t.datetime 'created_at', precision: nil, null: false + t.datetime 'updated_at', precision: nil, null: false + t.integer 'reply_counter' + t.integer '#' + t.boolean 'remind_needed' + t.string 'channel_id' end - create_table "slack_thread_labels", force: :cascade do |t| - t.integer "slack_thread_id", null: false - t.integer "label_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["label_id"], name: "index_slack_thread_labels_on_label_id" - t.index ["slack_thread_id"], name: "index_slack_thread_labels_on_slack_thread_id" + create_table 'slack_thread_labels', force: :cascade do |t| + t.integer 'slack_thread_id', null: false + t.integer 'label_id', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['label_id'], name: 'index_slack_thread_labels_on_label_id' + t.index ['slack_thread_id'], name: 'index_slack_thread_labels_on_slack_thread_id' end - create_table "slack_threads", force: :cascade do |t| - t.string "thread_ts" - t.string "channel_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'slack_threads', force: :cascade do |t| + t.string 'thread_ts' + t.string 'channel_id' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - create_table "teams", force: :cascade do |t| - t.string "name" - t.text "description" - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false + create_table 'teams', force: :cascade do |t| + t.string 'name' + t.text 'description' + t.datetime 'created_at', precision: nil, null: false + t.datetime 'updated_at', precision: nil, null: false end - create_table "users", id: false, force: :cascade do |t| - t.string "slack_user_id" - t.string "name" - t.string "real_name" - t.string "contacts" - t.string "tz" - t.integer "tz_offset" - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - t.string "status" - t.index ["slack_user_id"], name: "index_users_on_slack_user_id", unique: true + create_table 'users', id: false, force: :cascade do |t| + t.string 'slack_user_id' + t.string 'name' + t.string 'real_name' + t.string 'contacts' + t.string 'tz' + t.integer 'tz_offset' + t.datetime 'created_at', precision: nil, null: false + t.datetime 'updated_at', precision: nil, null: false + t.string 'status' + t.index ['slack_user_id'], name: 'index_users_on_slack_user_id', unique: true end - add_foreign_key "slack_thread_labels", "labels" - add_foreign_key "slack_thread_labels", "slack_threads" + add_foreign_key 'slack_thread_labels', 'labels' + add_foreign_key 'slack_thread_labels', 'slack_threads' end