diff --git a/Gemfile b/Gemfile index c2d5a61..7973a1f 100644 --- a/Gemfile +++ b/Gemfile @@ -11,30 +11,19 @@ source 'https://rubygems.org' gem 'activerecord', require: 'active_record' - -gem 'base64', '0.1.1' - +gem 'certified' gem 'dotenv' - -gem 'nio4r', '2.5.8' - -gem 'otr-activerecord', '2.0.3' - -gem 'pagy' +gem 'otr-activerecord' gem 'pagy_cursor' -gem 'parser', '3.0.2.0' -gem 'pg', '1.2.3' -gem 'puma', '5.5.2' - -gem 'racc', '1.5.1' -gem 'rack', '2.2.3.1' +gem 'pg' +gem 'puma' +gem 'rack' +gem 'rackup' gem 'rubocop', '0.89.1', group: %i[development test], require: false gem 'rubocop-ast', '0.6.0', group: %i[development test], require: false gem 'rubocop-performance', '1.7.1', group: %i[development test], require: false - -gem 'sinatra', '2.0.8.1' -gem 'slack-ruby-bot-server', '2.1.1' -gem 'slack-ruby-bot-server-events', '0.3.2' +gem 'sinatra' +gem 'slack-ruby-bot-server' +gem 'slack-ruby-bot-server-events' gem 'slack-ruby-client' - gem 'unicode-display_width', '1.6.1' diff --git a/Gemfile.lock b/Gemfile.lock index a1531bb..372ddb3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,119 +1,136 @@ GEM remote: https://rubygems.org/ specs: - activemodel (7.0.8) - activesupport (= 7.0.8) - activerecord (7.0.8) - activemodel (= 7.0.8) - activesupport (= 7.0.8) - activesupport (7.0.8) + activemodel (7.0.8.4) + activesupport (= 7.0.8.4) + activerecord (7.0.8.4) + activemodel (= 7.0.8.4) + activesupport (= 7.0.8.4) + activesupport (7.0.8.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) ast (2.4.2) - async (1.31.0) - console (~> 1.10) - nio4r (~> 2.3) - timers (~> 4.1) - base64 (0.1.1) - builder (3.2.4) - concurrent-ruby (1.2.2) - console (1.23.2) + async (2.17.0) + console (~> 1.26) fiber-annotation - fiber-local + io-event (~> 1.6, >= 1.6.5) + base64 (0.2.0) + bigdecimal (3.1.8) + certified (1.0.0) + concurrent-ruby (1.3.4) + console (1.27.0) + fiber-annotation + fiber-local (~> 1.1) + json declarative (0.0.20) - dotenv (2.8.1) + dotenv (3.1.4) dry-core (1.0.1) concurrent-ruby (~> 1.0) zeitwerk (~> 2.6) - dry-inflector (1.0.0) + dry-inflector (1.1.0) dry-logic (1.5.0) concurrent-ruby (~> 1.0) dry-core (~> 1.0, < 2) zeitwerk (~> 2.6) - dry-types (1.7.1) + dry-types (1.7.2) + bigdecimal (~> 3.0) concurrent-ruby (~> 1.0) dry-core (~> 1.0) dry-inflector (~> 1.0) dry-logic (~> 1.4) zeitwerk (~> 2.6) - faraday (2.7.11) - base64 - faraday-net_http (>= 2.0, < 3.1) - ruby2_keywords (>= 0.0.4) + faraday (2.12.0) + faraday-net_http (>= 2.0, < 3.4) + json + logger faraday-mashify (0.1.1) faraday (~> 2.0) hashie faraday-multipart (1.0.4) multipart-post (~> 2) - faraday-net_http (3.0.2) + faraday-net_http (3.3.0) + net-http fiber-annotation (0.2.0) - fiber-local (1.0.0) - foreman (0.87.2) - gli (2.21.1) - grape (1.8.0) - activesupport (>= 5) - builder + fiber-local (1.1.0) + fiber-storage + fiber-storage (1.0.0) + foreman (0.88.1) + gli (2.21.5) + grape (2.2.0) + activesupport (>= 6) dry-types (>= 1.1) - mustermann-grape (~> 1.0.0) - rack (>= 1.3.0) - rack-accept + mustermann-grape (~> 1.1.0) + rack (>= 2) + zeitwerk grape-roar (0.4.1) grape multi_json roar (~> 1.1.0) - grape-swagger (1.6.1) - grape (~> 1.3) + grape-swagger (2.1.1) + grape (>= 1.7, < 3.0) + rack-test (~> 2) hashie (5.0.0) hashie-forbidden_attributes (0.1.1) hashie (>= 3.0) - i18n (1.14.1) + i18n (1.14.6) concurrent-ruby (~> 1.0) + io-event (1.7.1) + json (2.7.2) kaminari-core (1.2.2) kaminari-grape (1.0.1) grape kaminari-core (~> 1.0) - minitest (5.20.0) + logger (1.6.1) + minitest (5.25.1) multi_json (1.15.0) - multipart-post (2.3.0) - mustermann (1.1.2) + multipart-post (2.4.1) + mustermann (3.0.3) ruby2_keywords (~> 0.0.1) - mustermann-grape (1.0.2) + mustermann-grape (1.1.0) mustermann (>= 1.0.0) + net-http (0.4.1) + uri nio4r (2.5.8) - otr-activerecord (2.0.3) - activerecord (>= 4.0, < 7.1) + otr-activerecord (2.4.0) + activerecord (>= 6.0, < 7.3) hashie-forbidden_attributes (~> 0.1) - pagy (6.2.0) - pagy_cursor (0.6.1) + pagy (8.6.3) + pagy_cursor (0.8.0) activerecord (>= 5) - pagy (>= 6, < 7) - parallel (1.23.0) - parser (3.0.2.0) + pagy (>= 6, < 9) + parallel (1.26.3) + parser (3.3.5.0) ast (~> 2.4.1) racc - pg (1.2.3) + pg (1.5.8) puma (5.5.2) nio4r (~> 2.0) - racc (1.5.1) - rack (2.2.3.1) - rack-accept (0.4.5) - rack (>= 0.4) - rack-cors (2.0.1) + racc (1.7.3) + rack (3.1.7) + rack-cors (2.0.2) rack (>= 2.0.0) - rack-protection (2.0.8.1) - rack + rack-protection (4.0.0) + base64 (>= 0.1.0) + rack (>= 3.0.0, < 4) rack-rewrite (1.5.1) rack-server-pages (0.1.0) rack + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) rainbow (3.1.1) - regexp_parser (2.8.2) + regexp_parser (2.9.2) representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) - rexml (3.2.6) + rexml (3.3.8) roar (1.1.1) representable (~> 3.0) rubocop (0.89.1) @@ -131,10 +148,11 @@ GEM rubocop (>= 0.82.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) - sinatra (2.0.8.1) - mustermann (~> 1.0) - rack (~> 2.0) - rack-protection (= 2.0.8.1) + sinatra (4.0.0) + mustermann (~> 3.0) + rack (>= 3.0.0, < 4) + rack-protection (= 4.0.0) + rack-session (>= 2.0.0, < 3) tilt (~> 2.0) slack-ruby-bot-server (2.1.1) async @@ -149,40 +167,44 @@ GEM slack-ruby-client slack-ruby-bot-server-events (0.3.2) slack-ruby-bot-server (>= 0.12.0) - slack-ruby-client (2.2.0) + slack-ruby-client (2.4.0) faraday (>= 2.0) faraday-mashify faraday-multipart gli hashie - tilt (2.3.0) - timers (4.3.5) + tilt (2.4.0) trailblazer-option (0.1.2) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) unicode-display_width (1.6.1) - zeitwerk (2.6.12) + uri (0.13.1) + webrick (1.8.2) + zeitwerk (2.7.0) PLATFORMS + ruby x86_64-linux DEPENDENCIES activerecord + certified dotenv - nio4r (= 2.5.8) - otr-activerecord (= 2.0.3) - pagy + otr-activerecord pagy_cursor - pg (= 1.2.3) - puma (= 5.5.2) - rack (= 2.2.3.1) + pg + puma + rack + rackup rubocop (= 0.89.1) + rubocop-ast (= 0.6.0) rubocop-performance (= 1.7.1) - sinatra (= 2.0.8.1) - slack-ruby-bot-server (= 2.1.1) - slack-ruby-bot-server-events (= 0.3.2) + sinatra + slack-ruby-bot-server + slack-ruby-bot-server-events slack-ruby-client + unicode-display_width (= 1.6.1) BUNDLED WITH - 2.2.22 + 2.5.9 diff --git a/config.ru b/config.ru index f4a6bc9..9dc7288 100644 --- a/config.ru +++ b/config.ru @@ -12,4 +12,6 @@ require 'puma' require './lib/slack_bot_app' require_relative 'config/initializers/active_record_established' +use Rack::RewindableInput::Middleware + run Rack::URLMap.new('/' => SlackRubyBotServer::Api::Middleware.instance, '/github' => Server) diff --git a/lib/github_app/server.rb b/lib/github_app/server.rb index 9b03433..ecb6102 100644 --- a/lib/github_app/server.rb +++ b/lib/github_app/server.rb @@ -19,6 +19,14 @@ class Server < Sinatra::Base halt 200 end + get '/translate/:name' do + user_info = Client.new.find_user_id_by_name(params[:name]) + + halt 404, 'User not found' unless user_info + + halt 200, user_info + end + post '/comment' do halt 401, 'Invalid user / password' unless authentication Client.new.chat(request.body.read) diff --git a/lib/slack/client.rb b/lib/slack/client.rb index da40082..6979382 100644 --- a/lib/slack/client.rb +++ b/lib/slack/client.rb @@ -23,6 +23,14 @@ def initialize @client = Slack::Web::Client.new end + def find_user_id_by_name(username) + user = @client.users_list.members.find { |u| u.name == username || u.display_name == username } + + puts user.inspect + + user ? user.id : nil + end + def chat(message, channel: fetch_channel) @client.chat_postMessage(channel: channel, text: message, diff --git a/lib/slack/slash_commands/bamboo_ci/command.rb b/lib/slack/slash_commands/bamboo_ci/command.rb index e6b4c96..169b1e0 100644 --- a/lib/slack/slash_commands/bamboo_ci/command.rb +++ b/lib/slack/slash_commands/bamboo_ci/command.rb @@ -14,7 +14,7 @@ module Slack module BambooCi class Command COMMANDS = %w[notify subscribe settings].freeze - NOTIFY_OPTS = %w[all errors pass off].freeze + NOTIFY_OPTS = %w[all errors pass stages off].freeze include SlackBot::Request include Singleton diff --git a/lib/slack/slash_commands/bamboo_ci/help.rb b/lib/slack/slash_commands/bamboo_ci/help.rb index 8b1230a..141d852 100644 --- a/lib/slack/slash_commands/bamboo_ci/help.rb +++ b/lib/slack/slash_commands/bamboo_ci/help.rb @@ -12,11 +12,12 @@ module Slack module BambooCi class Help TEXT = ' -/ci notify [all | errors | pass | off] +/ci notify [all | errors | pass | stages | off] is the PR number (or * for the off option) all: All finished runs errors: Just failed runs pass: Just successful runs + stages: Just stages updates off: Disable notifications Notify on all CI runs (all) or just the CI runs with errors (errors) or only for successful CI runs (pass) @@ -26,11 +27,12 @@ class Help /ci notify 6 pass Returns a slack notification whenever the PR6 finishes running and passes all CI tests -/ci subscribe [all | errors | pass | off] +/ci subscribe [all | errors | pass | stages | off] github_name is the Github Username all: All finished runs errors: Just failed runs pass: Just successful runs + stages: Just stages updates off: Disable notifications Similar to notify, but for all CI runs for that specific Github User diff --git a/service/devel/server_devel.sh b/service/devel/server_devel.sh index a48a0ff..8a0606d 100755 --- a/service/devel/server_devel.sh +++ b/service/devel/server_devel.sh @@ -12,10 +12,9 @@ # frozen_string_literal: true # -# -# SPDX-License-Identifier: BSD-2-Clause -# -# Startup script for CI Slack Bot +source "$HOME/.rvm/scripts/rvm" +rvm use 3.3.1 +bundle install echo ">> Running server" rackup -o 0.0.0.0 -p 4681 config.ru diff --git a/service/prod/server.sh b/service/prod/server.sh index 05420b2..ea1e86c 100755 --- a/service/prod/server.sh +++ b/service/prod/server.sh @@ -12,10 +12,9 @@ # frozen_string_literal: true # -# -# SPDX-License-Identifier: BSD-2-Clause -# -# Startup script for CI Slack Bot +source "$HOME/.rvm/scripts/rvm" +rvm use 3.3.1 +bundle install echo ">> Running server" rackup -o 0.0.0.0 -p 4680 config.ru