deploy_changes_notifier 0.1.1
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +67 -0
- data/Rakefile +6 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/deploy_changes_notifier.gemspec +37 -0
- data/lib/deploy_changes.rb +6 -0
- data/lib/deploy_changes/error_raiser.rb +66 -0
- data/lib/deploy_changes/errors/errors.rb +21 -0
- data/lib/deploy_changes/notifier.rb +212 -0
- data/lib/deploy_changes/validator.rb +77 -0
- data/lib/deploy_changes/version.rb +3 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c89752ea354cc918a35c7494349eb1d39e3665ca
|
4
|
+
data.tar.gz: 75b6aff3c508b22ae24014d49e50a62d6e749c2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f54c96c9cc55e69bfc170cf5a4020eee555cd9aaa72fa60305b57e3da180969ba7a2ca5b602e36a0c24dae399bc08b557c3476b267513aca3682abeb443441c
|
7
|
+
data.tar.gz: accbc3a2f8aa17462cbeccd65853d116b7534abb53ad9a7fde59e02638ae5943cfdbc611de7d35666b355ec13471fa0f2c1059d4b93d018e81b8778f944991df
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
deploy_changes_notifier
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Subodh Khanduri
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# DeployChangesNotifier
|
2
|
+
|
3
|
+
Send notifications for the changes deployed in each build, compared to the previous build. It is a good practise to create GIT tags for each deployment. DeployChangesNotifier compares the latest deployed tag with the previous deployed tag and sends the list of new commits deployed to a Slack channel.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'deploy_changes_notifier'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install deploy_changes_notifier
|
20
|
+
|
21
|
+
Or use the github url:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'deploy_changes_notifier', git: "https://github.com/subodhkhanduri1/deploy_changes_notifier.git"
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Require the gem
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'deploy_changes'
|
33
|
+
```
|
34
|
+
|
35
|
+
Send notification
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
notifier = DeployChanges::Notifier.new do |config|
|
39
|
+
config.git_repo_url = 'https://github.com/<your_organization>/<your_repo_name>'
|
40
|
+
# Tags are expected to be numbered in sequential order. Build numbers would work nicely.
|
41
|
+
config.tag_prefix = 'app-prd-'
|
42
|
+
config.deploy_job_name = '<your_deploy_job_name>'
|
43
|
+
config.deploy_job_build_number = 3 # The latest deploy job build number
|
44
|
+
config.slack_channel = 'Production'
|
45
|
+
config.slack_bot_api_token = '<some_token>'
|
46
|
+
end
|
47
|
+
|
48
|
+
notifier.send_deploy_changes_notification
|
49
|
+
```
|
50
|
+
|
51
|
+
To supply the config parameters to a script, pass in environment variables with the same name as the config variables. If you pass in environment variables, there is no need to pass config variables in the constructor.
|
52
|
+
|
53
|
+
## Development
|
54
|
+
|
55
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
|
+
|
57
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/subodhkhanduri1/deploy_changes_notifier.
|
62
|
+
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
67
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
puts $LOAD_PATH
|
4
|
+
require "bundler/setup"
|
5
|
+
require "deploy_changes"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'deploy_changes/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "deploy_changes_notifier"
|
8
|
+
spec.version = DeployChanges::VERSION
|
9
|
+
spec.authors = ["Subodh Khanduri"]
|
10
|
+
spec.email = ["subodhkhanduri1@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Deploy changes notifier"
|
13
|
+
spec.description = "This is a simple gem to push deploy changes notification to a Slack channel."
|
14
|
+
spec.homepage = "https://github.com/subodhkhanduri1/deploy_changes_notifier"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_dependency "slack-ruby-client", "~> 0.5.0"
|
37
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative 'errors/errors'
|
2
|
+
|
3
|
+
module DeployChanges
|
4
|
+
class ErrorRaiser
|
5
|
+
|
6
|
+
def raise_slack_channel_missing_error
|
7
|
+
fail(
|
8
|
+
Errors::SlackChannelMissing.new,
|
9
|
+
"SLACK_CHANNEL env variable missing. Ex: '#test_channel'"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def raise_slack_api_token_missing_error
|
14
|
+
fail(
|
15
|
+
Errors::SlackApiTokenMissing.new,
|
16
|
+
"SLACK_BOT_API_TOKEN env variable missing"
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def raise_invalid_git_repo_url_error(repo_url)
|
21
|
+
fail(
|
22
|
+
Errors::InvalidGitRepoUrl.new(repo_url),
|
23
|
+
"'#{repo_url}' is not a valid SQ Git Repo URL"
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def raise_invalid_tag_name_error(tag_name)
|
28
|
+
message = if tag_name.nil? || tag_name.empty?
|
29
|
+
"Git tag name missing"
|
30
|
+
else
|
31
|
+
"Git tag '#{tag_name}' not found"
|
32
|
+
end
|
33
|
+
|
34
|
+
fail Errors::InvalidTagName.new, message
|
35
|
+
end
|
36
|
+
|
37
|
+
def raise_git_repo_clone_failed_error(git_repo_url)
|
38
|
+
fail(
|
39
|
+
Errors::GitRepoCloneFailed.new,
|
40
|
+
"Git clone from '#{git_repo_url}' failed"
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def raise_deploy_job_build_number_missing_error
|
45
|
+
fail(
|
46
|
+
Errors::DeployJobBuildNumberMissing.new,
|
47
|
+
"DEPLOY_JOB_BUILD_NUMBER env variable missing."
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def raise_deploy_job_name_missing_error
|
52
|
+
fail(
|
53
|
+
Errors::DeployJobNameMissing.new,
|
54
|
+
"DEPLOY_JOB_NAME env variable missing."
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def raise_tag_prefix_missing_error
|
59
|
+
fail(
|
60
|
+
Errors::TagPrefixMissingError.new,
|
61
|
+
"TAG_PREFIX env variable missing."
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DeployChanges
|
2
|
+
module Errors
|
3
|
+
|
4
|
+
class InvalidGitRepoUrl < StandardError; end
|
5
|
+
|
6
|
+
class InvalidTagName < StandardError; end
|
7
|
+
|
8
|
+
class DeployJobNameMissing < StandardError; end
|
9
|
+
|
10
|
+
class DeployJobBuildNumberMissing < StandardError; end
|
11
|
+
|
12
|
+
class TagPrefixMissingError < StandardError; end
|
13
|
+
|
14
|
+
class SlackChannelMissing < StandardError; end
|
15
|
+
|
16
|
+
class SlackApiTokenMissing < StandardError; end
|
17
|
+
|
18
|
+
class GitRepoCloneFailed < StandardError; end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,212 @@
|
|
1
|
+
# This class compares the latest deployed tag and the one deployed before it,
|
2
|
+
# and sends a Slack notification with the list of all new commits deployed
|
3
|
+
#
|
4
|
+
# Requirements:
|
5
|
+
#
|
6
|
+
# The following environment variables must be supplied
|
7
|
+
# - GIT_REPO_URL: The url of the deployed repository
|
8
|
+
# - TAG_PREFIX: The prefix before the build number
|
9
|
+
# (Ex: "app-stg-")
|
10
|
+
# - DEPLOY_JOB_NAME: The name of the deploy job that was triggered
|
11
|
+
# - DEPLOY_JOB_BUILD_NUMBER: The latest build number of the deploy job
|
12
|
+
# - SLACK_BOT_API_TOKEN: The access token of the Slack bot which will post the notification
|
13
|
+
# - SLACK_CHANNEL: The Slack channel to post to
|
14
|
+
#
|
15
|
+
# Assumptions:
|
16
|
+
#
|
17
|
+
# - The DEPLOY_JOB_BUILD_NUMBER is always of the latest stable build
|
18
|
+
|
19
|
+
require 'slack-ruby-client'
|
20
|
+
require_relative 'validator'
|
21
|
+
|
22
|
+
module DeployChanges
|
23
|
+
|
24
|
+
class Notifier
|
25
|
+
|
26
|
+
attr_reader(
|
27
|
+
:git_repo_url,
|
28
|
+
:tag_prefix,
|
29
|
+
:slack_channel,
|
30
|
+
:deploy_job_name,
|
31
|
+
:deploy_job_build_number,
|
32
|
+
:new_tag_name
|
33
|
+
)
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
self.validator = Validator.new(self)
|
37
|
+
|
38
|
+
config = OpenStruct.new
|
39
|
+
|
40
|
+
yield config if block_given?
|
41
|
+
|
42
|
+
self.git_repo_url = config.git_repo_url || ENV["GIT_REPO_URL"]
|
43
|
+
self.tag_prefix = config.tag_prefix || ENV["TAG_PREFIX"]
|
44
|
+
|
45
|
+
self.deploy_job_build_number = config.deploy_job_build_number || ENV["DEPLOY_JOB_BUILD_NUMBER"]
|
46
|
+
self.deploy_job_name = config.deploy_job_name || ENV["DEPLOY_JOB_NAME"]
|
47
|
+
|
48
|
+
self.new_tag_name = tag_prefix + deploy_job_build_number
|
49
|
+
|
50
|
+
self.slack_channel = config.slack_channel || ENV["SLACK_CHANNEL"]
|
51
|
+
self.slack_bot_api_token = config.slack_bot_api_token || ENV["SLACK_BOT_API_TOKEN"]
|
52
|
+
configure_slack
|
53
|
+
end
|
54
|
+
|
55
|
+
def send_deploy_changes_notification
|
56
|
+
cleanup_repo
|
57
|
+
clone_repo
|
58
|
+
send_slack_notification
|
59
|
+
rescue StandardError => e
|
60
|
+
raise e
|
61
|
+
ensure
|
62
|
+
cleanup_repo
|
63
|
+
end
|
64
|
+
|
65
|
+
def git_repo_directory
|
66
|
+
@git_repo_directory ||= git_repo_url
|
67
|
+
.split('/')
|
68
|
+
.last
|
69
|
+
.gsub('.git', '')
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
attr_writer :new_tag_name
|
75
|
+
attr_accessor :validator, :slack_bot_api_token
|
76
|
+
|
77
|
+
def configure_slack
|
78
|
+
validator.validate_slack_api_token(ENV["SLACK_BOT_API_TOKEN"])
|
79
|
+
|
80
|
+
Slack.configure do |config|
|
81
|
+
config.token = ENV["SLACK_BOT_API_TOKEN"]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def send_slack_notification
|
86
|
+
slack_client.auth_test
|
87
|
+
|
88
|
+
slack_client.chat_postMessage(
|
89
|
+
channel: slack_channel,
|
90
|
+
text: deploy_changes_message,
|
91
|
+
as_user: true
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
def deploy_changes_message
|
96
|
+
deploy_changes_array = deploy_changes_list
|
97
|
+
|
98
|
+
message = "*#{deploy_job_name} \##{deploy_job_build_number} changes:*\n"
|
99
|
+
|
100
|
+
message += if deploy_changes_array.empty?
|
101
|
+
" - No changes"
|
102
|
+
else
|
103
|
+
deploy_changes_array
|
104
|
+
.map { |commit_message| " - " + commit_message }
|
105
|
+
.join("\n")
|
106
|
+
end
|
107
|
+
|
108
|
+
puts message
|
109
|
+
|
110
|
+
message
|
111
|
+
end
|
112
|
+
|
113
|
+
def deploy_changes_list
|
114
|
+
return [] if previous_tag_name.nil? || previous_tag_name.empty?
|
115
|
+
|
116
|
+
deploy_changes_string = deploy_changes_command_output
|
117
|
+
return [] unless validator.last_command_successful?
|
118
|
+
|
119
|
+
deploy_changes_string.split("\n")
|
120
|
+
end
|
121
|
+
|
122
|
+
def deploy_changes_command_output
|
123
|
+
`#{deploy_changes_command}`
|
124
|
+
end
|
125
|
+
|
126
|
+
def deploy_changes_command
|
127
|
+
validator.validate_new_tag(new_tag_name)
|
128
|
+
|
129
|
+
puts "New tag name: #{new_tag_name}"
|
130
|
+
|
131
|
+
"cd #{git_repo_directory} && git log --pretty=oneline --no-merges --format=\"%s [%an]\" #{previous_tag_name}...#{new_tag_name}"
|
132
|
+
end
|
133
|
+
|
134
|
+
def previous_tag_name
|
135
|
+
return @previous_tag_name if @previous_tag_name
|
136
|
+
|
137
|
+
previous_tag = previous_tag_from_tags_list(tags_list)
|
138
|
+
|
139
|
+
puts "Previous tag name: #{previous_tag}"
|
140
|
+
@previous_tag_name = previous_tag
|
141
|
+
end
|
142
|
+
|
143
|
+
def tags_list
|
144
|
+
tags = tags_list_command_output
|
145
|
+
tags.split("\n")
|
146
|
+
.reverse
|
147
|
+
.map { |ref| ref.gsub("refs/tags/", "") }
|
148
|
+
end
|
149
|
+
|
150
|
+
def tags_list_command_output
|
151
|
+
`cd #{git_repo_directory} && git for-each-ref --sort=taggerdate --format="%(refname)" refs/tags/#{tag_prefix}*`
|
152
|
+
end
|
153
|
+
|
154
|
+
def previous_tag_from_tags_list(tags_list)
|
155
|
+
tags_list.each_with_index do |tag, index|
|
156
|
+
return tags_list[index + 1] if tag == new_tag_name
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def clone_repo
|
161
|
+
puts "Cloning from '#{git_repo_url}'"
|
162
|
+
|
163
|
+
`git clone #{git_repo_url}`
|
164
|
+
|
165
|
+
validator.validate_repo_cloned(git_repo_directory)
|
166
|
+
end
|
167
|
+
|
168
|
+
def cleanup_repo
|
169
|
+
return true unless Dir.exist?(git_repo_directory)
|
170
|
+
|
171
|
+
puts "Deleting '#{git_repo_directory}' folder"
|
172
|
+
|
173
|
+
`rm -rf #{git_repo_directory}`
|
174
|
+
end
|
175
|
+
|
176
|
+
def git_repo_url=(repo_url)
|
177
|
+
validator.validate_repo_url(repo_url)
|
178
|
+
|
179
|
+
@git_repo_url = repo_url
|
180
|
+
end
|
181
|
+
|
182
|
+
def tag_prefix=(prefix)
|
183
|
+
validator.validate_tag_prefix(prefix)
|
184
|
+
|
185
|
+
@tag_prefix = prefix
|
186
|
+
end
|
187
|
+
|
188
|
+
def deploy_job_build_number=(job_build_number)
|
189
|
+
validator.validate_deploy_job_build_number(job_build_number)
|
190
|
+
|
191
|
+
@deploy_job_build_number = job_build_number
|
192
|
+
end
|
193
|
+
|
194
|
+
def deploy_job_name=(job_name)
|
195
|
+
validator.validate_deploy_job_name(job_name)
|
196
|
+
|
197
|
+
@deploy_job_name = job_name
|
198
|
+
end
|
199
|
+
|
200
|
+
def slack_channel=(channel_name)
|
201
|
+
validator.validate_slack_channel_name(channel_name)
|
202
|
+
|
203
|
+
@slack_channel = channel_name
|
204
|
+
end
|
205
|
+
|
206
|
+
def slack_client
|
207
|
+
@slack_client ||= Slack::Web::Client.new
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require_relative 'error_raiser'
|
2
|
+
require 'English'
|
3
|
+
|
4
|
+
module DeployChanges
|
5
|
+
class Validator
|
6
|
+
|
7
|
+
attr_accessor :notifier, :error_raiser
|
8
|
+
|
9
|
+
def initialize(notifier_object)
|
10
|
+
self.notifier = notifier_object
|
11
|
+
self.error_raiser = ErrorRaiser.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def validate_repo_url(repo_url)
|
15
|
+
error_raiser.raise_invalid_git_repo_url_error(
|
16
|
+
repo_url
|
17
|
+
) unless repo_url =~ git_repo_url_regex
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_tag_prefix(prefix)
|
21
|
+
error_raiser.raise_tag_prefix_missing_error unless non_empty_string?(prefix)
|
22
|
+
end
|
23
|
+
|
24
|
+
def validate_deploy_job_build_number(job_build_number)
|
25
|
+
return if non_empty_string?(job_build_number) && job_build_number.to_i > 0
|
26
|
+
|
27
|
+
error_raiser.raise_deploy_job_build_number_missing_error
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate_deploy_job_name(job_name)
|
31
|
+
error_raiser.raise_deploy_job_name_missing_error unless non_empty_string?(job_name)
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate_slack_channel_name(channel_name)
|
35
|
+
error_raiser.raise_slack_channel_missing_error unless non_empty_string?(channel_name)
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_new_tag(new_tag_name)
|
39
|
+
return if non_empty_string?(new_tag_name) && git_tag_exists?(new_tag_name)
|
40
|
+
|
41
|
+
error_raiser.raise_invalid_tag_name_error(new_tag_name)
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_slack_api_token(token)
|
45
|
+
return if non_empty_string?(token)
|
46
|
+
|
47
|
+
error_raiser.raise_slack_api_token_missing_error
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_repo_cloned(repo_directory_name)
|
51
|
+
error_raiser.raise_git_repo_clone_failed_error(
|
52
|
+
notifier.git_repo_url
|
53
|
+
) unless last_command_successful? && Dir.exist?(repo_directory_name)
|
54
|
+
end
|
55
|
+
|
56
|
+
def last_command_successful?
|
57
|
+
$CHILD_STATUS.success?
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def git_repo_url_regex
|
63
|
+
/^https:\/\/github.com\/(.*)\/(.*)/
|
64
|
+
end
|
65
|
+
|
66
|
+
def git_tag_exists?(tag_name)
|
67
|
+
tag_command_output = `cd #{notifier.git_repo_directory} && git tag -l #{tag_name}`
|
68
|
+
|
69
|
+
$CHILD_STATUS.success? && tag_command_output.split("\n").count == 1
|
70
|
+
end
|
71
|
+
|
72
|
+
def non_empty_string?(string_var)
|
73
|
+
string_var.is_a?(String) && !string_var.empty?
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deploy_changes_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Subodh Khanduri
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: slack-ruby-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.5.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.5.0
|
69
|
+
description: This is a simple gem to push deploy changes notification to a Slack channel.
|
70
|
+
email:
|
71
|
+
- subodhkhanduri1@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".ruby-gemset"
|
79
|
+
- ".ruby-version"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- deploy_changes_notifier.gemspec
|
88
|
+
- lib/deploy_changes.rb
|
89
|
+
- lib/deploy_changes/error_raiser.rb
|
90
|
+
- lib/deploy_changes/errors/errors.rb
|
91
|
+
- lib/deploy_changes/notifier.rb
|
92
|
+
- lib/deploy_changes/validator.rb
|
93
|
+
- lib/deploy_changes/version.rb
|
94
|
+
homepage: https://github.com/subodhkhanduri1/deploy_changes_notifier
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata:
|
98
|
+
allowed_push_host: https://rubygems.org
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.5.1
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Deploy changes notifier
|
119
|
+
test_files: []
|