capistrano-dingtalk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2e7395106c59bc7d87e3b8dd8460d5a758dd9ccf
4
+ data.tar.gz: 7bfc5f252e97152991c26fe79cfab99ff0e21a5b
5
+ SHA512:
6
+ metadata.gz: 5145836e12ac43075d6b5499cfddfe0f45ec004984e0586d22575074bf79fe7ec0b95116fa32ac49e814052743c023d3de577d29f8de79acc0683aaaecefd8ff
7
+ data.tar.gz: 7d394b88541a8ba591e2a53ef7de4f86afacb51ac095c00a4bdd2590f20fde5c42de905efc9fb3bc680d7042a7800edfd0dd91c5179bfbaf8bf2c9be7993f146
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .tag*
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.6
@@ -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 atpking@gmail.com. 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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://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-dingtalk.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 atpking
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,58 @@
1
+ # Capistrano::Dingtalk
2
+
3
+ send msg to ding talk webhook rebot when capistrano works.
4
+
5
+ ## Requirements
6
+
7
+ - Capistrano >= 3.5.0
8
+ - Ruby >= 2.0
9
+
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'capistrano-dingtalk'
17
+ ```
18
+
19
+ Require the library in your application's Capfile:
20
+
21
+ ```ruby
22
+ require 'capistrano/dingtalk'
23
+ ```
24
+
25
+ ## configuration
26
+
27
+ 1. get dingtalk webhook url.
28
+ 2. add config to `config/deploy.rb` or the stages files.
29
+
30
+ ```ruby
31
+ set :dingtalk_info, {
32
+ category: "text" # option, selection: text, markdown, default is text
33
+ url: 'https://oapi.dingtalk.com/robot/send?access_token=abcedf012345678' # change to your url
34
+ at_mobiles: [], # option
35
+ at_all: false # option
36
+ }
37
+ ```
38
+
39
+ if you have any question, contact me by Wechat (name: atpking).
40
+
41
+ ## Thanks
42
+
43
+ Thanks to project `slackistrano` which could send msg to `slack.com`
44
+
45
+ ## Development
46
+
47
+ 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.
48
+
49
+ 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).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/capistrano-dingtalk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
54
+
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
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/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "capistrano/dingtalk"
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,31 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'capistrano/dingtalk/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "capistrano-dingtalk"
9
+ spec.version = Capistrano::Dingtalk::VERSION
10
+ spec.authors = ["atpking"]
11
+ spec.email = ["atpking@gmail.com"]
12
+
13
+ spec.summary = "ding talk capistrano plugin"
14
+ spec.description = "ding talk capistrano plugin, sending message to ding talk custom webhook rebot"
15
+ spec.homepage = "https://github.com/jicheng1014/capistrano-dingtalk"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.14"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+
29
+ spec.add_dependency "capistrano", ">= 3.5.0"
30
+ spec.add_dependency "rest-client", ">= 2.0"
31
+ end
@@ -0,0 +1,50 @@
1
+ require 'rest-client'
2
+ require_relative "dingtalk/version"
3
+ require_relative "dingtalk/messaging/base"
4
+ require_relative "dingtalk/messaging/text"
5
+ require_relative "dingtalk/messaging/markdown"
6
+ require 'forwardable'
7
+
8
+ load File.expand_path("../tasks/dingtalk.rake", __FILE__)
9
+
10
+ module Capistrano
11
+ class Dingtalk
12
+ extend Forwardable
13
+ def_delegators :env, :fetch, :run_locally
14
+
15
+ attr_reader :message
16
+ def initialize(env)
17
+ @env = env
18
+ @config = fetch(:dingtalk_info, {})
19
+ # TODO: supports more message categories
20
+ klass = message_klass
21
+ @message = klass.new @config
22
+ end
23
+
24
+ def run(action)
25
+ local = self
26
+ run_locally do
27
+ info "begin to send action #{action} to Dingtalk"
28
+ json = local.message.build_msg_json(action)
29
+ local.send(:send_msg_to_ding_talk, json)
30
+ end
31
+ end
32
+
33
+ def send_msg_to_ding_talk(json)
34
+ url = @config[:url]
35
+ RestClient.post(url, json, content_type: :json, accept: :json)
36
+ end
37
+
38
+ def message_klass
39
+ category = @config[:category] || 'text'
40
+ klass = Object
41
+ case category
42
+ when 'text'
43
+ klass = ::Capistrano::Dingtalk::Messaging::Text
44
+ when 'markdown'
45
+ klass = ::Capistrano::Dingtalk::Messaging::Markdown
46
+ end
47
+ klass
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,57 @@
1
+ require 'forwardable'
2
+ require 'json'
3
+ require_relative 'helpers'
4
+
5
+ module Capistrano::Dingtalk::Messaging
6
+ class Base
7
+ include Helpers
8
+ extend Forwardable
9
+ def_delegators :env, :fetch
10
+
11
+ def initialize(info)
12
+ @info = info || {}
13
+ end
14
+
15
+ def message_for_updating
16
+ "#{deployer} has started deploying branch #{branch} of #{application} to #{stage}"
17
+ end
18
+
19
+ def message_for_reverting
20
+ "#{deployer} has started rolling back branch #{branch} of #{application} to #{stage}"
21
+ end
22
+
23
+ def message_for_updated
24
+ "#{deployer} has finished deploying branch #{branch} of #{application} to #{stage}"
25
+ end
26
+
27
+ def message_for_reverted
28
+ "#{deployer} has finished rolling back branch of #{application} to #{stage}"
29
+ end
30
+
31
+ def message_for_failed
32
+ "#{deployer} has failed to #{deploying? ? 'deploy' : 'rollback'} branch #{branch} of #{application} to #{stage}"
33
+ end
34
+
35
+ ################################################################################
36
+
37
+ def message_for(action)
38
+ method = "message_for_#{action}"
39
+ respond_to?(method) && send(method)
40
+ end
41
+
42
+ def build_at_dict
43
+ at = {}
44
+ at["at"] = @info[:at_all]
45
+ at["atMobiles"] = @info[:at_mobiles]
46
+ at
47
+ end
48
+
49
+ def build_hash(action)
50
+ # implements on children
51
+ end
52
+
53
+ def build_msg_json(action)
54
+ build_hash(action).merge(build_at_dict).to_json
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,32 @@
1
+ module Capistrano::Dingtalk::Messaging
2
+ module Helpers
3
+ def username
4
+ 'cap-dingtalk-bot'
5
+ end
6
+
7
+ def deployer
8
+ ENV['USER'] || ENV['USERNAME']
9
+ end
10
+
11
+ def branch
12
+ fetch(:branch)
13
+ end
14
+
15
+ def application
16
+ fetch(:application)
17
+ end
18
+
19
+ def stage(default = 'an unknown stage')
20
+ fetch(:stage, default)
21
+ end
22
+
23
+ #
24
+ # Return the elapsed running time as a string.
25
+ #
26
+ # Examples: 21-18:26:30, 15:28:37, 01:14
27
+ #
28
+ def elapsed_time
29
+ `ps -p #{$PROCESS_ID} -o etime=`.strip
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'base'
2
+
3
+ module Capistrano::Dingtalk::Messaging
4
+ class Markdown < Base
5
+ def initialize(info)
6
+ @info = info || {}
7
+ end
8
+
9
+ def markdown_load(action)
10
+ "
11
+ ### #{application}
12
+ action: #{action}
13
+ deployer: `#{deployer}`
14
+ branch: `#{branch}`
15
+ stage: `#{stage}`"
16
+ end
17
+
18
+ ################################################################################
19
+
20
+ def markdown(action)
21
+ method = "message_for_#{action}"
22
+ respond_to?(method) && send(method)
23
+ end
24
+
25
+ def build_hash(action)
26
+ {
27
+ msgtype: "markdown",
28
+ markdown: {
29
+ title: message_for(action),
30
+ text: markdown_load(action)
31
+ }
32
+ }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'base'
2
+
3
+ module Capistrano::Dingtalk::Messaging
4
+ class Text < Base
5
+ def build_hash(action)
6
+ {
7
+ msgtype: "text",
8
+ text: {
9
+ content: message_for(action)
10
+ }
11
+ }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ class Dingtalk
3
+ VERSION = "0.1.0".freeze
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ namespace :dingtalk do
2
+ namespace :deploy do
3
+ desc 'Notify about updating deploy'
4
+ task :updating do
5
+ Capistrano::Dingtalk.new(self).run(:updating)
6
+ end
7
+
8
+ desc 'Notify about reverting deploy'
9
+ task :reverting do
10
+ Capistrano::Dingtalk.new(self).run(:reverting)
11
+ end
12
+
13
+ desc 'Notify about updated deploy'
14
+ task :updated do
15
+ Capistrano::Dingtalk.new(self).run(:updated)
16
+ end
17
+
18
+ desc 'Notify about reverted deploy'
19
+ task :reverted do
20
+ Capistrano::Dingtalk.new(self).run(:reverted)
21
+ end
22
+
23
+ desc 'Notify about failed deploy'
24
+ task :failed do
25
+ Capistrano::Dingtalk.new(self).run(:failed)
26
+ end
27
+
28
+ desc 'Test dingtalk integration'
29
+ task test: %i[updating updated reverting reverted failed] do
30
+ # all tasks run as dependencies
31
+ end
32
+ end
33
+ end
34
+
35
+ before 'deploy:updating', 'dingtalk:deploy:updating'
36
+ before 'deploy:reverting', 'dingtalk:deploy:reverting'
37
+ after 'deploy:finishing', 'dingtalk:deploy:updated'
38
+ after 'deploy:finishing_rollback', 'dingtalk:deploy:reverted'
39
+ after 'deploy:failed', 'dingtalk:deploy:failed'
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-dingtalk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - atpking
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-05 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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: capistrano
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.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: 3.5.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
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
+ description: ding talk capistrano plugin, sending message to ding talk custom webhook
84
+ rebot
85
+ email:
86
+ - atpking@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - capistrano-dingtalk.gemspec
102
+ - lib/capistrano/dingtalk.rb
103
+ - lib/capistrano/dingtalk/messaging/base.rb
104
+ - lib/capistrano/dingtalk/messaging/helpers.rb
105
+ - lib/capistrano/dingtalk/messaging/markdown.rb
106
+ - lib/capistrano/dingtalk/messaging/text.rb
107
+ - lib/capistrano/dingtalk/version.rb
108
+ - lib/capistrano/tasks/dingtalk.rake
109
+ homepage: https://github.com/jicheng1014/capistrano-dingtalk
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.10
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: ding talk capistrano plugin
133
+ test_files: []