ZReviewTender 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/Processors/SlackProcessor.rb +45 -24
- 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: 2807fe3efdfb17de59b50713359ba58097f36482389f1d4089056103d16be154
|
4
|
+
data.tar.gz: 8366edb466dda73e67a553084b7b96e97f42c03e4cdb8dc2509e2edacd2f1d3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eb36009c81955c741701b5c57559d67a16c1fd7df2528b2893ceae37f40c00879d81d8a6a65d4eae930d6125b2f33492f966837ed440acd15d56e42a631c378
|
7
|
+
data.tar.gz: 108d45d065e7f045a5bb88c72fe8e8e79b132f5bb42cdb7e9f00191a4b660e3ff726f4027d79889e5b0d0c67975cf56c02494754449641774f5107b2fb1ed96b
|
@@ -9,7 +9,7 @@ require "time"
|
|
9
9
|
|
10
10
|
class SlackProcessor < Processor
|
11
11
|
|
12
|
-
attr_accessor :botToken, :inCommingWebHookURL, :targetChannel, :timeZoneOffset
|
12
|
+
attr_accessor :botToken, :inCommingWebHookURL, :targetChannel, :timeZoneOffset, :attachmentGroupByNumber
|
13
13
|
|
14
14
|
def initialize(config, configFilePath, baseExecutePath)
|
15
15
|
@config = config
|
@@ -20,6 +20,11 @@ class SlackProcessor < Processor
|
|
20
20
|
@inCommingWebHookURL = config["slackInCommingWebHookURL"]
|
21
21
|
@targetChannel = config["slackBotTargetChannel"]
|
22
22
|
@timeZoneOffset = Helper.unwrapRequiredParameter(config, "slackTimeZoneOffset")
|
23
|
+
@attachmentGroupByNumber = 1
|
24
|
+
|
25
|
+
if !config['slackAttachmentGroupByNumber'].nil? && config['slackAttachmentGroupByNumber'] != "" && config['slackAttachmentGroupByNumber'].to_i > 0 && config['slackAttachmentGroupByNumber'].to_i < 100
|
26
|
+
@attachmentGroupByNumber = config['slackAttachmentGroupByNumber'].to_i
|
27
|
+
end
|
23
28
|
|
24
29
|
if (botToken.nil? && inCommingWebHookURL.nil?) || (botToken == "" && inCommingWebHookURL == "")
|
25
30
|
raise "must specify slackBotToken or slackInCommingWebHookURL in SlackProcessor."
|
@@ -30,35 +35,51 @@ class SlackProcessor < Processor
|
|
30
35
|
|
31
36
|
def processReviews(reviews, platform)
|
32
37
|
|
33
|
-
|
34
|
-
|
38
|
+
pendingPayloads = []
|
39
|
+
|
40
|
+
# Slack Message Limit: posting one message per second per channel
|
41
|
+
reviews.each_slice(attachmentGroupByNumber) do |reviewGroup|
|
35
42
|
payload = Payload.new()
|
36
43
|
payload.attachments = []
|
37
|
-
|
38
|
-
attachment = Payload::Attachment.new()
|
39
44
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
title = "#{review.title} - #{stars}"
|
47
|
-
end
|
45
|
+
reviewGroup.each do |review|
|
46
|
+
attachment = Payload::Attachment.new()
|
47
|
+
|
48
|
+
stars = "★" * review.rating + "☆" * (5 - review.rating)
|
49
|
+
color = review.rating >= 4 ? "good" : (review.rating > 2 ? "warning" : "danger")
|
50
|
+
date = Time.at(review.createdDateTimestamp).getlocal(timeZoneOffset)
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
title = "#{stars}"
|
53
|
+
if !review.title.nil?
|
54
|
+
title = "#{review.title} - #{stars}"
|
55
|
+
end
|
56
|
+
|
57
|
+
attachment.color = color
|
58
|
+
attachment.author_name = review.userName
|
59
|
+
attachment.fallback = title
|
60
|
+
attachment.title = title
|
61
|
+
attachment.text = review.body
|
62
|
+
attachment.footer = "#{platform} - #{review.platform} - #{review.appVersion} - #{review.territory} - <#{review.url}|#{date}>"
|
63
|
+
|
64
|
+
payload.attachments.append(attachment)
|
65
|
+
end
|
66
|
+
|
67
|
+
pendingPayloads.append(payload)
|
68
|
+
end
|
69
|
+
|
70
|
+
loop do
|
71
|
+
payload = pendingPayloads.pop
|
57
72
|
|
58
73
|
result = request(payload)
|
59
|
-
if !result
|
74
|
+
if !result[:ok]
|
60
75
|
Helper.logError(result)
|
76
|
+
if result[:message] == "ratelimited"
|
77
|
+
sleep(1)
|
78
|
+
pendingPayloads.append(payload)
|
79
|
+
end
|
61
80
|
end
|
81
|
+
|
82
|
+
break if pendingPayloads.length < 1
|
62
83
|
end
|
63
84
|
|
64
85
|
return reviews
|
@@ -108,10 +129,10 @@ class SlackProcessor < Processor
|
|
108
129
|
res = http.request(req)
|
109
130
|
|
110
131
|
if isInCommingWebHook
|
111
|
-
return res.body == "ok"
|
132
|
+
return {"ok":res.body == "ok", "message":nil}
|
112
133
|
else
|
113
134
|
result = JSON.parse(res.body)
|
114
|
-
return result["ok"] == true
|
135
|
+
return {"ok":result["ok"] == true, "message":result['error']}
|
115
136
|
end
|
116
137
|
|
117
138
|
end
|