ZReviewTender 0.0.3 → 0.0.6

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: dc1e614d966b0f41f5b5032eb6f223479688d87b93ae38ad31ac88a3e913cb2d
4
- data.tar.gz: f29b845cffc50b86d69d38353385dda2e1aecde20ad947ea19f469bcff951772
3
+ metadata.gz: 2807fe3efdfb17de59b50713359ba58097f36482389f1d4089056103d16be154
4
+ data.tar.gz: 8366edb466dda73e67a553084b7b96e97f42c03e4cdb8dc2509e2edacd2f1d3b
5
5
  SHA512:
6
- metadata.gz: fed9e078491c756e1461ae4c5592f3ff0b07b3037b12dea35488e5ea63f241321ae81b404acd49156cf8240edffa177ebc5bc89ce681cf75b6e3d14a4d27cd9a
7
- data.tar.gz: 8819c1f9a5dab412bf6e676eeea9c493b4d2f4e8442d9b7fe99777973955d6c178f7cfc33c7991d56b9574566d926bcac95169f80faa08d4c9c51a7d0bfddd6d
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."
@@ -29,7 +34,11 @@ class SlackProcessor < Processor
29
34
  end
30
35
 
31
36
  def processReviews(reviews, platform)
32
- reviews.each_slice(10) do |reviewGroup|
37
+
38
+ pendingPayloads = []
39
+
40
+ # Slack Message Limit: posting one message per second per channel
41
+ reviews.each_slice(attachmentGroupByNumber) do |reviewGroup|
33
42
  payload = Payload.new()
34
43
  payload.attachments = []
35
44
 
@@ -55,10 +64,22 @@ class SlackProcessor < Processor
55
64
  payload.attachments.append(attachment)
56
65
  end
57
66
 
67
+ pendingPayloads.append(payload)
68
+ end
69
+
70
+ loop do
71
+ payload = pendingPayloads.pop
72
+
58
73
  result = request(payload)
59
- if result["ok"] != true
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
@@ -87,14 +108,18 @@ class SlackProcessor < Processor
87
108
 
88
109
  private
89
110
  def request(payload)
111
+
112
+ isInCommingWebHook = false
90
113
  if !botToken.nil? && botToken != ""
91
114
  uri = URI("https://slack.com/api/chat.postMessage")
92
115
  payload.channel = targetChannel
93
116
  headers = {'Content-Type': 'application/json; charset=utf-8', 'Authorization': "Bearer #{botToken}"}
117
+ isInCommingWebHook = false
94
118
  else
95
119
  uri = URI(inCommingWebHookURL)
96
120
  payload.channel = nil
97
121
  headers = {'Content-Type': 'application/json; charset=utf-8'}
122
+ isInCommingWebHook = true
98
123
  end
99
124
 
100
125
  http = Net::HTTP.new(uri.host, uri.port)
@@ -102,7 +127,14 @@ class SlackProcessor < Processor
102
127
  req = Net::HTTP::Post.new(uri.request_uri, headers)
103
128
  req.body = payload.to_json
104
129
  res = http.request(req)
105
- JSON.parse(res.body)
130
+
131
+ if isInCommingWebHook
132
+ return {"ok":res.body == "ok", "message":nil}
133
+ else
134
+ result = JSON.parse(res.body)
135
+ return {"ok":result["ok"] == true, "message":result['error']}
136
+ end
137
+
106
138
  end
107
139
 
108
140
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZReviewTender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi