watchdoge 0.1.7 → 0.1.8

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
2
  SHA256:
3
- metadata.gz: c7d55d35da8cf78d104cd137006589fd6c1385e8fe6073e6ea2105e47dbddd83
4
- data.tar.gz: 309a97e2cdf1afe3e2d9145d0645f06399a9d1912368afbdc0565ef1fa1bd688
3
+ metadata.gz: 31dedfc4a4c2e9534672ab388d89afeccb56e9855b5e14e9c454f9b4b0750670
4
+ data.tar.gz: c91210715bedf6187b55e543ff95f82a4390457bd9a4c83026c36d1ab130175b
5
5
  SHA512:
6
- metadata.gz: beb39f5cd806d48d66878e5c3c05d714b333c481c5f47507e089a604f14862b93bb5f28d584547c759aad92c9c2c62da710749754b18141153ea5ca7e0596e81
7
- data.tar.gz: 2b4e8171569a1ead3761c0936a647f73903f0cd107dc3a6723eff105a411dcdf8ab0f4bb1c4e0161e13621a8010d1094677a567d7c1099e3b6ee51d0a93e3fee
6
+ metadata.gz: aead7efe871204a654be431a18eacbd5eb1b22e299f0f2eb6d941022d58826fb0cb5024623dff704758558a07a2531c6d3e825409a0f5d4c74b66b5115ee29b4
7
+ data.tar.gz: e255c5c965a8a3dcaa8709a762a07127d9aa6850b3f06ecacfb67dac9accca785fd4a84e48fd53bb0988b738a27b0a29a6ca06a714f1e39dd26e3fe3201f2a00
@@ -0,0 +1,107 @@
1
+ require 'pry'
2
+ require 'net_http_ssl_fix'
3
+
4
+ require 'chunky_png'
5
+ require 'json'
6
+ require 'net/http'
7
+ require 'net/http/post/multipart'
8
+ require 'uri'
9
+
10
+ module WatchDoge
11
+ module Notification
12
+ class GitlabRepo
13
+ def initialize opt
14
+ @host = opt[:host] || ENV['CI_API_V4_URL']
15
+ @project_id = opt[:project_id] || ENV['CI_PROJECT_ID']
16
+ @source_branch = opt[:source_branch] || ENV['CI_COMMIT_REF_NAME']
17
+
18
+ @private_token = opt[:private_token]
19
+
20
+ @message_queue = []
21
+ end
22
+
23
+ def push message
24
+ @message_queue << message
25
+ end
26
+
27
+ def flush
28
+ @message_queue.each do |message|
29
+ iid = get_latest_request_iid
30
+
31
+ return if iid.nil?
32
+
33
+ case message
34
+ when String
35
+ post_discussion request_iid: iid, message: message
36
+ when ChunkyPNG::Image
37
+ image_blob = message.to_blob
38
+ res = upload_image image_blob
39
+ image_link = "![image](#{ENV['CI_PROJECT_URL']}#{res['url']})"
40
+ post_discussion request_iid: iid, message: image_link
41
+
42
+ # TODO: should add WatchDoge::Diff as pair of before/after iamges
43
+ # when WatchDoge::Diff
44
+ end
45
+ end
46
+ end
47
+
48
+ def post_discussion request_iid:, message:
49
+ uri = project_uri "/merge_requests/#{request_iid}/discussions"
50
+
51
+ Net::HTTP.post uri,
52
+ { body: message }.to_json,
53
+ "Content-Type": "application/json",
54
+ "PRIVATE-TOKEN": @private_token
55
+ end
56
+
57
+ def upload_image blob
58
+ uri = project_uri "/uploads"
59
+
60
+ req = Net::HTTP::Post::Multipart.new uri.path, {
61
+ file: UploadIO.new(StringIO.new(blob), 'image/png', 'image.png')
62
+ }
63
+
64
+ req.add_field("PRIVATE-TOKEN", @private_token)
65
+
66
+ res = Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == "https")) do |http|
67
+ res = http.request(req).body
68
+ end
69
+
70
+ JSON.parse(res)
71
+ end
72
+
73
+ def get_latest_request_iid
74
+ uri = project_uri "/merge_requests?source_branch=#{@source_branch}&view=simple"
75
+
76
+ req = Net::HTTP::Get.new uri
77
+ req.add_field("PRIVATE-TOKEN", @private_token)
78
+
79
+ res = Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == "https")) do |http|
80
+ http.request(req).body
81
+ end
82
+
83
+ return nil if res.empty?
84
+
85
+ JSON.parse(res)[0]['iid']
86
+ end
87
+
88
+ private
89
+
90
+ # markdown_table do |context|
91
+ def markdown_table
92
+ "<table>
93
+ <tr>
94
+ <th>before</th>
95
+ <th>after</th>
96
+ <th>diff</th>
97
+ </tr>
98
+ #{yield("")}
99
+ </table>"
100
+ end
101
+
102
+ def project_uri path
103
+ URI(@host + "/projects/#{@project_id}#{path}")
104
+ end
105
+ end
106
+ end
107
+ end
@@ -11,14 +11,22 @@ module WatchDoge
11
11
  @host = args[:host]
12
12
  @channel_id = args[:channel_id]
13
13
  @auth_token = args[:auth_token]
14
+
15
+ @message_queue = []
14
16
  end
15
17
 
16
18
  def push message
17
- case message
18
- when String
19
- post matter_most_meta(message)
20
- when ChunkyPNG::Image
21
- post_file matter_most_meta(message)
19
+ @message_queue << message
20
+ end
21
+
22
+ def flush
23
+ @message_queue.each do |message|
24
+ case message
25
+ when String
26
+ post matter_most_meta(message)
27
+ when ChunkyPNG::Image
28
+ post_file matter_most_meta(message)
29
+ end
22
30
  end
23
31
  end
24
32
 
@@ -8,13 +8,21 @@ module WatchDoge
8
8
  class SlackWebhook
9
9
  def initialize opt
10
10
  @incoming_url = opt[:incoming_url]
11
+
12
+ @message_queue = []
11
13
  end
12
14
 
13
15
  def push message
14
- body = slack_body(message).to_json
15
- Net::HTTP.post URI(@incoming_url),
16
- body,
17
- "Content-Type" => "application/json"
16
+ @message_queue << message
17
+ end
18
+
19
+ def flush
20
+ @message_queue.each do |message|
21
+ body = slack_body(message).to_json
22
+ Net::HTTP.post URI(@incoming_url),
23
+ body,
24
+ "Content-Type" => "application/json"
25
+ end
18
26
  end
19
27
 
20
28
  private
@@ -23,24 +23,49 @@
23
23
  # built-in sources
24
24
  require 'watchdoge/notification/slack_webhook'
25
25
  require 'watchdoge/notification/mattermost'
26
+ require 'watchdoge/notification/gitlab_repo'
26
27
 
27
28
  module WatchDoge
29
+ class RegressionError < StandardError; end
30
+
28
31
  module Notification
29
32
  class << self
30
33
  def push message
31
- sources = WatchDoge.configuration.notifications
32
-
33
- raise "can't find notification sources in configuration" if sources.empty?
34
+ sources do |klass|
35
+ puts "new msg push to #{klass}"
36
+ klass.push message
37
+ end
38
+ end
34
39
 
35
- sources.each do |klass_sym, source_args|
36
- source_class = get_source_class klass_sym
37
- source = source_class.new source_args
38
- source.push message
40
+ def flush
41
+ sources do |klass|
42
+ puts 'flush!'
43
+ klass.flush
39
44
  end
45
+
46
+ raise WatchDoge::RegressionError, 'Has detected style changed. Regression failed'
40
47
  end
41
48
 
42
49
  private
43
50
 
51
+ def sources
52
+ @sources ||= WatchDoge.configuration.notifications
53
+
54
+ raise "can't find notification sources in configuration" if @sources.empty?
55
+
56
+ @sources.each do |klass_sym, source_args|
57
+ sources_map[klass_sym] ||=
58
+ get_source_class(klass_sym).new source_args
59
+
60
+ yield(sources_map[klass_sym])
61
+ end
62
+ end
63
+
64
+ def sources_map
65
+ @sources_map ||= {}
66
+ @sources_map
67
+ end
68
+
44
69
  def get_source_class klass_sym
45
70
  klass = klass_sym.to_s.split('_').collect(&:capitalize).join
46
71
 
@@ -1,4 +1,4 @@
1
1
  # Version of WatchDoge
2
2
  module WatchDoge
3
- VERSION = '0.1.7'
3
+ VERSION = '0.1.8'
4
4
  end
data/watchdoge.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'watchdoge'
3
- s.version = '0.1.7'
3
+ s.version = '0.1.8'
4
4
  s.date = '2019-07-22'
5
5
  s.summary = "dogi"
6
6
  s.description = "WatchDoge is Ruby on Rails friendly frontend regression test tool"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watchdoge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shen Lee
@@ -116,6 +116,7 @@ files:
116
116
  - lib/watchdoge/cookie_pool.rb
117
117
  - lib/watchdoge/image_diff.rb
118
118
  - lib/watchdoge/notification.rb
119
+ - lib/watchdoge/notification/gitlab_repo.rb
119
120
  - lib/watchdoge/notification/mattermost.rb
120
121
  - lib/watchdoge/notification/slack_webhook.rb
121
122
  - lib/watchdoge/rails/generator.rb