capistrano-around_chatwork 0.2.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fe7aa212a935a1142575c6294d6cc6a6fc866190
4
- data.tar.gz: 25d4d134ae843d346b36840e16030fe19410bf93
2
+ SHA256:
3
+ metadata.gz: 5b34c7cd65eac8fc38b71cf21d2b7409914b41b2f098a18a0c80393073574d4f
4
+ data.tar.gz: 8275c92cb60eaf6e2f26901ff17e6cedc5c32451db544c65a9f8055ffeeb0d8e
5
5
  SHA512:
6
- metadata.gz: 62ba7ebee1492675e0a27f11ad7d0f022d210ffc7bd2215b1790aa0f125eeea85b2af30c430ea3519029ab8cdb5229cd9668fb9019a983be60539eef94ce8856
7
- data.tar.gz: 76f9aac571b8dfb85a92f55926e0511635aa6d0653152bd1f137ad0366c917448c5a04d94624ba2de7a84997be7ad998a89e6850f2d6e6c0e7d27f67cb0a20aa
6
+ metadata.gz: 611fbcdf96089e7df3f4cf4a03827c438a23a58ad122022b89a5a61b312be65e5a100ec6fd6e1c5abc99332656fc049418ba3729afd31dd7932d26dc9db92fd9
7
+ data.tar.gz: bb36c905f53aac284010db88526dc2d0b1b792f10ce0742b5c3bf0da7dde404d4babbc1c9d14cbf75b814b6ef05561eae9f5948990358cd491c21c5bd6576c44
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Changelog
2
2
  ## Unreleased
3
- [full changelog](https://github.com/sue445/capistrano-around_chatwork/compare/v0.2.0...master)
3
+ [full changelog](https://github.com/sue445/capistrano-around_chatwork/compare/v1.0.0...master)
4
+
5
+ ## 1.0.0
6
+ [full changelog](https://github.com/sue445/capistrano-around_chatwork/compare/v0.2.0...v1.0.0)
7
+
8
+ * Drop support ruby older than 2.1 :bomb:
9
+ * Notify failure message if task is failed
10
+ * https://github.com/sue445/capistrano-around_chatwork/pull/3
4
11
 
5
12
  ## 0.2.0
6
13
  [full changelog](https://github.com/sue445/capistrano-around_chatwork/compare/v0.1.1...v0.2.0)
data/README.md CHANGED
@@ -36,10 +36,9 @@ around_chatwork "deploy"
36
36
  ```
37
37
 
38
38
  ## Customize
39
- If you want to customize starting and ending mesasge, set `starting_message` and `ending_message`
40
-
41
- example
39
+ If you want to customize messages, set `starting_message`, `ending_message` and `failure_message`
42
40
 
41
+ ### Example
43
42
  ```ruby
44
43
  set :starting_message, -> {
45
44
  "[info][title][#{fetch(:stage)}] :task_name: @#{fetch(:user)}[/title]started[/info]"
@@ -48,10 +47,22 @@ set :starting_message, -> {
48
47
  set :ending_message, -> {
49
48
  "[info][title][#{fetch(:stage)}] :task_name: @#{fetch(:user)}[/title]done (:elapsed_time: sec)[/info]"
50
49
  }
50
+
51
+ set :failure_message, -> {
52
+ <<-MSG
53
+ [info][title][#{fetch(:stage)}] :task_name: @#{fetch(:user)}[/title]failed (:elapsed_time: sec)
54
+ :error_inspect:
55
+ :error_backtrace:[/info]
56
+ MSG
57
+ }
51
58
  ```
52
59
 
60
+ ### Variables
53
61
  * `:task_name:` is replaced to current task name (e.g. `deploy`)
54
62
  * `:elapsed_time:` is replaced to elapsed time of task (e.g. `1.234`)
63
+ * `:error_message:` is replaced to error message (i.e. `Exception#message`) if task is failed
64
+ * `:error_inspect:` is replaced to error inspected message (i.e. `Exception#inspect`) if task is failed
65
+ * `:error_backtrace:` is replaced to error backtrace (i.e. `Exception#backtrace`) if task is failed
55
66
 
56
67
  ## Development
57
68
 
@@ -14,6 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/sue445/capistrano-around_chatwork"
15
15
  spec.license = "MIT"
16
16
 
17
+ spec.required_ruby_version = ">= 2.1.0"
18
+
17
19
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
20
  # delete this section to allow pushing this gem to any host.
19
21
  if spec.respond_to?(:metadata)
@@ -3,8 +3,19 @@ require "cha"
3
3
 
4
4
  module Capistrano
5
5
  module AroundChatwork
6
- def self.format_message(message, task_name, elapsed_time = 0)
7
- message.gsub(":task_name:", task_name).gsub(":elapsed_time:", sprintf("%5.3f", elapsed_time))
6
+ def self.format_message(message:, task_name:, elapsed_time: 0, error: nil)
7
+ formatted_message = message.
8
+ gsub(":task_name:", task_name).
9
+ gsub(":elapsed_time:", sprintf("%5.3f", elapsed_time))
10
+
11
+ if error
12
+ formatted_message = formatted_message.
13
+ gsub(":error_message:", error.message).
14
+ gsub(":error_inspect:", error.inspect).
15
+ gsub(":error_backtrace:", error.backtrace.join("\n"))
16
+ end
17
+
18
+ formatted_message
8
19
  end
9
20
 
10
21
  def self.post_chatwork(message)
@@ -18,18 +29,47 @@ def around_chatwork(task_name)
18
29
  start_time = nil
19
30
 
20
31
  before_task = Rake::Task.define_task("#{task_name}:__before__") do
21
- message = Capistrano::AroundChatwork.format_message(fetch(:starting_message), task_name)
32
+ message = Capistrano::AroundChatwork.format_message(
33
+ message: fetch(:starting_message),
34
+ task_name: task_name,
35
+ )
22
36
  Capistrano::AroundChatwork.post_chatwork(message)
23
37
  start_time = Time.now
24
38
  end
25
39
 
26
40
  after_task = Rake::Task.define_task("#{task_name}:__after__") do
27
41
  elapsed_time = Time.now - start_time
28
- message = Capistrano::AroundChatwork.format_message(fetch(:ending_message), task_name, elapsed_time)
42
+ message = Capistrano::AroundChatwork.format_message(
43
+ message: fetch(:ending_message),
44
+ task_name: task_name,
45
+ elapsed_time: elapsed_time,
46
+ )
29
47
  Capistrano::AroundChatwork.post_chatwork(message)
30
48
  end
31
49
 
32
- Rake::Task[task_name].enhance([before_task]) do
50
+ target_task = Rake::Task[task_name]
51
+
52
+ target_task.instance_eval do
53
+ define_singleton_method :invoke_with_failure_message do |*args|
54
+ begin
55
+ invoke_without_failure_message(*args)
56
+ rescue Exception => error
57
+ elapsed_time = Time.now - start_time
58
+ message = Capistrano::AroundChatwork.format_message(
59
+ message: fetch(:failure_message),
60
+ task_name: task_name,
61
+ elapsed_time: elapsed_time,
62
+ error: error,
63
+ )
64
+ Capistrano::AroundChatwork.post_chatwork(message)
65
+ raise
66
+ end
67
+ end
68
+ alias :invoke_without_failure_message :invoke
69
+ alias :invoke :invoke_with_failure_message
70
+ end
71
+
72
+ target_task.enhance([before_task]) do
33
73
  Rake::Task[after_task].invoke
34
74
  end
35
75
  end
@@ -42,4 +82,12 @@ set :ending_message, -> {
42
82
  "[info][title][#{fetch(:stage)}] :task_name: @#{fetch(:user)}[/title]done (:elapsed_time: sec)[/info]"
43
83
  }
44
84
 
85
+ set :failure_message, -> {
86
+ <<-MSG
87
+ [info][title][#{fetch(:stage)}] :task_name: @#{fetch(:user)}[/title]failed (:elapsed_time: sec)
88
+ :error_inspect:
89
+ :error_backtrace:[/info]
90
+ MSG
91
+ }
92
+
45
93
  set :user, local_user
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module AroundChatwork
3
- VERSION = "0.2.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-around_chatwork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-02 00:00:00.000000000 Z
11
+ date: 2018-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
97
  requirements:
98
98
  - - ">="
99
99
  - !ruby/object:Gem::Version
100
- version: '0'
100
+ version: 2.1.0
101
101
  required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  requirements:
103
103
  - - ">="
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  requirements: []
107
107
  rubyforge_project:
108
- rubygems_version: 2.6.8
108
+ rubygems_version: 2.7.3
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: post to ChatWork before and after the specified task