ci_slack 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7dbe8d3568f5028370b10d1325f89ca53e5c202c
4
+ data.tar.gz: 17fd30f8ec151788d7fa1056ef88fa5d3c6365d5
5
+ SHA512:
6
+ metadata.gz: 9d0430962ced5535065d5be9ccd85b48559b3178f3e1a3bd0ede1aae88176dde2b16368bfbbba566c446cfe93ad9d4b9109af4b4ff6feb8c7d2a75c41f47f692
7
+ data.tar.gz: 6f544cd2453e9553ed3d0c2bf89305528437792f5657dec16aed30b6f58eb773b2c0ea5e6e670fd243b6fdd1fcab75c9367a22f33a656cabae0de69cd87988b4
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 skrinits
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'CiSlack'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ Bundler::GemHelper.install_tasks
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'lib'
23
+ t.libs << 'test'
24
+ t.pattern = 'test/**/*_test.rb'
25
+ t.verbose = false
26
+ end
27
+
28
+
29
+ task default: :test
@@ -0,0 +1,14 @@
1
+ class CiSlack::Configuration
2
+ attr_accessor :icon, :webhook, :channel, :ci_computer,
3
+ :bot_name, :project, :slack_names
4
+
5
+ def initialize
6
+ @icon = 'failed'
7
+ @webhook = ''
8
+ @channel = '#ci'
9
+ @bot_name = 'CI BOT'
10
+ @project = ''
11
+ @slack_names = {}
12
+ @ci_computer = 'CI'
13
+ end
14
+ end
@@ -0,0 +1,36 @@
1
+ require 'slack-notifier'
2
+ require 'ci_slack'
3
+
4
+ class CiSlack::Messager
5
+ attr_reader :client, :project
6
+
7
+ def initialize
8
+ @client = ::Slack::Notifier.new(webhook, channel: channel, username: bot_name)
9
+ end
10
+
11
+ def send(message)
12
+ return unless ENV[ci_computer.to_s]
13
+
14
+ author, commit_message = last_git_log
15
+ slack_name = slack_names.select { |key, _| author.downcase =~ key }.values.first || author
16
+
17
+ text = "#{ project }. CI FAILED!\n<@#{ slack_name }> : #{ commit_message } \n#{ message }"
18
+
19
+ client.post(text: text, icon_emoji: ":#{ icon }:")
20
+ end
21
+
22
+ def method_missing(method, *args)
23
+ if %i[icon webhook channel ci_computer
24
+ bot_name project slack_names].include?(method)
25
+ CiSlack.configuration.send(method)
26
+ else
27
+ super
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def last_git_log
34
+ `git log -1 --pretty='%an||%s'`.split('||').map(&:strip)
35
+ end
36
+ end
@@ -0,0 +1,50 @@
1
+ require_relative 'patch'
2
+ require_relative '../messager'
3
+
4
+ module CiSlack
5
+ module Rspec
6
+ class Notifier
7
+ attr_reader :messager
8
+
9
+ def initialize
10
+ @messager = CiSlack::Messager.new
11
+ end
12
+
13
+ def example_failed(notification)
14
+ messager.send(Example.new(notification.example).to_s)
15
+ end
16
+
17
+ class Example
18
+ def initialize(example)
19
+ @example = example
20
+ end
21
+
22
+ def to_s
23
+ %(\n*Failed test:*
24
+ > Scenario: _#{ description }_
25
+ > File: #{ error_location }
26
+ > Error: ```#{ error }```\n)
27
+ end
28
+
29
+ private
30
+
31
+ def description
32
+ @example.metadata[:full_description]
33
+ end
34
+
35
+ def error
36
+ @example.execution_result.exception.to_s
37
+ end
38
+
39
+ def error_location
40
+ @example.metadata[:location]
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ RSpec.configure do |config|
48
+ config.fail_fast = true
49
+ config.reporter.register_listener CiSlack::Rspec::Notifier.new, :example_failed
50
+ end
@@ -0,0 +1,22 @@
1
+ # added a check on present @profiler
2
+ module RSpec::Core
3
+ class Reporter
4
+ def finish
5
+ close_after do
6
+ stop
7
+ notify :start_dump, Notifications::NullNotification
8
+ notify :dump_pending, Notifications::ExamplesNotification.new(self)
9
+ notify :dump_failures, Notifications::ExamplesNotification.new(self)
10
+ notify :deprecation_summary, Notifications::NullNotification
11
+ unless mute_profile_output?
12
+ notify :dump_profile, Notifications::ProfileNotification.new(@duration, @examples,
13
+ @configuration.profile_examples,
14
+ @profiler&.example_groups)
15
+ end
16
+ notify :dump_summary, Notifications::SummaryNotification.new(@duration, @examples, @failed_examples,
17
+ @pending_examples, @load_time)
18
+ notify :seed, Notifications::SeedNotification.new(@configuration.seed, seed_used?)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module CiSlack
2
+ VERSION = '0.0.1'
3
+ end
data/lib/ci_slack.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'ci_slack/configuration'
2
+
3
+ module CiSlack
4
+ class << self
5
+ def configuration
6
+ @configuration ||= CiSlack::Configuration.new
7
+ end
8
+
9
+ def configure
10
+ yield(configuration)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ class CiSlackTest < ActiveSupport::TestCase
4
+ test 'configure' do
5
+ CiSlack.configure do |config|
6
+ %i[icon webhook channel ci_computer bot_name project slack_names].each do |param|
7
+ config.send("#{ param }=", param)
8
+ end
9
+ end
10
+
11
+ %i[icon webhook channel ci_computer bot_name project slack_names].each do |param|
12
+ assert_equal(CiSlack.configuration.send(param), param)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigurationTest < ActiveSupport::TestCase
4
+ test 'default params' do
5
+ config = CiSlack::Configuration.new
6
+
7
+ assert_equal('failed', config.icon)
8
+ assert_equal('', config.webhook)
9
+ assert_equal('#ci', config.channel)
10
+ assert_equal('CI', config.ci_computer)
11
+ assert_equal('CI BOT', config.bot_name)
12
+ assert_equal('', config.project)
13
+ assert_equal({}, config.slack_names)
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+ require_relative '../lib/ci_slack/messager'
3
+
4
+ class MessagerTest < ActiveSupport::TestCase
5
+ setup do
6
+ CiSlack.configure do |config|
7
+ %i[icon webhook channel ci_computer bot_name project slack_names].each do |param|
8
+ if param == :webhook
9
+ config.send("#{ param }=", 'http://github.com')
10
+ elsif param == :slack_names
11
+ config.send("#{ param }=", {})
12
+ else
13
+ config.send("#{ param }=", param)
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ test "computer without ci: ENV['CI'] is absent" do
20
+ ENV['ci_computer'] = nil
21
+
22
+ messager = CiSlack::Messager.new
23
+
24
+ assert_nil(messager.send('message'))
25
+ end
26
+
27
+ test "computer with ci: ENV['CI'] is present" do
28
+ ENV['ci_computer'] = 'true'
29
+
30
+ messager = CiSlack::Messager.new
31
+
32
+ assert_raise Slack::Notifier::APIError do
33
+ messager.send('message')
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
5
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
6
+ require "rails/test_help"
7
+
8
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
9
+ # to be shown.
10
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
11
+
12
+ # Load support files
13
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
14
+
15
+ # Load fixtures from the engine
16
+ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
17
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
18
+ ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
19
+ ActiveSupport::TestCase.fixtures :all
20
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ci_slack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - skrinits
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slack-notifier
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.1
27
+ description: Send a message on failure of Continiues Integration to the specific channel
28
+ with a link to the author of a last commit
29
+ email:
30
+ - slavakrinicyn@mail.ru
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - MIT-LICENSE
36
+ - Rakefile
37
+ - lib/ci_slack.rb
38
+ - lib/ci_slack/configuration.rb
39
+ - lib/ci_slack/messager.rb
40
+ - lib/ci_slack/rspec/notifier.rb
41
+ - lib/ci_slack/rspec/patch.rb
42
+ - lib/ci_slack/version.rb
43
+ - test/ci_slack_test.rb
44
+ - test/configuration_test.rb
45
+ - test/messager_test.rb
46
+ - test/test_helper.rb
47
+ homepage: https://github.com/skrinits/ci_slack
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.6.14
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Slack report for Continiues Integration
71
+ test_files:
72
+ - test/messager_test.rb
73
+ - test/ci_slack_test.rb
74
+ - test/configuration_test.rb
75
+ - test/test_helper.rb