octobot-slack_agent 0.1.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/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/bin/console +15 -0
- data/bin/setup +7 -0
- data/lib/octobot/slack_agent/deploy_notifier.rb +43 -0
- data/lib/octobot/slack_agent/notifier.rb +64 -0
- data/lib/octobot/slack_agent/version.rb +5 -0
- data/lib/octobot/slack_agent.rb +10 -0
- data/octobot-slack_agent.gemspec +24 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 22cb0d20d4ce7fc92150fac6fb17b6db258b5ebe
|
4
|
+
data.tar.gz: fb7080eb8f07d9a099ebdbcdecfa5faf75dbd364
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c9d970866132da6b68e69b323af196b90a049e8f7f629b47c587312c53731907a27c7bfcb61c6fa9275853d199d76123149f4c2e2e75755bd9ca27466a5ce7f
|
7
|
+
data.tar.gz: fda06e7c5cf9d1153a65cece6425129a09ee491c481e19e4ee8d0ab23527e6a2475bb237e861692f7d35c32c63b300c7d988e87828c7e8c5da6a5c7eb09f61d6
|
data/.gitignore
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) 2015 defektive
|
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
|
+
# Octobot::SlackAgent
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/octobot/slack_agent`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'octobot-slack_agent'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install octobot-slack_agent
|
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 `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` to 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
|
+
1. Fork it ( https://github.com/[my-github-username]/octobot-slack_agent/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "octobot/slack_agent"
|
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
|
+
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module Octobot
|
4
|
+
module SlackAgent
|
5
|
+
class DeployNotifier < Notifier
|
6
|
+
attr_accessor :gitblit_url, :gerrit_url
|
7
|
+
|
8
|
+
def initialize(gitblit_url, gerrit_url, webhook_url, username='octobot', icon_emoji=nil)
|
9
|
+
@gitblit_url = gitblit_url
|
10
|
+
@gerrit_url = gerrit_url
|
11
|
+
super webhook_url, username, icon_emoji
|
12
|
+
end
|
13
|
+
|
14
|
+
def deployed(app, environment, git_hash, commit_msg)
|
15
|
+
title, message = process_message commit_msg
|
16
|
+
|
17
|
+
send_attachments [
|
18
|
+
attachment({
|
19
|
+
pretext: "#{app} #{environment} has been updated to #{git_hash}",
|
20
|
+
title: title,
|
21
|
+
title_link: gitblit_link(app, git_hash),
|
22
|
+
text: message
|
23
|
+
}, 'good')
|
24
|
+
]
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def gitblit_link(app, git_hash)
|
29
|
+
"#{gitblit_url}/commit/?r=#{app}&h=#{git_hash}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def process_message(commit_msg)
|
33
|
+
message_ar = commit_msg.split("\n")
|
34
|
+
title = message_ar.shift
|
35
|
+
|
36
|
+
message = message_ar.join("\n")
|
37
|
+
message.gsub!(/Change-Id: (I[a-f0-9]+)/, "Change-id: <#{gerrit_url}/#/q/\\1|\\1>")
|
38
|
+
|
39
|
+
[title, message]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module Octobot
|
4
|
+
module SlackAgent
|
5
|
+
|
6
|
+
GOOD = 'good'
|
7
|
+
WARNING = 'warning'
|
8
|
+
DANGER = 'danger'
|
9
|
+
|
10
|
+
class Notifier
|
11
|
+
|
12
|
+
attr_accessor :webhook_url, :username, :icon_emoji
|
13
|
+
|
14
|
+
def initialize(webhook_url, username='octobot', icon_emoji=nil)
|
15
|
+
@webhook_url = webhook_url
|
16
|
+
@username = username
|
17
|
+
@icon_emoji = icon_emoji
|
18
|
+
end
|
19
|
+
|
20
|
+
def success(params)
|
21
|
+
send_attachments [ attachment(params, GOOD) ]
|
22
|
+
end
|
23
|
+
|
24
|
+
def warn(params)
|
25
|
+
send_attachments [ attachment(params, WARNING) ]
|
26
|
+
end
|
27
|
+
|
28
|
+
def error(params)
|
29
|
+
send_attachments [ attachment(params, DANGER) ]
|
30
|
+
end
|
31
|
+
|
32
|
+
def send_attachments(attachments)
|
33
|
+
send attachments: attachments
|
34
|
+
end
|
35
|
+
|
36
|
+
def send(params)
|
37
|
+
send_request(base_params.merge(params))
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def send_request(data)
|
42
|
+
RestClient.post webhook_url, data.to_json
|
43
|
+
end
|
44
|
+
|
45
|
+
def base_params
|
46
|
+
bp = {}
|
47
|
+
bp[:username] = username if username
|
48
|
+
bp[:octobot] = username if icon_emoji
|
49
|
+
|
50
|
+
bp
|
51
|
+
end
|
52
|
+
|
53
|
+
def attachment(params, color=nil)
|
54
|
+
base_attachment = {
|
55
|
+
fallback: "#{params[:title]}\n\n#{params[:text]}",
|
56
|
+
}
|
57
|
+
|
58
|
+
base_attachment[:color] = color if color
|
59
|
+
|
60
|
+
base_attachment.merge(params)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'octobot/slack_agent/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "octobot-slack_agent"
|
8
|
+
spec.version = Octobot::SlackAgent::VERSION
|
9
|
+
spec.authors = ["defektive"]
|
10
|
+
spec.email = ["sirbradleyd@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A simple gem to send messages to a slack channel using webhook URLs}
|
13
|
+
spec.homepage = "https://github.com/defektive/octobot-slack_agent"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rest-client", "~> 1.8"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: octobot-slack_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- defektive
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- sirbradleyd@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/octobot/slack_agent.rb
|
71
|
+
- lib/octobot/slack_agent/deploy_notifier.rb
|
72
|
+
- lib/octobot/slack_agent/notifier.rb
|
73
|
+
- lib/octobot/slack_agent/version.rb
|
74
|
+
- octobot-slack_agent.gemspec
|
75
|
+
homepage: https://github.com/defektive/octobot-slack_agent
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.0.14
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: A simple gem to send messages to a slack channel using webhook URLs
|
99
|
+
test_files: []
|