watchdoge 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/watchdoge/notification/base.rb +2 -0
- data/lib/watchdoge/notification/gitlab_repo.rb +41 -11
- data/lib/watchdoge/notification/mattermost.rb +2 -0
- data/lib/watchdoge/notification/slack_webhook.rb +2 -0
- data/lib/watchdoge/version.rb +1 -1
- data/watchdoge.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76fd10c6db817b3ab03f70178df61e1aebe01746bf65880852cfc3760a1153b5
|
4
|
+
data.tar.gz: 6f91b29949c9180a40980f24499a8ff2a803454a3cf99fa4572cded427175c50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13fb74d5d2c25de6e884dc80dd3e60967bef9a3bc74e1f6934666982b472b8bbafcfdfcf8f49784ee978ee10136010adc4013b36c4282a56c59f526997daccf1
|
7
|
+
data.tar.gz: 72c8f4b464c69d87e056be7ef0e5edae5917bc31b345cd3e0a8ba79de18c71b7f0434dce53024f4f74ad9602cab65932ce2f14a093b99cea520082bce48987a6
|
@@ -16,25 +16,29 @@ module WatchDoge
|
|
16
16
|
@host = opt[:host] || ENV['CI_API_V4_URL']
|
17
17
|
@project_id = opt[:project_id] || ENV['CI_PROJECT_ID']
|
18
18
|
@source_branch = opt[:source_branch] || ENV['CI_COMMIT_REF_NAME']
|
19
|
+
@commit_short_sha = opt[:commit_short_sha] || ENV['CI_COMMIT_SHORT_SHA']
|
19
20
|
|
20
21
|
@private_token = opt[:private_token]
|
21
22
|
end
|
22
23
|
|
23
24
|
def flush
|
24
|
-
|
25
|
+
meesages_to_flush = @message_queue
|
26
|
+
@message_queue = []
|
27
|
+
|
28
|
+
target_id = get_latest_request_iid || get_commit_id
|
25
29
|
|
26
|
-
|
30
|
+
return if target_id.nil?
|
27
31
|
|
28
32
|
table = markdown_table do |table_context|
|
29
|
-
|
33
|
+
meesages_to_flush.each do |message|
|
30
34
|
case message
|
31
35
|
when String
|
32
|
-
post_discussion
|
36
|
+
post_discussion target_id, message: message
|
33
37
|
when ChunkyPNG::Image
|
34
38
|
upload_link = upload_image message
|
35
39
|
link = md_img_link upload_link
|
36
40
|
|
37
|
-
post_discussion
|
41
|
+
post_discussion target_id, message: link
|
38
42
|
when WatchDoge::PixelTest
|
39
43
|
before = md_img_link upload_image(message.before)
|
40
44
|
after = md_img_link upload_image(message.after)
|
@@ -47,13 +51,17 @@ module WatchDoge
|
|
47
51
|
table_context
|
48
52
|
end
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
post_discussion request_iid: iid, message: table
|
54
|
+
post_discussion target_id, message: table
|
53
55
|
end
|
54
56
|
|
55
|
-
def post_discussion
|
56
|
-
uri =
|
57
|
+
def post_discussion target_iid, message:
|
58
|
+
uri =
|
59
|
+
case @discussion_target
|
60
|
+
when :merge_request
|
61
|
+
project_uri("/merge_requests/#{target_iid}/discussions")
|
62
|
+
when :commit
|
63
|
+
project_uri("/commits/#{target_iid}/discussions")
|
64
|
+
end
|
57
65
|
|
58
66
|
Net::HTTP.post uri,
|
59
67
|
{ body: message }.to_json,
|
@@ -78,6 +86,8 @@ module WatchDoge
|
|
78
86
|
end
|
79
87
|
|
80
88
|
def get_latest_request_iid
|
89
|
+
@discussion_target = :merge_request
|
90
|
+
|
81
91
|
uri = project_uri "/merge_requests?source_branch=#{@source_branch}&view=simple"
|
82
92
|
|
83
93
|
req = Net::HTTP::Get.new uri
|
@@ -92,6 +102,23 @@ module WatchDoge
|
|
92
102
|
JSON.parse(res)[0]['iid']
|
93
103
|
end
|
94
104
|
|
105
|
+
def get_commit_id
|
106
|
+
@discussion_target = :commit
|
107
|
+
|
108
|
+
uri = project_uri "/repository/commits/#{@commit_short_sha}"
|
109
|
+
|
110
|
+
req = Net::HTTP::Get.new uri
|
111
|
+
req.add_field("PRIVATE-TOKEN", @private_token)
|
112
|
+
|
113
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == "https")) do |http|
|
114
|
+
http.request(req).body
|
115
|
+
end
|
116
|
+
|
117
|
+
return nil if res.empty?
|
118
|
+
|
119
|
+
JSON.parse(res)[0]['id']
|
120
|
+
end
|
121
|
+
|
95
122
|
private
|
96
123
|
|
97
124
|
def md_img_link link
|
@@ -100,7 +127,10 @@ module WatchDoge
|
|
100
127
|
|
101
128
|
# markdown_table do |context|
|
102
129
|
def markdown_table
|
103
|
-
"
|
130
|
+
"
|
131
|
+
#### Detail: #{ENV['CI_PIPELINE_URL']}
|
132
|
+
|
133
|
+
<table>
|
104
134
|
<tr>
|
105
135
|
<th>before</th>
|
106
136
|
<th>after</th>
|
data/lib/watchdoge/version.rb
CHANGED
data/watchdoge.gemspec
CHANGED