Module: Afterlife::Notify
- Defined in:
- lib/afterlife/notify.rb
Class Method Summary collapse
- .call(repository, branch) ⇒ Object
- .notification_url ⇒ Object
- .send_request(repository, branch) ⇒ Object
Class Method Details
.call(repository, branch) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/afterlife/notify.rb', line 9 def call(repository, branch) return if notification_url.empty? response = send_request(repository, branch) return if response.code == '200' fail Error, "The deploy notification URL returned a #{response.code} status code, " \ 'and the notification may not have been sent.' end |
.notification_url ⇒ Object
21 22 23 24 25 26 |
# File 'lib/afterlife/notify.rb', line 21 def notification_url @notification_url ||= ENV.fetch('AFTERLIFE_DEPLOY_NOTIFICATION_URL', nil) \ || Afterlife.config.deploy_notification_url \ || Afterlife.current_repo.conf.dig(:deploy, :deploy_notification_url) \ || '' end |
.send_request(repository, branch) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/afterlife/notify.rb', line 28 def send_request(repository, branch) uri = URI(notification_url) body = { branch: branch, repository: repository, } headers = { 'Content-Type': 'application/json' } Net::HTTP.post(uri, body.to_json, headers) end |