Skip to content

Commit

Permalink
added new action (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-exz authored Dec 2, 2024
1 parent 5955f0a commit d96268e
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 58 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## 0.12.0
### Features
- Added new action `git commits` - it will return last 10 user commits

## 0.11.0
### Features
- Added Bitbucket Datacenter commits report feature
Expand Down
29 changes: 29 additions & 0 deletions bot/commands/git_commits.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module WhoIsOnDutyTodaySlackBotModule
module Commands
class UserCommits
def self.call(client:, data:, match:)
message_processor = MessageProcessor.new
user_name = match["expression"][/<@(.+)>/, 1]
message_processor.collectUserInfoBySlackUserId(user_name)
user = User.where(slack_user_id: user_name).first
return unless user
commits = BitbucketCommit.where('LOWER(author) = ?', user.contacts.downcase).order(date: :desc).limit(10)
created_at = commits.first.created_at.strftime('%Y-%m-%d %H:%M:%S')
commit_messages = commits.map { |commit|
commit_url = generate_commit_url(commit)
"*#{commit.date.strftime('%Y-%m-%d')}*: <#{commit_url}|#{commit.message}>"
}.join("\n")

client.web_client.chat_postMessage(
channel: data.channel,
text: "Last 10 commits by #{user.name} synced at: #{created_at}:\n#{commit_messages}",
thread_ts: data.thread_ts || data.ts,
as_user: true
)
end
def self.generate_commit_url(commit)
"#{ENV['BITBUCKET_URL']}/projects/#{commit.project_key}/repos/#{commit.repo_slug}/commits/#{commit.commit_id}"
end
end
end
end
57 changes: 29 additions & 28 deletions bot/commands/main.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
require_relative "action_create"
require_relative "action_delete"
require_relative "allow_list"
require_relative "answer_delete_custom_text"
require_relative "answer_disable_hide_reason"
require_relative "answer_enable_hide_reason"
require_relative "answer_set_custom_text"
require_relative "call_duty_person"
require_relative "channel_reminder_disabled"
require_relative "channel_reminder_enabled"
require_relative "checked"
require_relative "create_duty_for_user"
require_relative "duty_create"
require_relative "duty_delete"
require_relative "duty_set_opsgenie_escalation"
require_relative "duty_sync_with_opsgenie_schedule"
require_relative "duty_update"
require_relative "help"
require_relative "i_am_on_duty"
require_relative "my_status"
require_relative "other"
require_relative "unknown"
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"
require_relative 'action_create'
require_relative 'action_delete'
require_relative 'allow_list'
require_relative 'answer_delete_custom_text'
require_relative 'answer_disable_hide_reason'
require_relative 'answer_enable_hide_reason'
require_relative 'answer_set_custom_text'
require_relative 'call_duty_person'
require_relative 'channel_reminder_disabled'
require_relative 'channel_reminder_enabled'
require_relative 'checked'
require_relative 'create_duty_for_user'
require_relative 'duty_create'
require_relative 'duty_delete'
require_relative 'duty_set_opsgenie_escalation'
require_relative 'duty_sync_with_opsgenie_schedule'
require_relative 'duty_update'
require_relative 'help'
require_relative 'i_am_on_duty'
require_relative 'my_status'
require_relative 'other'
require_relative 'unknown'
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'
require_relative 'git_commits'

module WhoIsOnDutyTodaySlackBotModule
module Commands
Expand Down
64 changes: 34 additions & 30 deletions bot/whoisondutytodayslackbot.rb
Original file line number Diff line number Diff line change
@@ -1,110 +1,114 @@
require "date"
require "json"
require_relative "commands/main"
require_relative "notify"
require_relative "message_processor"
require 'date'
require 'json'
require_relative 'commands/main'
require_relative 'notify'
require_relative 'message_processor'
class WhoIsOnDutyTodaySlackBot < SlackRubyBot::Bot
SlackRubyBot::Client.logger.level = Logger::WARN

command "help" do |client, data|
command 'help' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::Help.call(client: client, data: data)
end

command "call duty person" do |client, data|
command 'call duty person' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::CallDutyPerson.call(client: client, data: data)
end

command "my status" do |client, data, match|
command 'my status' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::MyStatus.call(client: client, data: data, match: match)
end

command "i am on duty" do |client, data|
command 'i am on duty' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::IAmOnDuty.call(client: client, data: data)
end

command "who is on duty?" do |client, data|
command 'who is on duty?' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::WhoIsOnDuty.call(client: client, data: data)
end

command "checked" do |client, data|
command 'checked' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::Checked.call(client: client, data: data)
end

command "duty create" do |client, data, match|
command 'duty create' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::DutyCreate.call(client: client, data: data, match: match)
end

command "create duty for user" do |client, data, match|
command 'create duty for user' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::CreateDutyForUser.call(client: client, data: data, match: match)
end

command "channel reminder enabled" do |client, data|
command 'channel reminder enabled' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelReminderEnabled.call(client: client, data: data)
end

command "channel reminder disabled" do |client, data|
command 'channel reminder disabled' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelReminderDisabled.call(client: client, data: data)
end

command "duty update" do |client, data, match|
command 'duty update' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::DutyUpdate.call(client: client, data: data, match: match)
end

command "duty delete" do |client, data|
command 'duty delete' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::DutyDelete.call(client: client, data: data)
end

command "duty sync with opsgenie schedule" do |client, data, match|
command 'duty sync with opsgenie schedule' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::DutySyncWithOpsgenieSchedule.call(client: client, data: data, match: match)
end

command "duty set opsgenie escalation" do |client, data, match|
command 'duty set opsgenie escalation' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::DutySetOpsgenieEscalation.call(client: client, data: data, match: match)
end

command "answer set custom text" do |client, data, match|
command 'answer set custom text' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::AnswerSetCustomText.call(client: client, data: data, match: match)
end

command "answer delete custom text" do |client, data|
command 'answer delete custom text' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::AnswerDeleteCustomText.call(client: client, data: data)
end

command "answer enable hide reason" do |client, data|
command 'answer enable hide reason' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::AnswerEnableHideReason.call(client: client, data: data)
end

command "answer disable hide reason" do |client, data|
command 'answer disable hide reason' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::AnswerEnableHideReason.call(client: client, data: data)
end

command "action create" do |client, data, match|
command 'action create' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::ActionCreate.call(client: client, data: data, match: match)
end

command "action delete" do |client, data, match|
command 'action delete' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::ActionDelete.call(client: client, data: data, match: match)
end

command "thread labels clean" do |client, data, match|
command 'thread labels clean' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::ThreadLabelsClean.call(client: client, data: data, match: match)
end

command "thread labels" do |client, data, match|
command 'thread labels' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::ThreadLabels.call(client: client, data: data, match: match)
end

command "channel labels statistic" do |client, data, match|
command 'channel labels statistic' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelLabelsStatistic.call(client: client, data: data, match: match)
end

command "channel labels list" do |client, data, match|
command 'channel labels list' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelLabelsList.call(client: client, data: data, match: match)
end

command "channel labels merge" do |client, data, match|
command 'channel labels merge' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelLabelsMerge.call(client: client, data: data, match: match)
end

command 'git commits' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::UserCommits.call(client: client, data: data, match: match)
end

command(/.*/) do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::Unknown.call(client: client, data: data)
Expand Down

0 comments on commit d96268e

Please sign in to comment.