mina-flowdock 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46b182d653465271aaf7e6ab1c5ab4dd61146d8a
4
+ data.tar.gz: b6c0583f4580f765df222dcca135378ebf6b0f46
5
+ SHA512:
6
+ metadata.gz: 8de3c513cd91b36876c75a18e5a73d3d8f0b3f25e1df15d0cc665f59311adc67e2d6214bb98dd776f02fb8361c9a7f2b44608ce8bbd7ae27747778bc7383dba0
7
+ data.tar.gz: 4edd364f8605efa8255914d6ce979e8d56836ce4bbf479e7818e9631c42e86f8c7a48266d89d0035568ce4d73b51af1e26890deff210fd8ea139cde011c63302
@@ -0,0 +1,3 @@
1
+ -
2
+ ChangeLog.md
3
+ LICENSE.txt
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ doc/
3
+ pkg/
4
+ vendor/cache/*.gem
@@ -0,0 +1 @@
1
+ --markup markdown --title "mina-flowdock Documentation" --protected
@@ -0,0 +1,8 @@
1
+ ### 0.2 (unreleased)
2
+
3
+ ### 0.1 / 2013-12-02
4
+
5
+ * Initial release:
6
+ * Add plugin, task, and mina/flowdock.rb
7
+ * Add README
8
+ * Add initial test setup
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "kramdown"
7
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Don Morrison
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,190 @@
1
+ # mina-flowdock
2
+
3
+ * [Homepage](https://github.com/elskwid/mina-flowdock#readme)
4
+ * [Issues](https://github.com/elskwid/mina-flowdock/issues)
5
+ * [Documentation](http://rubydoc.info/gems/mina-flowdock/frames)
6
+ * [Email](mailto:don at elskwid.net)
7
+
8
+ ## Description
9
+
10
+ Mina plugin to add [Flowdock](http://flowdock.com) deployment notifications.
11
+
12
+ `mina-flowdock` pushes deployment notifications to Flowdock team inboxes using
13
+ the Flowdock [API](https://github.com/flowdock/flowdock-api/).
14
+
15
+ ## Features
16
+
17
+ ### Notify multiple flows
18
+
19
+ Add multiple Flowdock API tokens to send notifications to multiple flows.
20
+
21
+ ### Default tags
22
+
23
+ Notifications are tagged with `#deploy` and the stage (deploy env). More
24
+ tags can be added. See (Settings).
25
+
26
+ ### Supports notifications for commit/branch
27
+
28
+ The Mina git module supports deployment using a specific commit or branch.
29
+ The option used is detected and included in the notifications.
30
+
31
+ ### Verifies the commit/branch
32
+
33
+ The bare checkout on the server is used to find the sha for the commit/branch
34
+ being deployed which is then returned in the notification. An error is raised
35
+ if it can't be retrieved.
36
+
37
+ ### Respects Mina simulate option
38
+
39
+ The notifications are not sent if mina is run with the `--simulate` option.
40
+
41
+ ### Uses git for user name and email
42
+
43
+ The `grit` library is used to access the git config for the local repository
44
+ and send the notification from the user configured there.
45
+
46
+ ### Configurable settings
47
+
48
+ Most of the settings are easily overridden. See (Settings).
49
+
50
+ ## Comparison to flowdock/capistrano
51
+
52
+ There are some differences between the Mina notifications and those sent
53
+ from [flowdock/capistrano](https://github.com/flowdock/flowdock-api/blob/master/lib/flowdock/capistrano.rb)
54
+ because of the assumptions made by each deployment library.
55
+
56
+ The capistrano notifications will list deployed commits when possible. Cap
57
+ has access to a full git checkout and with that the currently deployed branch.
58
+ Mina uses a bare repository and so the branch or commit for the current
59
+ deploy is not known. `mina-flowdock` just sends a simple notification that a
60
+ branch or commit has been deployed to a specific stage.
61
+
62
+ ## Usage
63
+
64
+ ```ruby
65
+ # In your deploy tasks...
66
+
67
+ require 'mina/flowdock'
68
+
69
+ # required settings
70
+ set :flowdock_project_name, "my_project"
71
+ set :flowdock_api_token, ["firstflowapitoken", "secondflowapitoken"]
72
+ set :flowdock_deploy_env, stage
73
+
74
+ # optional settings
75
+ set :flowdock_deploy_tags, ["my_tag1", "my_tag2]
76
+ ```
77
+
78
+ Then run `mina deploy ...` as usual. Requiring `mina/flowdock` extends the
79
+ file with some helper methods, includes the Flowdock notification task
80
+ (`flowdock:notify`), and uses `mina-hooks` to queue the notifications to
81
+ run after the deployment.
82
+
83
+ ## Settings
84
+
85
+ ### Required
86
+
87
+ The `flowdock:notify` task will exit with an error if any of the required
88
+ settings are missing.
89
+
90
+ #### `flowdock_project_name`
91
+
92
+ The name of the project being deployed. Used in the subject of the notfications.
93
+
94
+ **Default:** not set
95
+
96
+ #### `flowdock_api_token`
97
+
98
+ List of one or more api tokens for the flows that should receive notifications.
99
+ Used to authorize inbox notifications.
100
+
101
+ **Default:** not set
102
+
103
+ #### `flowdock_deploy_env`
104
+
105
+ Deployment environment for this deploy. (i.e. production, staging, qa). Used
106
+ in the default notification message.
107
+
108
+ **Default:** not set
109
+
110
+ ### Other / Optional
111
+
112
+ These settings aren't required to be set in your deployment scripts or may
113
+ be otherwise configurable.
114
+
115
+ #### `flowdock_deploy_tags`
116
+
117
+ List of tags used to tag the team inbox notification. Always includes both
118
+ the `deploy` and deploy env name as tags.
119
+
120
+ **Default:** ["deploy", flowdock_deploy_env]
121
+
122
+ #### `flowdock_source`
123
+
124
+ Source for Flowdock notifications.
125
+
126
+ **Default:** "Mina deployment"
127
+
128
+ #### `flowdock_from_name`
129
+
130
+ Name of the person sending the notifications. Used as the user link in
131
+ notifications.
132
+
133
+ **Default:** "user.name" retrieved from git config for the local repository.
134
+
135
+ #### `flowdock_from_email`
136
+
137
+ Email of the person sending the notifications. Used as the user link in
138
+ notificiations.
139
+
140
+ **Default:** "user.email" retrieved from git config for the local repository.
141
+
142
+ #### `flowdock_message_subject`
143
+
144
+ ERB string used as the notification subject.
145
+
146
+ **Default:** "<%= flowdock_project_name %> deployed to #<%= flowdock_deploy_env %>"
147
+
148
+ Example: MyProject deployed to staging.
149
+
150
+ #### `flowdock_message`
151
+
152
+ ERB string used as the notification body.
153
+
154
+ **Default:** "<%= flowdock_deploy_type %> <%= flowdock_deploy_ref %> (<%= flowdock_deploy_sha %>) was deployed to <%= flowdock_deploy_env %>."
155
+
156
+ Example: Branch feature-branch (git-sha) was deployed to staging.
157
+
158
+ ### Internal
159
+
160
+ These can't be overridden. Well, not easily overridden.
161
+
162
+ #### `flowdock_deploy_type`
163
+
164
+ One of "Branch" or "Commit" depending on the option passed to mina.
165
+
166
+ #### `flowdock_deploy_ref`
167
+
168
+ Either the branch name or the commit sha passed ot mina.
169
+
170
+ #### `flowdock_deploy_sha`
171
+
172
+ The git sha retrieved from the server after deployment. Uses the
173
+ `flowdock_deploy_ref` to get the sha and return it for use in notifications.
174
+
175
+ ## Requirements
176
+
177
+ * [flowdock](https://github.com/flowdock/flowdock-api/)
178
+ * [grit](https://github.com/mojombo/grit)
179
+ * [mina](https://github.com/nadarei/mina)
180
+ * [mina-hooks](https://github.com/elskwid/mina-hooks)
181
+
182
+ ## Install
183
+
184
+ $ gem install mina-flowdock
185
+
186
+ ## Copyright
187
+
188
+ Copyright (c) 2013 Don Morrison
189
+
190
+ See {file:LICENSE.txt} for details.
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ require "rubygems"
4
+
5
+ begin
6
+ require "bundler"
7
+ rescue LoadError => e
8
+ warn e.message
9
+ warn "Run `gem install bundler` to install Bundler."
10
+ exit -1
11
+ end
12
+
13
+ begin
14
+ Bundler.setup(:development)
15
+ rescue Bundler::BundlerError => e
16
+ warn e.message
17
+ warn "Run `bundle install` to install missing gems."
18
+ exit e.status_code
19
+ end
20
+
21
+ require "rake"
22
+
23
+ require "rubygems/tasks"
24
+ Gem::Tasks.new
25
+
26
+ require "rake/testtask"
27
+
28
+ Rake::TestTask.new do |test|
29
+ test.libs << "test"
30
+ test.pattern = "test/**/*_test.rb"
31
+ test.verbose = true
32
+ end
33
+
34
+ require "yard"
35
+ YARD::Rake::YardocTask.new
36
+ task :doc => :yard
@@ -0,0 +1,9 @@
1
+ require "mina/flowdock/version"
2
+ require "mina/flowdock/plugin"
3
+
4
+ extend Mina::Flowdock::Plugin
5
+
6
+ require "mina/flowdock/notify" # task
7
+
8
+ # Hook our task in after mina is done running
9
+ after_mina :"flowdock:notify"
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+
3
+ set_default :flowdock_deploy_tags, []
4
+ set_default :flowdock_source, "Mina deployment"
5
+ set_default :flowdock_from_name, git_config["user.name"]
6
+ set_default :flowdock_from_address, git_config["user.email"]
7
+
8
+
9
+ set_default :flowdock_message_subject,
10
+ "<%= flowdock_project_name %> deployed to #<%= flowdock_deploy_env %>"
11
+
12
+ set_default :flowdock_message,
13
+ "<%= flowdock_deploy_type %> <%= flowdock_deploy_ref %> (<%= flowdock_deploy_sha %>) was deployed to <%= flowdock_deploy_env %>."
14
+
15
+ set :flowdock_deploy_tags,
16
+ ["deploy", "#{flowdock_deploy_env}"] + flowdock_deploy_tags
17
+
18
+ namespace :flowdock do
19
+ task :notify do
20
+
21
+ %w(
22
+ flowdock_project_name
23
+ flowdock_api_token
24
+ flowdock_deploy_env
25
+ ).each do |required|
26
+ unless self.send("#{required}?")
27
+ error "Mina Flowdock notifications require '#{required}' to be set."
28
+ exit
29
+ end
30
+ end
31
+
32
+ # mina git module uses commit if given
33
+ type, ref = if commit? && !commit.nil?
34
+ ["Commit", commit]
35
+ else
36
+ ["Branch", branch]
37
+ end
38
+
39
+ sha = capture("cd #{deploy_to}/scm && git --no-pager show -s -v --format=%H #{ref}").strip
40
+
41
+ unless sha
42
+ error "Mina Flowdock notifications couldn't find the configured #{type} [#{ref}] on the server."
43
+ exit
44
+ end
45
+
46
+ set :flowdock_deploy_type, type
47
+ set :flowdock_deploy_ref, ref
48
+ set :flowdock_deploy_sha, sha
49
+
50
+ flows = Array(flowdock_api_token).map do |token|
51
+ Flowdock::Flow.new(
52
+ api_token: token,
53
+ source: flowdock_source,
54
+ project: flowdock_project_name,
55
+ from: {
56
+ name: flowdock_from_name,
57
+ address: flowdock_from_address
58
+ }
59
+ )
60
+ end
61
+
62
+ print_local_status "Notify configured Flowdock flows"
63
+
64
+ flows.each do |flow|
65
+ print_notification_debug(flow) if verbose_mode?
66
+ next if simulate_mode?
67
+
68
+ flow.push_to_team_inbox(
69
+ format: "html",
70
+ subject: flowdock_message_subject,
71
+ content: flowdock_message,
72
+ tags: flowdock_deploy_tags
73
+ )
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,55 @@
1
+ %w(flowdock grit mina/hooks).each do |lib|
2
+ begin
3
+ require lib
4
+ rescue LoadError => e
5
+ warn e.message
6
+ warn "Mina Flowdock notifications require '#{lib}' to be installed."
7
+ exit -1
8
+ end
9
+ end
10
+
11
+ module Mina
12
+ module Flowdock
13
+ module Plugin
14
+ def flowdock_message_subject
15
+ erb_string(settings.send :flowdock_message_subject)
16
+ end
17
+
18
+ def flowdock_message
19
+ erb_string(settings.send :flowdock_message)
20
+ end
21
+
22
+ def git_config
23
+ Grit::Config.new(Grit::Repo.new("."))
24
+ end
25
+
26
+ def erb_string(string, b = binding)
27
+ require "erb"
28
+ erb = ERB.new(string)
29
+ erb.result b
30
+ end
31
+
32
+ def print_notification_debug(flow)
33
+ flow = "flow: #{flow.api_token} [#{flow.project}]"
34
+ subj = "subject: #{flowdock_message_subject}"
35
+ msg = "message: #{flowdock_message}"
36
+
37
+ [flow, subj, msg].each do |debug|
38
+ print_local_debug(debug)
39
+ end
40
+ end
41
+
42
+ def print_local_debug(msg)
43
+ puts " #{color(">>", 32)} #{color(msg, 32)}"
44
+ end
45
+
46
+ unless defined?(:print_local_status)
47
+ # Prints a status message. (`<-----`)
48
+ def print_local_status(msg)
49
+ puts "" if verbose_mode?
50
+ puts "#{color('<-----', 32)} #{msg}"
51
+ end
52
+ end
53
+ end # Plugin
54
+ end # Flowdock
55
+ end # Mina
@@ -0,0 +1,6 @@
1
+ module Mina
2
+ module Flowdock
3
+ # mina-flowdock version
4
+ VERSION = "0.1"
5
+ end
6
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path("../lib/mina/flowdock/version", __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "mina-flowdock"
7
+ gem.version = Mina::Flowdock::VERSION
8
+ gem.summary = %q{Mina plugin to add Flowdock deployment notifications.}
9
+ gem.description = %q{Mina plugin to add Flowdock deployment notifications.}
10
+ gem.license = "MIT"
11
+ gem.authors = ["Don Morrison"]
12
+ gem.email = "don@elskwid.net"
13
+ gem.homepage = "https://github.com/elskwid/mina-flowdock#readme"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "flowdock", "~> 0.3"
21
+ gem.add_dependency "grit", "~> 2.5"
22
+ gem.add_dependency "mina-hooks", "~> 0.2"
23
+
24
+ gem.add_development_dependency "bundler", "~> 1.2"
25
+ gem.add_development_dependency "minitest", "~> 5.0"
26
+ gem.add_development_dependency "rake", "~> 10.0"
27
+ gem.add_development_dependency "rubygems-tasks", "~> 0.2"
28
+ gem.add_development_dependency "yard", "~> 0.8"
29
+ end
@@ -0,0 +1,10 @@
1
+ require "helper"
2
+ require "mina/flowdock/version"
3
+
4
+ describe Mina::Flowdock do
5
+ it "has a version constant" do
6
+ version = Mina::Flowdock.const_get("VERSION")
7
+
8
+ refute_empty version
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ require "rubygems"
2
+
3
+ begin
4
+ require "bundler"
5
+ rescue LoadError => e
6
+ STDERR.puts e.message
7
+ STDERR.puts "Run `gem install bundler` to install Bundler."
8
+ exit e.status_code
9
+ end
10
+
11
+ begin
12
+ Bundler.setup(:default, :development, :test)
13
+ rescue Bundler::BundlerError => e
14
+ STDERR.puts e.message
15
+ STDERR.puts "Run `bundle install` to install missing gems."
16
+ exit e.status_code
17
+ end
18
+
19
+ require "minitest/autorun"
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mina-flowdock
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Don Morrison
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: flowdock
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: grit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mina-hooks
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubygems-tasks
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ description: Mina plugin to add Flowdock deployment notifications.
126
+ email: don@elskwid.net
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - .document
132
+ - .gitignore
133
+ - .yardopts
134
+ - ChangeLog.md
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - lib/mina/flowdock.rb
140
+ - lib/mina/flowdock/notify.rb
141
+ - lib/mina/flowdock/plugin.rb
142
+ - lib/mina/flowdock/version.rb
143
+ - mina-flowdock.gemspec
144
+ - test/flowdock_test.rb
145
+ - test/helper.rb
146
+ homepage: https://github.com/elskwid/mina-flowdock#readme
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.0.3
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Mina plugin to add Flowdock deployment notifications.
170
+ test_files:
171
+ - test/flowdock_test.rb
172
+ - test/helper.rb