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 +4 -4
- data/lib/Processors/SlackProcessor.rb +36 -4
- 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."
         | 
| @@ -29,7 +34,11 @@ class SlackProcessor < Processor | |
| 29 34 | 
             
                end
         | 
| 30 35 |  | 
| 31 36 | 
             
                def processReviews(reviews, platform)
         | 
| 32 | 
            -
             | 
| 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[ | 
| 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 | 
            -
             | 
| 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
         |