circleci_deployment_notifier 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/circleci_deployment_notifier.gemspec +29 -0
- data/exe/circleci_deployment_notify_slack +49 -0
- data/lib/circleci_deployment_notifier.rb +5 -0
- data/lib/circleci_deployment_notifier/build.rb +22 -0
- data/lib/circleci_deployment_notifier/build_info.rb +59 -0
- data/lib/circleci_deployment_notifier/slack.rb +71 -0
- data/lib/circleci_deployment_notifier/version.rb +3 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 214c419d82d11a261c0380fd0f0431c892fb4923
|
4
|
+
data.tar.gz: 9a58c249f3419846c69a220988d83dfabe529471
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2a361d88285b294255969f8a9fd52b6b97680292512d70d761128ed8ff835b1d890f150f47b89d879170a4416dd596f72a29e6951587dd62094eaba5aed57ac7
|
7
|
+
data.tar.gz: a3545c4d0505905c6e36a4af31e56ee249363900f497a43e4e079777745d15b7750c8025939a391eddcb013f7ac55b56308ad60e510c88618e76d2084b6bd378
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Robin Daugherty
|
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,39 @@
|
|
1
|
+
# CircleCI Deployment Notifier
|
2
|
+
|
3
|
+
Sends deployment notifications based on deployments that occur on CircleCI.
|
4
|
+
|
5
|
+
Assumptions:
|
6
|
+
|
7
|
+
- Using CircleCI.
|
8
|
+
- Using Github.
|
9
|
+
- Using Slack for notifications.
|
10
|
+
|
11
|
+
You can also:
|
12
|
+
|
13
|
+
- Deploy releases that are tagged using Github Releases.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Requires Ruby 2.0.0 or higher.
|
18
|
+
|
19
|
+
```sh
|
20
|
+
gem install circleci_deployment_notifier
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/RobinDaugherty/circleci_deployment_notifier.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "circleci_deployment_notifier"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'circleci_deployment_notifier/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "circleci_deployment_notifier"
|
8
|
+
spec.version = CircleciDeploymentNotifier::VERSION
|
9
|
+
spec.authors = ["Robin Daugherty"]
|
10
|
+
spec.email = ["robin@robindaugherty.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{Sends deployment notifications based on deployments that occur on CircleCI.}
|
13
|
+
spec.homepage = "https://github.com/RobinDaugherty/circleci_deployment_notifier"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "webmock", "~> 2.3"
|
27
|
+
spec.add_dependency "slack-notifier", "~> 2.0"
|
28
|
+
spec.add_dependency "slop", "~> 4.4"
|
29
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'circleci_deployment_notifier'
|
4
|
+
require 'slop'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
puts "CircleCI Deployment Notify Slack"
|
8
|
+
|
9
|
+
opts = Slop.parse do |o|
|
10
|
+
o.string '-a', '--app-name', 'Name of the application that was deployed (e.g. "Asgard Production")'
|
11
|
+
o.string '-u', '--webhook-url', 'Slack Webhook URL'
|
12
|
+
o.on '--version', 'print the version' do
|
13
|
+
puts CircleciDeploymentNotifier::VERSION
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
unless ENV['CIRCLECI']
|
19
|
+
STDERR.puts "ERROR: This is not a CircleCI build (missing environment variables)."
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
|
23
|
+
# unless ARGV.size == 2
|
24
|
+
# STDERR.puts "Not enough arguments."
|
25
|
+
# print_help
|
26
|
+
# end
|
27
|
+
|
28
|
+
app_name = opts[:app_name]
|
29
|
+
webhook_url = opts[:webhook_url]
|
30
|
+
|
31
|
+
if webhook_url.nil?
|
32
|
+
STDERR.puts "ERROR: Missing Slack Webhook URL"
|
33
|
+
puts opts
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
37
|
+
if app_name.nil?
|
38
|
+
STDERR.puts "ERROR: Missing App Name"
|
39
|
+
puts opts
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
|
43
|
+
unless webhook_url =~ /\A#{URI::regexp(['http', 'https'])}\z/
|
44
|
+
STDERR.puts "ERROR: Slack Webhook URL is not a valid URL: #{webhook_url}"
|
45
|
+
puts opts
|
46
|
+
exit 1
|
47
|
+
end
|
48
|
+
|
49
|
+
CircleciDeploymentNotifier::Build.new(app_name: app_name).send_to_slack(webhook_url: webhook_url)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "circleci_deployment_notifier/build_info"
|
2
|
+
require "circleci_deployment_notifier/slack"
|
3
|
+
|
4
|
+
module CircleciDeploymentNotifier
|
5
|
+
class Build
|
6
|
+
def initialize(app_name:)
|
7
|
+
self.app_name = app_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def send_to_slack(webhook_url:)
|
11
|
+
Slack.new(webhook_url: webhook_url, app_name: app_name, build_info: build_info).send
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_accessor :app_name
|
17
|
+
|
18
|
+
def build_info
|
19
|
+
@build_info ||= BuildInfo.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module CircleciDeploymentNotifier
|
2
|
+
class BuildInfo
|
3
|
+
def commit_hash
|
4
|
+
ENV['CIRCLE_SHA1']
|
5
|
+
end
|
6
|
+
|
7
|
+
def commit_browse_url
|
8
|
+
"#{repository_url}/tree/#{commit_hash}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def branch_name
|
12
|
+
ENV['CIRCLE_BRANCH']
|
13
|
+
end
|
14
|
+
|
15
|
+
def tag_name
|
16
|
+
ENV['CIRCLE_TAG']
|
17
|
+
end
|
18
|
+
|
19
|
+
def tag_url
|
20
|
+
return unless tag_name
|
21
|
+
"#{repository_url}/tree/#{tag_name}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def tag_release_notes_url
|
25
|
+
return unless tag_name
|
26
|
+
"#{repository_url}/releases/tag/#{tag_name}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def tag?
|
30
|
+
tag_name
|
31
|
+
end
|
32
|
+
|
33
|
+
def builder_username
|
34
|
+
ENV['CIRCLE_USERNAME']
|
35
|
+
end
|
36
|
+
|
37
|
+
def builder_icon
|
38
|
+
return unless builder_username
|
39
|
+
"https://github.com/#{builder_username}.png"
|
40
|
+
end
|
41
|
+
|
42
|
+
def builder_url
|
43
|
+
return unless builder_username
|
44
|
+
"https://github.com/#{builder_username}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def repository_url
|
48
|
+
ENV['CIRCLE_REPOSITORY_URL']
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_identifier
|
52
|
+
ENV['CIRCLE_BUILD_NUM']
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_url
|
56
|
+
ENV['CIRCLE_BUILD_URL']
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'slack-notifier'
|
2
|
+
|
3
|
+
module CircleciDeploymentNotifier
|
4
|
+
##
|
5
|
+
# Sends notifications to Slack.
|
6
|
+
# Builds the message from a BuildInfo object.
|
7
|
+
class Slack
|
8
|
+
def initialize(webhook_url:, app_name:, build_info:)
|
9
|
+
self.webhook_url = webhook_url
|
10
|
+
self.app_name = app_name
|
11
|
+
self.build_info = build_info
|
12
|
+
end
|
13
|
+
|
14
|
+
def send
|
15
|
+
slack_notifier.post message
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_accessor :webhook_url
|
21
|
+
attr_accessor :app_name
|
22
|
+
attr_accessor :build_info
|
23
|
+
|
24
|
+
def message
|
25
|
+
{
|
26
|
+
username: username,
|
27
|
+
attachments: [
|
28
|
+
{
|
29
|
+
fallback: fallback_text,
|
30
|
+
color: "good",
|
31
|
+
text: text,
|
32
|
+
footer: footer_text,
|
33
|
+
footer_icon: footer_icon,
|
34
|
+
},
|
35
|
+
],
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def username
|
40
|
+
"#{app_name} Deployments"
|
41
|
+
end
|
42
|
+
|
43
|
+
def fallback_text
|
44
|
+
"#{build_info.tag_name || build_info.branch_name} deployed"\
|
45
|
+
"#{build_info.builder_username ? " by #{build_info.builder_username}" : ""}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def text
|
49
|
+
if build_info.tag_name
|
50
|
+
"<#{build_info.tag_url}|#{build_info.tag_name}>" \
|
51
|
+
" (<#{build_info.tag_release_notes_url}|release notes>)"
|
52
|
+
elsif build_info.branch_name
|
53
|
+
"<#{build_info.commit_browse_url}|#{build_info.branch_name}>"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def footer_text
|
58
|
+
return unless build_info.builder_url
|
59
|
+
"deployed by <#{build_info.builder_url}|#{build_info.builder_username}>" \
|
60
|
+
" in <#{build_info.build_url}|build #{build_info.build_identifier}>"
|
61
|
+
end
|
62
|
+
|
63
|
+
def footer_icon
|
64
|
+
build_info.builder_icon
|
65
|
+
end
|
66
|
+
|
67
|
+
def slack_notifier
|
68
|
+
@slack_notifier ||= ::Slack::Notifier.new(webhook_url)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: circleci_deployment_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robin Daugherty
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-14 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: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: slack-notifier
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: slop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.4'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.4'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- robin@robindaugherty.net
|
100
|
+
executables:
|
101
|
+
- circleci_deployment_notify_slack
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- circleci_deployment_notifier.gemspec
|
115
|
+
- exe/circleci_deployment_notify_slack
|
116
|
+
- lib/circleci_deployment_notifier.rb
|
117
|
+
- lib/circleci_deployment_notifier/build.rb
|
118
|
+
- lib/circleci_deployment_notifier/build_info.rb
|
119
|
+
- lib/circleci_deployment_notifier/slack.rb
|
120
|
+
- lib/circleci_deployment_notifier/version.rb
|
121
|
+
homepage: https://github.com/RobinDaugherty/circleci_deployment_notifier
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.6.8
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Sends deployment notifications based on deployments that occur on CircleCI.
|
145
|
+
test_files: []
|