Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-exz committed Dec 22, 2024
1 parent b9450bf commit 2a066c3
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 89 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
48 changes: 48 additions & 0 deletions bot/commands/action_show_action.rb
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions bot/commands/action_show_problems.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions bot/commands/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def self.generate_help_text
AnswerEnableHideReason,
ActionCreate,
ActionDelete,
ActionShowProblems,
ActionShowAction,
ThreadLabelsClean,
ThreadLabels,
UserCommits,
Expand All @@ -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
}
]
Expand Down
2 changes: 2 additions & 0 deletions bot/commands/main.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
8 changes: 8 additions & 0 deletions bot/whoisondutytodayslackbot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
174 changes: 87 additions & 87 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 "#<ActiveRecord::ConnectionAdapters::SQLite3::TableDefinition:0x00000001247100a0>"
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 '#<ActiveRecord::ConnectionAdapters::SQLite3::TableDefinition:0x00000001247100a0>'
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

0 comments on commit 2a066c3

Please sign in to comment.