capistrano-teams 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 109610593702b3c23d33d6a4deac385fbfe1f0fd541b262c7446a584b061e784
4
+ data.tar.gz: 61948c2f8f58d0987eb97127014691c57b8397a8e15974b500c57b520f13a8cd
5
+ SHA512:
6
+ metadata.gz: ab50b9a83b8d2fa6ba44e11eb8b88288f16d4d3d7cd1e03704df6ca015e16d19803b1e6382a1e0050c6467cb0d6098b2cf6aa1d36dc22b24e7233455af48291b
7
+ data.tar.gz: 4730104e2d1164d9ffd594d3a1893ad27da180625fc2cc9f6487866dc2876f775a089a412ec5f6ef5779ddf24210429092c9303315eaeffddaef17e1e97f0019
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,42 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Publish
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby 2.6
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6.x
20
+
21
+ - name: Publish to GPR
22
+ run: |
23
+ mkdir -p $HOME/.gem
24
+ touch $HOME/.gem/credentials
25
+ chmod 0600 $HOME/.gem/credentials
26
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
27
+ gem build *.gemspec
28
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
29
+ env:
30
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
31
+ OWNER: ${{ github.repository_owner }}
32
+
33
+ - name: Publish to RubyGems
34
+ run: |
35
+ mkdir -p $HOME/.gem
36
+ touch $HOME/.gem/credentials
37
+ chmod 0600 $HOME/.gem/credentials
38
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
39
+ gem build *.gemspec
40
+ gem push *.gem
41
+ env:
42
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/.gitignore ADDED
@@ -0,0 +1,28 @@
1
+ *.gem
2
+ *.rbc
3
+ .config
4
+ Gemfile.lock
5
+ InstalledFiles
6
+ lib/bundler/man
7
+ rdoc
8
+ spec/reports
9
+ test/tmp
10
+ test/version_tmp
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+
17
+ /.bundle/
18
+ /.yardoc
19
+ /_yardoc/
20
+ /coverage/
21
+ /doc/
22
+ /pkg/
23
+ /spec/reports/
24
+ /tmp/
25
+ /.idea/
26
+
27
+ # rspec failure tracking
28
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ # This is the configuration used to check the capistrano-graphite source code.
2
+ inherit_from: .rubocop_todo.yml
3
+
4
+ Style/Encoding:
5
+ Enabled: true
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,53 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-08-03 09:21:59 UTC using RuboCop version 0.88.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
11
+ Metrics/MethodLength:
12
+ Max: 20
13
+
14
+ Metrics/LineLength:
15
+ Max: 120
16
+
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - '*.gemspec'
20
+ - '**/**/**/*.rake'
21
+
22
+ # Offense count: 1
23
+ # Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
24
+ # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
25
+ Naming/FileName:
26
+ Exclude:
27
+ - 'lib/capistrano-teams.rb'
28
+
29
+ # Offense count: 12
30
+ # Cop supports --auto-correct.
31
+ # Configuration parameters: EnforcedStyle.
32
+ # SupportedStyles: always, always_true, never
33
+ Style/FrozenStringLiteralComment:
34
+ Exclude:
35
+ - 'Gemfile'
36
+ - 'Rakefile'
37
+ - 'bin/console'
38
+ - 'capistrano-teams.gemspec'
39
+ - 'lib/capistrano/tasks/teams.rake'
40
+ - 'lib/capistrano/teams.rb'
41
+ - 'lib/capistrano/teams/defaults.rb'
42
+ - 'lib/capistrano/teams/version.rb'
43
+ - 'lib/capistrano/teams/web_hook.rb'
44
+ - 'spec/capistrano/teams/web_hook_spec.rb'
45
+ - 'spec/capistrano/teams_spec.rb'
46
+ - 'spec/spec_helper.rb'
47
+
48
+ # Offense count: 1
49
+ # Cop supports --auto-correct.
50
+ # Configuration parameters: AllowAsExpressionSeparator.
51
+ Style/Semicolon:
52
+ Exclude:
53
+ - 'lib/capistrano/teams/web_hook.rb'
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.0.0
7
+ - 2.1.0
8
+ - 2.2.0
9
+ - 2.3.0
10
+ - 2.4.0
11
+ - 2.5.0
12
+ - 2.6.0
13
+ - 2.7.0
14
+ before_install: gem install bundler -v 1.3
15
+
16
+ script:
17
+ - bundle exec rspec
18
+ - bundle exec rubocop
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.0.0] - 2020-08-09
11
+
12
+ ### Added
13
+
14
+ - Plugin logic
15
+
16
+ [unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD
17
+ [1.0.0]: https://github.com/danieltoader/capistrano-teams/releases/tag/v1.0.0
data/CODEOWNERS ADDED
@@ -0,0 +1,11 @@
1
+ ##########################################################
2
+ #
3
+ # List of approvers for danieltoader/capistrano-teams
4
+ #
5
+ ##########################################################
6
+ #
7
+ # Learn about CODEOWNERS file format:
8
+ # https://help.github.com/en/articles/about-code-owners
9
+ #
10
+
11
+ * @danieltoader
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at daniel.toader@emag.ro. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-teams.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Daniel Toader
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,256 @@
1
+ # Capistrano::Teams
2
+
3
+ [![Gem Downloads](http://img.shields.io/gem/dt/capistrano-teams.svg)](https://rubygems.org/gems/capistrano-teams)
4
+ [![GitHub](https://img.shields.io/github/license/danieltoader/capistrano-teams?color=113399)](https://github.com/danieltoader/capistrano-teams/blob/master/LICENSE.md)
5
+ [![Changelog](https://img.shields.io/badge/capistrano-capistran--teams-E05735)](https://github.com/danieltoader/capistrano-teams/blob/master/CHANGELOG.md)
6
+ [![Gem Version](http://img.shields.io/gem/v/capistrano-teams.svg)](https://rubygems.org/gems/capistrano-teams)
7
+ [![Build Status](http://img.shields.io/travis/danieltoader/capistrano-teams.svg)](http://travis-ci.org/danieltoader/capistrano-teams)
8
+ [![Build status](https://ci.appveyor.com/api/projects/status/8e9dteu7ibxsb4ou?svg=true)](https://ci.appveyor.com/project/danieltoader/capistrano-teams)
9
+ [![Coverage Status](https://img.shields.io/coveralls/danieltoader/capistrano-teams.svg)](https://coveralls.io/r/danieltoader/capistrano-teams?branch=master)
10
+
11
+ This gem extends Capistrano functionality to push notices to Microsoft Teams via an incoming webhook.
12
+
13
+ With just the webhook url configured and the default values, the plugin registers hooks for the base
14
+ deploy tasks (start, revert, finish, rollback and failed) and pushes simple notifications to the room
15
+ where the used webhook was created.
16
+
17
+ This project is meant to be highly customisable, you can find all the details below.
18
+
19
+ This gem works with Capistrano v3.x+. Please check the capistrano gem version you're using before
20
+ installing this gem:
21
+ ```shell script
22
+ bundle show | grep capistrano
23
+ ```
24
+ If you are new to Capistrano, check the [Capistrano 3 documentation](http://capistranorb.com/).
25
+
26
+ ## Installation
27
+ Add this line to your application's Gemfile:
28
+ ```ruby
29
+ gem 'capistrano', '~> 3.0.0'
30
+ gem 'capistrano-teams'
31
+ ```
32
+
33
+ And then execute:
34
+ ```shell script
35
+ bundle install
36
+ ```
37
+
38
+ Or install it manually:
39
+ ```shell script
40
+ gem install capistrano-teams
41
+ ```
42
+
43
+ ## Usage
44
+ In Microsoft Teams, add an "Incoming Webhook" connector in the channel where you want to
45
+ see deployment notices as described [here](https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook).
46
+ Copy the generated Webhook URL since you will need to add it in one of the detailed steps below.
47
+
48
+ ### Setup your application
49
+ Add the following line to your `Capfile`.
50
+ ```ruby
51
+ require "capistrano/teams"
52
+ ```
53
+
54
+ In order to send notifications you must set the following options in your `deploy.rb` or
55
+ stage file (staging.rb, production.rb, etc). The only required option is the `:teams_webhook_url` setting.
56
+
57
+ ```ruby
58
+ set :teams_webhook_url, "https://outlook.office.com/webhook/{groupId}@{tenantId}/IncomingWebhook/{connectorId}/{webHookId}"
59
+
60
+ set :teams_suppress_events, false
61
+ set :teams_content_mode, Message::TYPE_CARD
62
+ set :teams_http_options, verify_mode: OpenSSL::SSL::VERIFY_PEER
63
+ ```
64
+
65
+ To disable sending notifications for a certain stage, or to change the team/channel/room the message is
66
+ posted to, you need to edit the stage file and set the following:
67
+ ```ruby
68
+ set :teams_suppress_events, true # Default value: false
69
+ ```
70
+
71
+ #### Automated notifications
72
+ After setting the minimum options needed for your application, the plugin will push notifications to
73
+ the teams room where the webhook was created for all the deploy events. Listed below you can see the
74
+ hooks where the plugin injects itself:
75
+ ```ruby
76
+ namespace :deploy do
77
+ before 'deploy:starting', 'teams:deploy:starting'
78
+ before 'deploy:reverting', 'teams:deploy:reverting'
79
+ after 'deploy:finishing', 'teams:deploy:finishing'
80
+ after 'deploy:finishing_rollback', 'teams:deploy:finishing_rollback'
81
+ after 'deploy:failed', 'teams:deploy:failed'
82
+ end
83
+ ```
84
+
85
+ #### Custom notifications
86
+ If you want to send a custom notification you can invoke or execute the rake task `teams:notify` as shown below
87
+
88
+ ```ruby
89
+ # with invoke
90
+ Rake::Task["teams:notify"].invoke(
91
+ "{status}",
92
+ [
93
+ {"name"=>"{first_fact_name}", "value"=>"{first_fact_value}"},
94
+ {"name"=>"{second_fact_name}", "value"=>"{second_fact_value}"},
95
+ # ...
96
+ ],
97
+ "{theme_color}"
98
+ )
99
+ # with execute
100
+ Rake::Task["teams:notify"].execute(
101
+ Rake::TaskArguments.new(
102
+ [:status, :facts, :theme_color],
103
+ [
104
+ "{status}",
105
+ [
106
+ {"name"=>"{first_fact_name}", "value"=>"{first_fact_value}"},
107
+ {"name"=>"{second_fact_name}", "value"=>"{second_fact_value}"},
108
+ # ...
109
+ ],
110
+ "{theme_color}"
111
+ ]
112
+ )
113
+ )
114
+ ```
115
+
116
+ #### Remove default hooks for an action
117
+ To remove a default hook from this plugin you can use the following line, it can be used
118
+ anywhere in the desired `deploy.rb` or stage file
119
+ ```ruby
120
+ Rake::Task['deploy:starting'].prerequisites.delete('teams:deploy:starting')
121
+ ```
122
+
123
+ #### Custom Hook for rake task with arguments
124
+ If you want to create a custom hook for tasks with arguments you can use the snippet below
125
+ (with both invoke and execute shown above):
126
+ ```ruby
127
+ before 'deploy:starting', :only => :deploy do
128
+ Rake::Task["teams:notify"].invoke(
129
+ "{status}",
130
+ [
131
+ {"name"=>"{first_fact_name}", "value"=>"{first_fact_value}"},
132
+ {"name"=>"{second_fact_name}", "value"=>"{second_fact_value}"},
133
+ # ...
134
+ ],
135
+ "{theme_color}"
136
+ )
137
+ end
138
+ ```
139
+
140
+
141
+ #### Message Types
142
+ You can use this plugin with two message types: `Message::TYPE_BASIC` or `Message::TYPE_CARD`
143
+
144
+ ##### Basic message type (default)
145
+ ![Basic message type](docs/img/message_type_basic.png)
146
+ The basic message type is the simple way to send notifications from capistrano to Teams.
147
+
148
+ ```ruby
149
+ set :teams_basic_message_title, 'Deployment Notice » %<application>s'
150
+ set :teams_basic_message_text, '<h1>Deploy for %<application>s' \
151
+ ' on <strong>%<stage>s</strong> by ' \
152
+ '<strong>%<user>s</strong></h1> ' \
153
+ "Branch: %<branch>s \n\n" \
154
+ 'Status: %<status>s'
155
+ ```
156
+
157
+ ##### Card message type
158
+ ![Card message type](docs/img/message_type_card.png)
159
+ The card message type has a few more options and can be configured more and can list several facts (name => value)
160
+
161
+
162
+ ```ruby
163
+ set :teams_card_message_title, 'Deployment Notice » %<application>s'
164
+ set :teams_card_message_sub_title, 'On %<stage>s'
165
+ set :teams_card_message_image, ''
166
+ set :teams_card_message_summary, 'Deploy for %<application>s on %<stage>s by %<user>s'
167
+ set :teams_card_message_markdown, true
168
+ ```
169
+ #### Configurable options
170
+
171
+ ##### Available options and default values
172
+ ```ruby
173
+ set :teams_webhook_url, "https://outlook.office.com/webhook/{groupId}@{tenantId}/IncomingWebhook/{connectorId}/{webHookId}"
174
+
175
+ set :teams_suppress_events, false # Default value: false
176
+ set :teams_content_mode, Message::TYPE_BASIC # Message::TYPE_BASIC or Message::TYPE_CARD
177
+ set :teams_http_options, verify_mode: OpenSSL::SSL::VERIFY_PEER # Default verify mode
178
+
179
+ # Theme colors
180
+ set :teams_starting_color, '0000FF' # Default color: blue
181
+ set :teams_reverting_color, 'FFFF00' # Default color: yellow
182
+ set :teams_finishing_color, '00FF00' # Default color: green
183
+ set :teams_rollback_color, 'FFFF00' # Default color: yellow
184
+ set :teams_failed_color, 'FF0000' # Default color: red
185
+
186
+ # Statuses
187
+ set :teams_starting_status, 'STARTING'
188
+ set :teams_reverting_status, 'REVERTING'
189
+ set :teams_finishing_status, 'FINISHED'
190
+ set :teams_rollback_status, 'ROLLBACK'
191
+ set :teams_failed_status, 'FAILED'
192
+
193
+ # Used for Message::TYPE_BASIC
194
+ set :teams_basic_message_title, 'Deployment Notice » %<application>s'
195
+ set :teams_basic_message_text, '<h1>Deploy for %<application>s' \
196
+ ' on <strong>%<stage>s</strong> by ' \
197
+ '<strong>%<user>s</strong></h1> ' \
198
+ "Branch: %<branch>s \n\n" \
199
+ 'Status: %<status>s'
200
+
201
+ # Used for Message::TYPE_CARD
202
+ set :teams_card_message_title, 'Deployment Notice » %<application>s'
203
+ set :teams_card_message_sub_title, 'On %<stage>s'
204
+ set :teams_card_message_image, ''
205
+ set :teams_card_message_summary, 'Deploy for %<application>s on %<stage>s by %<user>s'
206
+ set :teams_card_message_markdown, false # Enable markdown inside message
207
+
208
+ # Default values
209
+ set :teams_default_color, '333333' # Default color: grey
210
+ set :teams_default_status, 'UNKNOWN'
211
+ set :teams_default_application, 'N/A'
212
+ set :teams_default_branch, 'N/A'
213
+ set :teams_default_stage, 'N/A'
214
+ set :teams_default_user, 'UNKNOWN'
215
+ ```
216
+
217
+ ## Development
218
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the
219
+ tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
220
+
221
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version,
222
+ update the version number in `version.rb`, and then run `bundle exec rake release`, which will create
223
+ a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
224
+
225
+ ## Deployment
226
+ Run deploy
227
+ ```shell script
228
+ cap <stage_name> deploy
229
+ ```
230
+
231
+ You should then be able to proceed as you would usually, you may want to familiarise yourself
232
+ with the truncated list of tasks, you can get a full list with:
233
+ ```shell script
234
+ cap -T
235
+ ```
236
+
237
+ ## Contributing
238
+ 1. Fork it
239
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
240
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
241
+ 4. Push to the branch (`git push origin my-new-feature`)
242
+ 5. Create new Pull Request
243
+
244
+ If something is not working for you, or you find a bug, please report it.
245
+ Bug reports and pull requests are welcome on GitHub at https://github.com/danieltoader/capistrano-teams.
246
+
247
+ ## License
248
+ The gem is available as open source under the terms of the [MIT License](https://github.com/danieltoader/capistrano-teams/blob/master/LICENSE.md).
249
+
250
+ ## Code of Conduct
251
+ Everyone interacting in the Capistrano::Teams project's codebase, issue trackers, chat rooms and mailing
252
+ lists is expected to follow the [code of conduct](https://github.com/danieltoader/capistrano-teams/blob/master/CODE_OF_CONDUCT.md).
253
+
254
+ ## Todo's
255
+ [] Add tests
256
+ [] Add functionality for sending "potentialAction" key for the card message type
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/appveyor.yml ADDED
@@ -0,0 +1,21 @@
1
+ version: '{build}'
2
+
3
+ skip_tags: true
4
+
5
+ skip_branch_with_pr: true
6
+
7
+ environment:
8
+ matrix:
9
+ - ruby_version: "23"
10
+ - ruby_version: "23-x64"
11
+
12
+ install:
13
+ - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
14
+ - gem uninstall bundler --all --executables
15
+ - gem install bundler --no-document -v ">=1.16"
16
+ - bundle install --retry=3
17
+
18
+ test_script:
19
+ - bundle exec rake
20
+
21
+ build: off
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'capistrano/teams'
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ require_relative 'lib/capistrano/teams/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'capistrano-teams'
5
+ spec.version = Capistrano::Teams::VERSION
6
+ spec.authors = ['Daniel Toader']
7
+ spec.email = ['developer@danieltoader.com']
8
+
9
+ spec.summary = 'Microsoft Teams integration for Capistrano 3.x'
10
+ # spec.description = %q{Microsoft Teams integration for Capistrano 3.x}
11
+ spec.homepage = 'https://rubygems.org/gems/capistrano-teams'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.0.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://github.com/danieltoader/capistrano-teams'
17
+ spec.metadata['changelog_uri'] = 'https://github.com/danieltoader/capistrano-teams/blob/master/CHANGELOG.md'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`
22
+ .split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'bin'
25
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_dependency 'capistrano', '~> 3.0'
30
+ spec.add_development_dependency 'bundler', '>= 1.16'
31
+ spec.add_development_dependency 'coveralls'
32
+ spec.add_development_dependency 'rake', '~> 12.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.2'
34
+ spec.add_development_dependency 'rubocop'
35
+ spec.add_development_dependency 'webmock'
36
+ end
Binary file
Binary file
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,52 @@
1
+ require 'capistrano/teams/web_hook'
2
+ require 'capistrano'
3
+
4
+ namespace :teams do
5
+ task :notify, :status, :facts, :theme_color do |task, args|
6
+ send_notification(
7
+ args[:status] || fetch(:teams_default_status),
8
+ args[:theme_color] || fetch(:teams_default_color),
9
+ args[:facts] || []
10
+ )
11
+ task.reenable
12
+ end
13
+ namespace :deploy do
14
+ task :starting do |task|
15
+ notify_event(fetch(:teams_starting_status), fetch(:teams_starting_color))
16
+ task.reenable
17
+ end
18
+
19
+ task :reverting do |task|
20
+ notify_event(fetch(:teams_reverting_status), fetch(:teams_reverting_color))
21
+ task.reenable
22
+ end
23
+
24
+ task :finishing do |task|
25
+ notify_event(fetch(:teams_finishing_status), fetch(:teams_finishing_color))
26
+ task.reenable
27
+ end
28
+
29
+ task :finishing_rollback do |task|
30
+ notify_event(fetch(:teams_rollback_status), fetch(:teams_rollback_color))
31
+ task.reenable
32
+ end
33
+
34
+ task :failed do |task|
35
+ notify_event(fetch(:teams_failed_status), fetch(:teams_failed_color))
36
+ task.reenable
37
+ end
38
+ end
39
+ end
40
+
41
+ def send_notification(status, color, facts)
42
+ Capistrano::Teams::WebHook.new.notify(status, color, facts)
43
+ puts "'#{status.capitalize}' event notification sent to teams."
44
+ end
45
+
46
+ def notify_event(status, color)
47
+ if fetch(:teams_suppress_events) == false
48
+ send_notification(status, color, [])
49
+ else
50
+ puts 'Notification not sent, `teams_suppress_events` is set to true or is invalid.'
51
+ end
52
+ end
@@ -0,0 +1,20 @@
1
+ require 'rake'
2
+ require 'capistrano/teams/version'
3
+ require 'capistrano/teams/message/types'
4
+
5
+ # Core tasks for teams integration
6
+ load File.expand_path('tasks/teams.rake', __dir__)
7
+
8
+ namespace :deploy do
9
+ before 'deploy:starting', 'teams:deploy:starting'
10
+ before 'deploy:reverting', 'teams:deploy:reverting'
11
+ after 'deploy:finishing', 'teams:deploy:finishing'
12
+ after 'deploy:finishing_rollback', 'teams:deploy:finishing_rollback'
13
+ after 'deploy:failed', 'teams:deploy:failed'
14
+ end
15
+
16
+ namespace :load do
17
+ task :defaults do
18
+ load 'capistrano/teams/defaults.rb'
19
+ end
20
+ end
@@ -0,0 +1,42 @@
1
+ # Teams defaults
2
+
3
+ # set :teams_webhook_url, "url"
4
+ set :teams_suppress_events, false
5
+ set :teams_message_type, Message::TYPE_BASIC # Message::TYPE_BASIC or Message::TYPE_CARD
6
+ set :teams_http_options, verify_mode: OpenSSL::SSL::VERIFY_PEER
7
+
8
+ # Theme colors
9
+ set :teams_starting_color, '0033CC'
10
+ set :teams_reverting_color, 'FFFF00'
11
+ set :teams_finishing_color, '00FF00'
12
+ set :teams_rollback_color, 'FFFF00'
13
+ set :teams_failed_color, 'FF0000'
14
+
15
+ # Statuses
16
+ set :teams_starting_status, 'STARTING'
17
+ set :teams_reverting_status, 'REVERTING'
18
+ set :teams_finishing_status, 'FINISHED'
19
+ set :teams_rollback_status, 'ROLLBACK'
20
+ set :teams_failed_status, 'FAILED'
21
+
22
+ # Used for Message::TYPE_BASIC
23
+ set :teams_basic_message_title, 'Deployment Notice » %<application>s'
24
+ set :teams_basic_message_text, '<h1>Deploy on <strong>%<stage>s</strong> by ' \
25
+ '<strong>%<user>s</strong></h1> ' \
26
+ "Branch: %<branch>s \n\n" \
27
+ 'Status: %<status>s'
28
+
29
+ # Used for Message::TYPE_CARD
30
+ set :teams_card_message_title, 'Deployment Notice » %<application>s'
31
+ set :teams_card_message_sub_title, 'On %<stage>s'
32
+ set :teams_card_message_image, ''
33
+ set :teams_card_message_summary, 'Deploy for %<application>s on %<stage>s by %<user>s'
34
+ set :teams_card_message_markdown, false
35
+
36
+ # Default values
37
+ set :teams_default_color, '333333'
38
+ set :teams_default_status, 'UNKNOWN'
39
+ set :teams_default_application, 'N/A'
40
+ set :teams_default_branch, 'N/A'
41
+ set :teams_default_stage, 'N/A'
42
+ set :teams_default_user, 'UNKNOWN'
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Message
4
+ # Placeholder
5
+ class Placeholders
6
+ attr_reader :placeholders
7
+
8
+ def initialize(placeholders)
9
+ @placeholders = defaults.merge(placeholders)
10
+ end
11
+
12
+ private
13
+
14
+ def defaults
15
+ {
16
+ application: fetch(:application, fetch(:teams_default_application)),
17
+ branch: fetch(:branch, fetch(:teams_default_branch)),
18
+ stage: fetch(:stage, :teams_default_stage),
19
+ user: ENV.fetch('USER', ENV.fetch('USERNAME', :teams_default_user))
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'capistrano/teams/message/placeholders'
4
+
5
+ module Message
6
+ TYPE_BASIC = 1
7
+ TYPE_CARD = 2
8
+ # Message builder class
9
+ class Builder
10
+ def self.of_type(type, placeholder_list, theme_color, facts)
11
+ case type
12
+ when Message::TYPE_BASIC
13
+ Basic.new(placeholder_list, theme_color, facts)
14
+ when Message::TYPE_CARD
15
+ MessageCard.new(placeholder_list, theme_color, facts)
16
+ else
17
+ raise 'Capistrano Teams: Unknown message type'
18
+ end
19
+ end
20
+ end
21
+
22
+ # Type
23
+ class Type
24
+ def initialize(placeholder_list, theme_color, facts = [])
25
+ @placeholder_list = placeholder_list
26
+ @theme_color = theme_color
27
+ @facts = facts
28
+ end
29
+
30
+ def placeholders
31
+ Message::Placeholders.new(@placeholder_list).placeholders
32
+ end
33
+
34
+ def content
35
+ raise 'Abstract method called'
36
+ end
37
+ end
38
+
39
+ # Basic type
40
+ class Basic < Type
41
+ # Get the body of the POST message as JSON.
42
+ def content
43
+ {
44
+ title: fetch(:teams_basic_message_title),
45
+ text: fetch(:teams_basic_message_text),
46
+ themeColor: @theme_color
47
+ }.to_json % placeholders
48
+ end
49
+ end
50
+
51
+ # MessageCard type
52
+ class MessageCard < Type
53
+ # Get the body of the POST message as JSON.
54
+ def content
55
+ {
56
+ '@type' => 'MessageCard',
57
+ '@context' => 'http://schema.org/extensions',
58
+ 'themeColor' => @theme_color,
59
+ 'summary' => fetch(:teams_card_message_summary),
60
+ 'sections' => sections,
61
+ 'potentialAction' => []
62
+ }.to_json % placeholders
63
+ end
64
+
65
+ private
66
+
67
+ def sections
68
+ [{
69
+ 'activityTitle' => fetch(:teams_card_message_title),
70
+ 'activitySubtitle' => fetch(:teams_card_message_sub_title),
71
+ 'activityImage' => fetch(:teams_card_message_image),
72
+ 'facts' => facts,
73
+ 'markdown' => fetch(:teams_card_message_markdown)
74
+ }]
75
+ end
76
+
77
+ def facts
78
+ [
79
+ {
80
+ 'name' => 'Deploy by',
81
+ 'value' => '%<user>s'
82
+ },
83
+ {
84
+ 'name' => 'Branch',
85
+ 'value' => '%<branch>s'
86
+ },
87
+ {
88
+ 'name' => 'Deploy date',
89
+ 'value' => Time.now.strftime('%d/%m/%Y %H:%M:%S')
90
+ }, {
91
+ 'name' => 'Status',
92
+ 'value' => '%<status>s'
93
+ }
94
+ ].concat(@facts)
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Teams
3
+ VERSION = '1.0.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+ require 'capistrano'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json'
5
+ require 'capistrano/teams/message/types'
6
+
7
+ module Capistrano
8
+ module Teams
9
+ class Error < StandardError; end
10
+
11
+ # Teams Webhook class
12
+ class WebHook
13
+ def notify(
14
+ status = fetch(:teams_default_status),
15
+ theme_color = fetch(:teams_default_color),
16
+ facts = []
17
+ )
18
+ content = Message::Builder.of_type(
19
+ fetch(:teams_message_type),
20
+ {
21
+ status: status
22
+ },
23
+ theme_color,
24
+ facts
25
+ ).content
26
+ send_message_to_webhook(content)
27
+ end
28
+
29
+ # Post to Teams.
30
+ def send_message_to_webhook(body)
31
+ uri = URI.parse(fetch(:teams_webhook_url).to_s)
32
+ request = Net::HTTP::Post.new(uri.path)
33
+ request.content_type = 'application/json'
34
+ request.body = body
35
+
36
+ opts = { use_ssl: uri.scheme == 'https' } \
37
+ .merge(fetch(:teams_http_options))
38
+
39
+ Net::HTTP.start(uri.host, uri.port, opts) do |http|
40
+ http.request(request)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-teams
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Toader
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
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.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - developer@danieltoader.com
114
+ executables:
115
+ - console
116
+ - setup
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".coveralls.yml"
121
+ - ".github/workflows/gem-push.yml"
122
+ - ".gitignore"
123
+ - ".rspec"
124
+ - ".rubocop.yml"
125
+ - ".rubocop_todo.yml"
126
+ - ".travis.yml"
127
+ - CHANGELOG.md
128
+ - CODEOWNERS
129
+ - CODE_OF_CONDUCT.md
130
+ - Gemfile
131
+ - LICENSE.md
132
+ - README.md
133
+ - Rakefile
134
+ - appveyor.yml
135
+ - bin/console
136
+ - bin/setup
137
+ - capistrano-teams.gemspec
138
+ - docs/img/message_type_basic.png
139
+ - docs/img/message_type_card.png
140
+ - lib/capistrano-teams.rb
141
+ - lib/capistrano/tasks/teams.rake
142
+ - lib/capistrano/teams.rb
143
+ - lib/capistrano/teams/defaults.rb
144
+ - lib/capistrano/teams/message/placeholders.rb
145
+ - lib/capistrano/teams/message/types.rb
146
+ - lib/capistrano/teams/version.rb
147
+ - lib/capistrano/teams/web_hook.rb
148
+ homepage: https://rubygems.org/gems/capistrano-teams
149
+ licenses:
150
+ - MIT
151
+ metadata:
152
+ homepage_uri: https://rubygems.org/gems/capistrano-teams
153
+ source_code_uri: https://github.com/danieltoader/capistrano-teams
154
+ changelog_uri: https://github.com/danieltoader/capistrano-teams/blob/master/CHANGELOG.md
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: 2.0.0
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubygems_version: 3.0.3
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Microsoft Teams integration for Capistrano 3.x
174
+ test_files: []