ci_slack 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e7fc82227bb4a7377109f371acd8b1dd65be275
4
- data.tar.gz: 31424e4553462864c599eafd1f0f181e4aed2c72
3
+ metadata.gz: f99d5ee84a508ed11a15c05c2fb8c30c77f32de2
4
+ data.tar.gz: 96ea17fa76a7225bb45e6805ac24bfc4565a4c2b
5
5
  SHA512:
6
- metadata.gz: 3cfa35a4ad6a9e5577b71b6ed8e4a4b1e9f42df7f5496275e3391e48e37a79771ff266db033054558d3ce94316ef3b1a2282824e9cc4b11fb7fcd360f9162332
7
- data.tar.gz: 82a5de91f080ddd442b18ba0b9e4163122014e7d561f06c6864e148742a71996b621d01a1448a06ea9843d9d32cef19d394135eb24de57c92fbfa8e91359c77c
6
+ metadata.gz: b44f58c5152d8c7abaaf4c29a775c59275b134afa72121fd24f864140faf7051ffacdb5b7c318b1d7a802dea8218a2d2062f10fe0d37c26b9e40f947a997389e
7
+ data.tar.gz: bfa80b9d2aced0ea115596e59f6682aa3264ff6563ba85e3beed9da260dd2918debb607c6085f341101370d9013deeca9044a953bf50b58bc68a0ccd90ad2b45
@@ -3,7 +3,8 @@ module CiSlack
3
3
  attr_accessor :webhook, :channel, :ci_computer,
4
4
  :bot_name, :project, :slack_names,
5
5
  :failed_icon, :success_icon,
6
- :failed_title, :success_title
6
+ :failed_title, :success_title,
7
+ :skip_success_message
7
8
 
8
9
  def initialize
9
10
  @webhook = ''
@@ -17,6 +18,8 @@ module CiSlack
17
18
  @success_icon = 'successful'
18
19
  @failed_title = 'CI FAILED!'
19
20
  @success_title = 'SUCCESS'
21
+
22
+ @skip_success_message = []
20
23
  end
21
24
  end
22
25
  end
@@ -8,18 +8,15 @@ module CiSlack
8
8
  return unless ENV[ci_computer.to_s]
9
9
 
10
10
  author, commit_message = last_git_log
11
- slack_name = slack_names.select { |key, _| author.downcase =~ key }.values.first || author
12
11
 
13
- text = "#{ project }. #{ send(status.to_s + '_title') }\n<@#{ slack_name }> : #{ commit_message }\n#{ message }"
14
-
15
- client.post(text: text, icon_emoji: ":#{ send(status.to_s + '_icon') }:")
12
+ client.post(text: text(status, author, commit_message, message),
13
+ icon_emoji: ":#{ send(status.to_s + '_icon') }:")
16
14
  end
17
15
 
18
16
  def method_missing(method, *args)
19
- if %i[success_icon failed_icon
20
- failed_title success_title
21
- webhook channel ci_computer
22
- bot_name project slack_names].include?(method)
17
+ if %i[success_icon failed_icon skip_success_message
18
+ failed_title success_title webhook channel
19
+ ci_computer bot_name project slack_names].include?(method)
23
20
  CiSlack.configuration.send(method)
24
21
  else
25
22
  super
@@ -28,6 +25,24 @@ module CiSlack
28
25
 
29
26
  private
30
27
 
28
+ def text(status, author, commit_message, message)
29
+ "#{ project }. #{ send(status.to_s + '_title') }\n#{ slack_name(author, status) } : #{ commit_message }\n#{ message }"
30
+ end
31
+
32
+ def slack_name(author, status)
33
+ slack_name = slack_names.select { |key, _| author.downcase =~ key }.values.first
34
+
35
+ unless slack_name.nil?
36
+ if skip_success_message.include?(slack_name) && status == :success
37
+ slack_name
38
+ else
39
+ "<@#{ slack_name }>"
40
+ end
41
+ else
42
+ author
43
+ end
44
+ end
45
+
31
46
  def last_git_log
32
47
  `git log -1 --pretty='%an||%s'`.split('||').map(&:strip)
33
48
  end
@@ -1,3 +1,3 @@
1
1
  module CiSlack
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CiSlack do
4
+ it '.configure' do
5
+ CiSlack.configure do |config|
6
+ %i[failed_icon success_icon
7
+ success_title failed_title
8
+ webhook channel ci_computer
9
+ bot_name project slack_names
10
+ skip_success_message].each do |param|
11
+ config.send("#{ param }=", param)
12
+ end
13
+ end
14
+
15
+ %i[failed_icon success_icon
16
+ success_title failed_title
17
+ webhook channel ci_computer
18
+ bot_name project slack_names
19
+ skip_success_message].each do |param|
20
+ expect(CiSlack.configuration.send(param)).to eq(param)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CiSlack::Configuration do
4
+ it 'default params' do
5
+ config = CiSlack::Configuration.new
6
+
7
+ expect(config.failed_icon).to eq('failed')
8
+ expect(config.failed_title).to eq('CI FAILED!')
9
+ expect(config.success_icon).to eq('successful')
10
+ expect(config.success_title).to eq('SUCCESS')
11
+ expect(config.channel).to eq('#ci')
12
+ expect(config.ci_computer).to eq('CI')
13
+ expect(config.project).to eq('')
14
+ expect(config.slack_names).to eq({})
15
+ expect(config.skip_success_message).to eq([])
16
+ end
17
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/ci_slack/messager'
3
+
4
+ RSpec.describe CiSlack::Messager do
5
+ before do
6
+ CiSlack.configure do |config|
7
+ %i[webhook channel ci_computer bot_name project slack_names success_title].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
+ it "computer without ci: ENV['CI'] is absent" do
20
+ ENV['ci_computer'] = nil
21
+
22
+ messager = CiSlack::Messager.new
23
+
24
+ expect(messager.deliver('message')).to be_nil
25
+ end
26
+
27
+ it "computer with ci: ENV['CI'] is present" do
28
+ ENV['ci_computer'] = 'true'
29
+
30
+ messager = CiSlack::Messager.new
31
+
32
+ expect{messager.deliver('message')}.to raise_error(Slack::Notifier::APIError)
33
+ end
34
+
35
+ context 'configuration @skip_success_message' do
36
+ let(:messager) { CiSlack::Messager.new }
37
+
38
+ it 'present' do
39
+ CiSlack.configure do |config|
40
+ config.skip_success_message = ['author']
41
+ config.slack_names = { %r{author} => 'author' }
42
+ end
43
+
44
+ expect(messager.send(:text, :success, 'author', 'commit_message', 'message')).
45
+ to eq("project. success_title\nauthor : commit_message\nmessage")
46
+
47
+ end
48
+
49
+ it 'absent' do
50
+ CiSlack.configure do |config|
51
+ config.skip_success_message = []
52
+ config.slack_names = { %r{author} => 'author' }
53
+ end
54
+
55
+ expect(messager.send(:text, :success, 'author', 'commit_message', 'message')).
56
+ to eq("project. success_title\n<@author> : commit_message\nmessage")
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,105 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'ci_slack'
5
+
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
9
+ # this file to always be loaded, without a need to explicitly require it in any
10
+ # files.
11
+ #
12
+ # Given that it is always loaded, you are encouraged to keep this file as
13
+ # light-weight as possible. Requiring heavyweight dependencies from this file
14
+ # will add to the boot time of your test suite on EVERY test run, even for an
15
+ # individual file that may not need all of that loaded. Instead, consider making
16
+ # a separate helper file that requires the additional dependencies and performs
17
+ # the additional setup, and require it from the spec files that actually need
18
+ # it.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
46
+ # have no way to turn it off -- the option exists only for backwards
47
+ # compatibility in RSpec 3). It causes shared context metadata to be
48
+ # inherited by the metadata hash of host groups and examples, rather than
49
+ # triggering implicit auto-inclusion in groups with matching metadata.
50
+ config.shared_context_metadata_behavior = :apply_to_host_groups
51
+
52
+ # The settings below are suggested to provide a good initial experience
53
+ # with RSpec, but feel free to customize to your heart's content.
54
+ =begin
55
+ # This allows you to limit a spec run to individual examples or groups
56
+ # you care about by tagging them with `:focus` metadata. When nothing
57
+ # is tagged with `:focus`, all examples get run. RSpec also provides
58
+ # aliases for `it`, `describe`, and `context` that include `:focus`
59
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
60
+ config.filter_run_when_matching :focus
61
+
62
+ # Allows RSpec to persist some state between runs in order to support
63
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
64
+ # you configure your source control system to ignore this file.
65
+ config.example_status_persistence_file_path = "spec/examples.txt"
66
+
67
+ # Limits the available syntax to the non-monkey patched syntax that is
68
+ # recommended. For more details, see:
69
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
70
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
72
+ config.disable_monkey_patching!
73
+
74
+ # This setting enables warnings. It's recommended, but in some cases may
75
+ # be too noisy due to issues in dependencies.
76
+ config.warnings = true
77
+
78
+ # Many RSpec users commonly either run the entire suite or an individual
79
+ # file, and it's useful to allow more verbose output when running an
80
+ # individual spec file.
81
+ if config.files_to_run.one?
82
+ # Use the documentation formatter for detailed output,
83
+ # unless a formatter has already been configured
84
+ # (e.g. via a command-line flag).
85
+ config.default_formatter = "doc"
86
+ end
87
+
88
+ # Print the 10 slowest examples and example groups at the
89
+ # end of the spec run, to help surface which specs are running
90
+ # particularly slow.
91
+ config.profile_examples = 10
92
+
93
+ # Run specs in random order to surface order dependencies. If you find an
94
+ # order dependency and want to debug it, you can fix the order by providing
95
+ # the seed, which is printed after each run.
96
+ # --seed 1234
97
+ config.order = :random
98
+
99
+ # Seed global randomization in this process using the `--seed` CLI option.
100
+ # Setting this allows you to use `--seed` to deterministically reproduce
101
+ # test failures related to randomization by passing the same `--seed` value
102
+ # as the one that triggered the failure.
103
+ Kernel.srand config.seed
104
+ =end
105
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ci_slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - skrinits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-01 00:00:00.000000000 Z
11
+ date: 2017-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-notifier
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.3.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Send a message on failure of Continiues Integration to the specific channel
28
42
  with a link to the author of a last commit
29
43
  email:
@@ -33,17 +47,16 @@ extensions: []
33
47
  extra_rdoc_files: []
34
48
  files:
35
49
  - MIT-LICENSE
36
- - Rakefile
37
50
  - lib/ci_slack.rb
38
51
  - lib/ci_slack/configuration.rb
39
52
  - lib/ci_slack/messager.rb
40
53
  - lib/ci_slack/rspec/notifier.rb
41
54
  - lib/ci_slack/rspec/patch.rb
42
55
  - 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
56
+ - spec/ci_slack_spec.rb
57
+ - spec/configuration_spec.rb
58
+ - spec/messager_spec.rb
59
+ - spec/spec_helper.rb
47
60
  homepage: https://github.com/skrinits/ci_slack
48
61
  licenses:
49
62
  - MIT
@@ -69,7 +82,7 @@ signing_key:
69
82
  specification_version: 4
70
83
  summary: Slack report for Continiues Integration
71
84
  test_files:
72
- - test/messager_test.rb
73
- - test/ci_slack_test.rb
74
- - test/configuration_test.rb
75
- - test/test_helper.rb
85
+ - spec/spec_helper.rb
86
+ - spec/messager_spec.rb
87
+ - spec/ci_slack_spec.rb
88
+ - spec/configuration_spec.rb
data/Rakefile DELETED
@@ -1,29 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,36 +0,0 @@
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.deliver('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.deliver('message')
34
- end
35
- end
36
- end
data/test/test_helper.rb DELETED
@@ -1,20 +0,0 @@
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