chatopsify 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ad7c973ce861d481cbc1b15b008de15c5a489c84ed1410d61ec2bb834bed9be
4
- data.tar.gz: a87c09f10af7611b2453756767b1b413f4a89bd504afa16e2e353ec79cc58bbe
3
+ metadata.gz: d3e35cc917b13e407c723bfc8a553d7473223e9bef9a303d79901a73f3c3101e
4
+ data.tar.gz: 48275bee23cfe021d2837962017453aba49b645c86659c4fbeb39af66bc2605f
5
5
  SHA512:
6
- metadata.gz: 2a37716e4e9e248095a2ad2a2754eccd59315b1f684e1efcc5a2d14da788d37f71521e7d1b35344720e2095cbef4908e73336050c76bef40b8769c37a27ebb95
7
- data.tar.gz: b8cb3e14161a00fea4ea68f58199e82ba75741a75dae5733655bb078d724966f819521ed23f8cb47f2d06ad0dfed83e0090487b26670892640c289eea3c9473b
6
+ metadata.gz: 4f4d63cad15b583743737c8981d46207c7e38803fbc396226756ae1a117eb23a1d91f0161ea7f803e96fdf449aad93b2feaf29639d0c2d14ae7742448463a3b0
7
+ data.tar.gz: 319578035100502524f43404ee4542e90fe22f918a93aa1ca6b5029ba1609d89d48efe031d218faf63366a5b5e51bb19d1d5d187bc469dc95d92b05ff08a034d
@@ -8,20 +8,17 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
 
10
10
  steps:
11
- - uses: actions/checkout@v2
12
- - name: Set up Ruby 2.6 is
13
- uses: actions/setup-ruby@v1
11
+ - uses: actions/checkout@v4
12
+ - name: Set up Ruby 2.6.4
13
+ uses: ruby/setup-ruby@v1
14
14
  with:
15
- ruby-version: 2.6.x
16
- - uses: actions/cache@v1
17
- with:
18
- path: vendor/bundle
19
- key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
20
- restore-keys: |
21
- ${{ runner.os }}-gems-
15
+ ruby-version: 2.6.4
16
+ # - uses: ruby/setup-ruby@v1
17
+ # with:
18
+ # bundler-cache: true
22
19
  - name: Run Rubocop linter
23
20
  run: |
24
- gem install bundler
21
+ gem install bundler -v 2.4.22
25
22
  bundle config path vendor/bundle
26
23
  bundle install --jobs 4 --retry 3
27
24
  bundle exec rubocop
@@ -8,20 +8,14 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
 
10
10
  steps:
11
- - uses: actions/checkout@v2
12
- - name: Set up Ruby 2.6 is
13
- uses: actions/setup-ruby@v1
11
+ - uses: actions/checkout@v4
12
+ - name: Set up Ruby 2.6.4
13
+ uses: ruby/setup-ruby@v1
14
14
  with:
15
- ruby-version: 2.6.x
16
- - uses: actions/cache@v1
17
- with:
18
- path: vendor/bundle
19
- key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
20
- restore-keys: |
21
- ${{ runner.os }}-gems-
15
+ ruby-version: 2.6.4
22
16
  - name: Run test suite
23
17
  run: |
24
- gem install bundler
18
+ gem install bundler -v 2.4.22
25
19
  bundle config path vendor/bundle
26
20
  bundle install --jobs 4 --retry 3
27
21
  bundle exec rake test
data/.rubocop.yml CHANGED
@@ -6,8 +6,14 @@ Style/StringLiteralsInInterpolation:
6
6
  Enabled: true
7
7
  EnforcedStyle: single_quotes
8
8
 
9
+ Metrics/AbcSize:
10
+ Enabled: false
11
+
9
12
  Layout/LineLength:
10
13
  Max: 120
14
+ Metrics/MethodLength:
15
+ Max: 120
16
+
11
17
 
12
18
  AllCops:
13
19
  NewCops: enable
data/Gemfile CHANGED
@@ -5,8 +5,7 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in Chatopsify.gemspec
6
6
  gemspec
7
7
 
8
- gem 'rake', '~> 13.0'
9
-
8
+ gem 'bundler', '~> 2'
10
9
  gem 'minitest', '~> 5.0'
11
-
10
+ gem 'rake', '~> 13.0'
12
11
  gem 'rubocop', '~> 1.21'
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Chatopsify
2
2
 
3
- ![Gem](https://img.shields.io/gem/v/chatopsify?color=%25234cc61f&label=Gem%20version&logo=ruby&logoColor=red)
4
- ![Gem](https://img.shields.io/gem/dt/chatopsify?color=%2330c754&label=Downloads&logo=rubygems&logoColor=red)
5
- <!-- ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/rs-phunt/Chatopsify/Tests%20%F0%9F%A7%AA?label=Tests&logo=github)
6
- ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/rs-phunt/Chatopsify/Rubocop%20Lint?label=Rubocop&logo=github) -->
3
+ ![Gem](https://img.shields.io/gem/v/chatopsify?color=%25234cc61f&label=Gem%20version&logo=ruby&logoColor=red&link=https%3A%2F%2Frubygems.org%2Fgems%2Fchatopsify)
4
+ ![Gem](https://img.shields.io/gem/dt/chatopsify?color=%2330c754&label=Downloads&logo=rubygems&logoColor=red&link=https%3A%2F%2Frubygems.org%2Fgems%2Fchatopsify)
5
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/papakvy/chatopsify/run_rubocop.yml?branch=main&logo=rubocop&logoColor=red&label=Rubocop%20Lint)
6
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/papakvy/chatopsify/run_tests.yml?branch=main&logo=rubocop&logoColor=red&label=Tests%20%F0%9F%A7%AA)
7
+ <!-- ![GitHub Repo stars](https://img.shields.io/github/stars/papakvy/chatopsify?logoColor=red) -->
7
8
 
8
9
  ## Installation
9
10
 
@@ -48,6 +49,13 @@ set :chatops_channel_id, 'your_channel_id'
48
49
  ...
49
50
  ```
50
51
 
52
+ Config deploy success/failure notifications are posted as thread replies to the initial deploy start message.
53
+
54
+ ```ruby
55
+ # config/deploy.rb
56
+ set :chatops_use_thread_replies, true
57
+ ```
58
+
51
59
  ### Copyright
52
60
 
53
61
  ©rs-phunt
data/chatopsify.gemspec CHANGED
@@ -12,15 +12,15 @@ Gem::Specification.new do |spec|
12
12
  spec.email = ['phunt@runsystem.net']
13
13
 
14
14
  spec.summary = 'Publish deployment notifications to ChatOps via the API'
15
- spec.description = 'Publish deployment notifications to ChatOps via the API'
15
+ spec.description = 'chatopsify = ChatOps + Capistrano notifications via API'
16
16
  spec.homepage = 'https://github.com/papakvy/chatopsify'
17
17
  spec.license = 'MIT'
18
18
  spec.required_ruby_version = '>= 2.6'
19
19
 
20
20
  # spec.metadata['allowed_push_host'] = 'TODO: Set to your gem server 'https://example.com''
21
21
  spec.metadata['rubygems_mfa_required'] = 'true'
22
- spec.metadata['homepage_uri'] = spec.homepage
23
- spec.metadata['source_code_uri'] = 'https://github.com/papakvy/chatopsify'
22
+ # spec.metadata['homepage_uri'] = spec.homepage
23
+ # spec.metadata['source_code_uri'] = 'https://github.com/papakvy/chatopsify'
24
24
  spec.metadata['changelog_uri'] = 'https://github.com/papakvy/chatopsify/blob/master/CHANGELOG.md'
25
25
 
26
26
  spec.files = `git ls-files -z`.split("\x0")
@@ -31,8 +31,6 @@ Gem::Specification.new do |spec|
31
31
  # Uncomment to register a new dependency of your gem
32
32
 
33
33
  spec.add_dependency 'capistrano', '~> 3.2', '>= 3.2.0'
34
- spec.add_development_dependency 'bundler', '~> 2'
35
- spec.add_development_dependency 'rake', '~> 1'
36
34
 
37
35
  # For more information and examples about making a new gem, checkout our
38
36
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -4,7 +4,13 @@ namespace :chatops do
4
4
  set :chatops_time_started, Time.now
5
5
  run_locally do
6
6
  if fetch(:chatops_notify_events).include? :started
7
- Chatopsify::Co.call.process(Chatopsify::CoLib.msg_fmt(:starting))
7
+ info 'Notifying ChatOps of deploy started'
8
+ begin
9
+ response = Chatopsify::Co.call.process(Chatopsify::CoLib.msg_fmt(:starting))
10
+ set :chatops_root_id, response.dig('id') if fetch(:chatops_use_thread_replies)
11
+ rescue StandardError => e
12
+ info "ERROR notify_started: #{e}"
13
+ end
8
14
  end
9
15
  end
10
16
  end
@@ -17,20 +23,30 @@ namespace :chatops do
17
23
  run_locally do
18
24
  if fetch(:chatops_notify_events).include? :finished
19
25
  info 'Notifying ChatOps of deploy finished'
20
- Chatopsify::Co.call.process(Chatopsify::CoLib.msg_fmt(:success))
26
+ begin
27
+ root_id = fetch(:chatops_use_thread_replies) ? fetch(:chatops_root_id) : nil
28
+ Chatopsify::Co.call.process(Chatopsify::CoLib.msg_fmt(:success), root_id)
29
+ rescue StandardError => e
30
+ info "ERROR notify_finished: #{e}"
31
+ end
21
32
  end
22
33
  end
23
34
  end
24
35
  after 'deploy:finished', 'chatops:notify_finished'
25
36
  # before 'deploy:failed', 'chatops:notify_finished'
26
37
 
27
- desc "Notify ChatOps Finished"
38
+ desc "Notify ChatOps Failed"
28
39
  task :notify_failed do
29
40
  set :chatops_time_finished, Time.now
30
41
  run_locally do
31
42
  if fetch(:chatops_notify_events).include? :failed
32
43
  info 'Notifying ChatOps of deploy failed'
33
- Chatopsify::Co.call.process(Chatopsify::CoLib.msg_fmt(:failed))
44
+ begin
45
+ root_id = fetch(:chatops_use_thread_replies) ? fetch(:chatops_root_id) : nil
46
+ Chatopsify::Co.call.process(Chatopsify::CoLib.msg_fmt(:failed), root_id)
47
+ rescue StandardError => e
48
+ info "ERROR notify_failed: #{e}"
49
+ end
34
50
  end
35
51
  end
36
52
  end
@@ -42,6 +58,7 @@ namespace :load do
42
58
  set :chatops_co_uri, nil
43
59
  set :chatops_api_key, nil
44
60
  set :chatops_channel_id, nil
61
+ set :chatops_use_thread_replies, false
45
62
 
46
63
  set :local_user, ->{ ENV["USER"] || ENV["LOGNAME"] || ENV["USERNAME"] || `hostname`.strip + '•' + `whoami`.strip || "default_user" }
47
64
  set :ip_address, ->{
data/lib/chatopsify/co.rb CHANGED
@@ -4,6 +4,7 @@ require 'json'
4
4
  require 'net/http'
5
5
 
6
6
  module Chatopsify
7
+ # ChatOps services
7
8
  class Co
8
9
  def initialize(api_key = nil)
9
10
  @api_key = api_key || load_api_key
@@ -15,16 +16,16 @@ module Chatopsify
15
16
  new(*args, &block)
16
17
  end
17
18
 
18
- def process(body = nil)
19
+ def process(body = nil, root_id = nil)
19
20
  body ||= Chatopsify::CoLib.msg_fmt
20
21
 
21
- send_request(body)
22
+ send_request(body, root_id)
22
23
  rescue StandardError => e
23
24
  puts e.message
24
25
  end
25
26
 
26
- def call_get(id = nil)
27
- send_get_request(id)
27
+ def call_delete(id = nil)
28
+ send_delete_request(id)
28
29
  rescue StandardError => e
29
30
  puts e.message
30
31
  end
@@ -50,26 +51,26 @@ module Chatopsify
50
51
  Chatopsify::CoSecurity.call(@api_key).decrypt_string
51
52
  end
52
53
 
53
- def send_request(msg)
54
+ def send_request(msg, root_id)
54
55
  # puts "msg: #{msg}"
55
56
  uri = URI(@uri)
56
57
 
57
58
  req = Net::HTTP::Post.new(uri)
58
59
  req['authorization'] = "Bearer #{o_api_key}"
59
60
  req.content_type = 'application/json'
60
- req.body = { channel_id: @channel_id, message: msg }.to_json
61
+ req.body = { channel_id: @channel_id, message: msg, root_id: root_id }.to_json
61
62
  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
62
63
  http.request(req)
63
64
  end
64
65
 
65
66
  puts "Response: #{res.code} #{res.body}"
67
+ JSON.parse(res.body)
66
68
  end
67
69
 
68
- def send_get_request(id = nil)
70
+ def send_delete_request(id = nil)
69
71
  uri = URI(@uri)
70
72
  uri.path += "/#{id}" if id
71
73
 
72
- # req = Net::HTTP::Get.new(co_uri)
73
74
  req = Net::HTTP::Delete.new(uri)
74
75
  req['authorization'] = "Bearer #{o_api_key}"
75
76
  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
@@ -95,20 +96,23 @@ module Chatopsify
95
96
  end
96
97
  end
97
98
 
99
+ # rubocop:disable Lint/TripleQuotes, Style/StringLiterals, Layout/IndentationWidth
98
100
  def msg_fmt(status = nil)
99
101
  """#{text(status)}
100
102
  | TITLE | CONTENTS |
101
103
  |----------:|:-------------|
102
- | Stage | #{fetch(:stage).upcase!} |
103
- | Server | #{fetch(:ip_address) }|
104
+ | Stage | #{fetch(:stage)&.upcase!} |
105
+ | Server | #{fetch(:ip_address)}|
104
106
  | Branch | #{fetch(:branch)} |
105
107
  | Revision | #{fetch(:current_revision) || '<empty>'} |
106
- | Timestamp | #{Time.now.getlocal("+07:00") || Time.now} |
108
+ | Timestamp | #{Time.now.getlocal('+07:00') || Time.now} |
107
109
  """
108
110
  end
111
+ # rubocop:enable Lint/TripleQuotes, Style/StringLiterals, Layout/IndentationWidth
109
112
  end
110
113
  end
111
114
 
115
+ # CoSecurity service
112
116
  class CoSecurity
113
117
  require 'openssl'
114
118
  require 'securerandom'
@@ -122,44 +126,40 @@ module Chatopsify
122
126
  end
123
127
 
124
128
  def encrypt_string
125
- begin
126
- cipher = OpenSSL::Cipher::AES256.new(:CBC)
127
- cipher.encrypt
128
- salt = SecureRandom.random_bytes(16)
129
- key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(generate_pwd, salt, 2000, cipher.key_len + cipher.iv_len)
130
- key = key_iv[0, cipher.key_len]
131
- iv = key_iv[cipher.key_len, cipher.iv_len]
132
-
133
- cipher.key = key
134
- cipher.iv = iv
135
-
136
- encrypted = cipher.update(@str) + cipher.final
137
- (salt + encrypted).unpack1('H*')
138
- rescue => e
139
- false
140
- end
129
+ cipher = OpenSSL::Cipher.new('aes-256-cbc')
130
+ cipher.encrypt
131
+ salt = SecureRandom.random_bytes(16)
132
+ key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(generate_pwd, salt, 2000, cipher.key_len + cipher.iv_len)
133
+ key = key_iv[0, cipher.key_len]
134
+ iv = key_iv[cipher.key_len, cipher.iv_len]
135
+
136
+ cipher.key = key
137
+ cipher.iv = iv
138
+
139
+ encrypted = cipher.update(@str) + cipher.final
140
+ (salt + encrypted).unpack1('H*')
141
+ rescue StandardError => e
142
+ puts e.message
141
143
  end
142
144
 
143
145
  def decrypt_string
144
- begin
145
- encrypted = [@str].pack('H*')
146
- cipher = OpenSSL::Cipher::AES256.new(:CBC)
147
- cipher.decrypt
146
+ encrypted = [@str].pack('H*')
147
+ cipher = OpenSSL::Cipher.new('aes-256-cbc')
148
+ cipher.decrypt
148
149
 
149
- salt = encrypted[0, 16]
150
- encrypted_data = encrypted[16..-1]
150
+ salt = encrypted[0, 16]
151
+ encrypted_data = encrypted[16..]
151
152
 
152
- key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(generate_pwd, salt, 2000, cipher.key_len + cipher.iv_len)
153
- key = key_iv[0, cipher.key_len]
154
- iv = key_iv[cipher.key_len, cipher.iv_len]
153
+ key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(generate_pwd, salt, 2000, cipher.key_len + cipher.iv_len)
154
+ key = key_iv[0, cipher.key_len]
155
+ iv = key_iv[cipher.key_len, cipher.iv_len]
155
156
 
156
- cipher.key = key
157
- cipher.iv = iv
157
+ cipher.key = key
158
+ cipher.iv = iv
158
159
 
159
- cipher.update(encrypted_data) + cipher.final
160
- rescue => e
161
- false
162
- end
160
+ cipher.update(encrypted_data) + cipher.final
161
+ rescue StandardError => e
162
+ puts e.message
163
163
  end
164
164
 
165
165
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chatopsify
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.7'
5
5
  end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path('lib', __dir__)
4
- require 'Chatopsify'
4
+ require 'chatopsify'
5
5
 
6
6
  require 'minitest/autorun'
metadata CHANGED
@@ -1,64 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatopsify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - phunt
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-17 00:00:00.000000000 Z
11
+ date: 2026-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '3.2'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: 3.2.0
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
20
  - - "~>"
28
21
  - !ruby/object:Gem::Version
29
22
  version: '3.2'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 3.2.0
33
- - !ruby/object:Gem::Dependency
34
- name: bundler
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '2'
40
- type: :development
23
+ type: :runtime
41
24
  prerelease: false
42
25
  version_requirements: !ruby/object:Gem::Requirement
43
26
  requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '2'
47
- - !ruby/object:Gem::Dependency
48
- name: rake
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
27
+ - - ">="
52
28
  - !ruby/object:Gem::Version
53
- version: '1'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
29
+ version: 3.2.0
58
30
  - - "~>"
59
31
  - !ruby/object:Gem::Version
60
- version: '1'
61
- description: Publish deployment notifications to ChatOps via the API
32
+ version: '3.2'
33
+ description: chatopsify = ChatOps + Capistrano notifications via API
62
34
  email:
63
35
  - phunt@runsystem.net
64
36
  executables: []
@@ -84,17 +56,15 @@ files:
84
56
  - lib/chatopsify/co.rb
85
57
  - lib/chatopsify/version.rb
86
58
  - lib/core_ext/custom_lib.rb
87
- - test/chatworkify_test.rb
59
+ - test/chatopsify_test.rb
88
60
  - test/test_helper.rb
89
61
  homepage: https://github.com/papakvy/chatopsify
90
62
  licenses:
91
63
  - MIT
92
64
  metadata:
93
65
  rubygems_mfa_required: 'true'
94
- homepage_uri: https://github.com/papakvy/chatopsify
95
- source_code_uri: https://github.com/papakvy/chatopsify
96
66
  changelog_uri: https://github.com/papakvy/chatopsify/blob/master/CHANGELOG.md
97
- post_install_message:
67
+ post_install_message:
98
68
  rdoc_options: []
99
69
  require_paths:
100
70
  - lib
@@ -109,8 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
79
  - !ruby/object:Gem::Version
110
80
  version: '0'
111
81
  requirements: []
112
- rubygems_version: 3.5.10
113
- signing_key:
82
+ rubygems_version: 3.0.3.1
83
+ signing_key:
114
84
  specification_version: 4
115
85
  summary: Publish deployment notifications to ChatOps via the API
116
86
  test_files: []
File without changes