popper 0.4.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 187ce2bfa04e7e4e93dcb54d86c2dc89519adb27
4
- data.tar.gz: 424a05a87739b1521318237b45a21eeb6cfa7cd7
2
+ SHA256:
3
+ metadata.gz: c139212160c9146981eb7b1916a8ffdfde137559e98d97769372177ce79d85b4
4
+ data.tar.gz: a8529c375cfc5c5636c7d68a4540a694692f8d524346746f84fca6298928f6e3
5
5
  SHA512:
6
- metadata.gz: fa7432bf5a1123101ffb791c545977488925caf2e719ade9d934d68ce599d877974d3092b2d7e68890b0e06b551d8ce308727e675559898ff42ed36e2d69ede4
7
- data.tar.gz: 43186b300d72f4e04acf0b3fb835327200ae18b5dc3c21ad290c7e551cfddad3555363f5c948330b52e74fb8052be1113b43bc09ff75d38808318cefe0635369
6
+ metadata.gz: c55e98e69b188f7603c2d75da1833b37afad6becfce028f5bf215423b23cee059169dd4a0285566ebe5aa355732c39a9ebb08ccb11175aa4eb53c11286a64386
7
+ data.tar.gz: 07c95f847d754d05de0015daea9192c5958f17d2802deb3b34f8abedb8599244ffb5a5106eead73de0594cf732362c0452ab9039c63e57d534fcd7ef59995683
@@ -1,9 +1,19 @@
1
1
  require 'bundler'
2
+ require 'shellwords'
3
+ require 'tempfile'
2
4
  module Popper::Action
3
5
  class ExecCmd < Base
4
6
  def self.task(mail, params={})
7
+ tmps = mail.attachments.map do |a|
8
+ ::Tempfile.open(a.filename) do |f|
9
+ f.write a.body.decoded
10
+ f
11
+ end
12
+ end unless mail.attachments.empty?
13
+ cmd = "#{@action_config.cmd} #{Shellwords.escape(mail.subject)} #{Shellwords.escape(mail.utf_body)} #{Shellwords.escape(mail.from.join(";"))} #{Shellwords.escape(mail.to.join(";"))}"
14
+ cmd += " #{tmps.map {|t| Shellwords.escape(t.path) }.join(' ')}" if tmps && !tmps.empty?
5
15
  ::Bundler.with_clean_env do
6
- system("#{@action_config.cmd} '#{mail.subject}' '#{mail.utf_body}' '#{mail.from.join(";")}' '#{mail.to.join(";")}'")
16
+ system(cmd)
7
17
  end
8
18
  params
9
19
  end
@@ -0,0 +1,25 @@
1
+ module Popper::Action
2
+ class Webhook < Base
3
+ def self.task(mail, params = {})
4
+ post!(@action_config.webhook_url, mail.subject, mail.utf_body)
5
+
6
+ params
7
+ end
8
+
9
+ def self.check_params
10
+ @action_config.respond_to?(:webhook_url)
11
+ end
12
+
13
+ def self.post!(url, subject, body)
14
+ request_body = { subject: subject, body: body }.to_json
15
+
16
+ Faraday.post(
17
+ url,
18
+ request_body,
19
+ "Content-Type" => "application/json"
20
+ )
21
+ end
22
+
23
+ next_action(ExecCmd)
24
+ end
25
+ end
data/lib/popper/action.rb CHANGED
@@ -4,4 +4,5 @@ module Popper::Action
4
4
  autoload :Ghe, "popper/action/ghe"
5
5
  autoload :Git, "popper/action/git"
6
6
  autoload :ExecCmd, "popper/action/exec_cmd"
7
+ autoload :Webhook, "popper/action/webhook"
7
8
  end
data/lib/popper/config.rb CHANGED
@@ -56,7 +56,7 @@ module Popper
56
56
  end
57
57
 
58
58
  [
59
- %w(find all?),
59
+ %w(select all?),
60
60
  %w(each each),
61
61
  ].each do |arr|
62
62
  define_method("rule_with_conditions_#{arr[0]}") do |&blk|
@@ -47,9 +47,9 @@ module Popper
47
47
  def check_and_action(m)
48
48
  mail = EncodeMail.new(m.mail)
49
49
  Popper.log.info "check mail:#{mail.date.to_s} #{mail.subject}"
50
- if rule = match_rule?(mail)
50
+ match_rules?(mail).each do |rule|
51
51
  Popper.log.info "do action:#{mail.subject}"
52
- Popper::Action::ExecCmd.run(config.action_by_rule(rule), mail) if config.action_by_rule(rule)
52
+ Popper::Action::Webhook.run(config.action_by_rule(rule), mail) if config.action_by_rule(rule)
53
53
  end
54
54
 
55
55
  m.uidl
@@ -85,8 +85,8 @@ module Popper
85
85
  conn.mails.select {|_m|uidl_list.include?(_m.uidl)}
86
86
  end
87
87
 
88
- def match_rule?(mail)
89
- config.rule_with_conditions_find do |rule,mail_header,conditions|
88
+ def match_rules?(mail)
89
+ config.rule_with_conditions_select do |rule,mail_header,conditions|
90
90
  conditions.all? do |condition|
91
91
  mail.respond_to?(mail_header) && mail.send(mail_header).to_s.match(/#{condition}/)
92
92
  end
@@ -1,3 +1,3 @@
1
1
  module Popper
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.2"
3
3
  end
data/popper.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'toml'
25
25
  spec.add_dependency 'mail'
26
26
  spec.add_dependency 'octokit'
27
+ spec.add_dependency 'faraday'
27
28
  spec.add_dependency "bundler"
28
29
  spec.add_development_dependency "rake", "~> 10.0"
29
30
  spec.add_development_dependency "rspec"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: popper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyama86
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-19 00:00:00.000000000 Z
11
+ date: 2021-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -147,6 +161,7 @@ files:
147
161
  - lib/popper/action/ghe.rb
148
162
  - lib/popper/action/git.rb
149
163
  - lib/popper/action/slack.rb
164
+ - lib/popper/action/webhook.rb
150
165
  - lib/popper/cli.rb
151
166
  - lib/popper/config.rb
152
167
  - lib/popper/init.rb
@@ -157,7 +172,7 @@ homepage: http://ten-snapon.com
157
172
  licenses:
158
173
  - MIT
159
174
  metadata: {}
160
- post_install_message:
175
+ post_install_message:
161
176
  rdoc_options: []
162
177
  require_paths:
163
178
  - lib
@@ -172,9 +187,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
187
  - !ruby/object:Gem::Version
173
188
  version: '0'
174
189
  requirements: []
175
- rubyforge_project:
176
- rubygems_version: 2.6.13
177
- signing_key:
190
+ rubygems_version: 3.1.6
191
+ signing_key:
178
192
  specification_version: 4
179
193
  summary: email notification tool
180
194
  test_files: []