Class: Lita::Handlers::DeployTracker
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::DeployTracker
- Defined in:
- lib/lita/handlers/deploy_tracker.rb
Instance Method Summary collapse
- #check_deploy_in_progress(payload) ⇒ Object
- #define_routes(payload) ⇒ Object
- #get_deploys_in_progress(response) ⇒ Object
- #get_last_deploys(response) ⇒ Object
- #register_deploy(payload) ⇒ Object
- #update_deploy(payload) ⇒ Object
Instance Method Details
#check_deploy_in_progress(payload) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/lita/handlers/deploy_tracker.rb', line 59 def check_deploy_in_progress(payload) db = mongo_client # db[:deploys].drop result = db[:deploys].find({app: payload[:app], area: payload[:area], env: payload[:env], status: 'in progress'}).limit(1).count if result > 0 payload[:msg] = 'Já existe um deploy dessa aplicação sendo '\ 'executado nessa area. Aguarde ele ser finalizado' robot.trigger(:deploy_aborted, payload) else robot.trigger(:deploy_checked, payload) end end |
#define_routes(payload) ⇒ Object
16 17 18 |
# File 'lib/lita/handlers/deploy_tracker.rb', line 16 def define_routes(payload) define_static_routes end |
#get_deploys_in_progress(response) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/lita/handlers/deploy_tracker.rb', line 78 def get_deploys_in_progress(response) target = response..source.room_object db = mongo_client deploys = [] result = db[:deploys].find(status: 'in progress') if result.count == 0 return response.reply("No deploy in progress") end result.each do |doc| deploys << Adapters::Slack::Attachment.new( "", title: "Deploy #{doc[:app]} in progress", fields: [ { title: "App", value: doc[:app], short: true }, { title: "Área", value: doc[:area], short: true }, { title: "Ambiente", value: doc[:env], short: true }, { title: "tag", value: doc[:tag], short: true }, { title: "responsible", value: doc[:responsible], short: true } ] ) end return robot.chat_service.(target, deploys) end |
#get_last_deploys(response) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/lita/handlers/deploy_tracker.rb', line 123 def get_last_deploys(response) target = response..source.room_object app = response.args[3] area = response.args[4] db = mongo_client result = db[:deploys].find({app: app, area: area}).limit(5) if result.count == 0 return response.reply("No previous deployments of the app #{app} #{area}") end deploys = [] result.each do |doc| deploys << Adapters::Slack::Attachment.new( "", title: "Deploy #{doc[:app]}", fields: [ { title: "App", value: doc[:app], short: true }, { title: "Área", value: doc[:area], short: true }, { title: "Ambiente", value: doc[:env], short: true }, { title: "tag", value: doc[:tag], short: true }, { title: "responsible", value: doc[:responsible], short: true } ] ) end return robot.chat_service.(target, deploys) end |
#register_deploy(payload) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lita/handlers/deploy_tracker.rb', line 20 def register_deploy(payload) db = mongo_client db[:deploys].insert_one ({ app: payload[:app], area: payload[:area], env: payload[:env], tag: payload[:tag], responsible: payload[:responsible], start_time: payload[:start_time], status: 'in progress' }) end |
#update_deploy(payload) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lita/handlers/deploy_tracker.rb', line 34 def update_deploy(payload) db = mongo_client db[:deploys].update_one({ app: payload[:app], area: payload[:area], env: payload[:env], tag: payload[:tag], responsible: payload[:responsible], start_time: payload[:start_time] }, { app: payload[:app], area: payload[:area], env: payload[:env], tag: payload[:tag], responsible: payload[:responsible], start_time: payload[:start_time], finish_time: payload[:finish_time], status: payload[:status] }) db[:deploys].find().each do |doc| end end |