├── .ruby-version ├── Procfile ├── config.ru ├── Gemfile ├── config └── rainbow.rb ├── app.json ├── README.md ├── .gitignore ├── Gemfile.lock ├── LICENSE └── app.rb /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.2.2 2 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: bundle exec rainbows -p $PORT -c ./config/rainbow.rb 2 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | unless $LOAD_PATH.include? "." 2 | $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) 3 | end 4 | 5 | require 'app' 6 | 7 | run App.new 8 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem "sinatra" 4 | gem "rainbows" 5 | gem "eventmachine" 6 | 7 | 8 | gem "yajl-ruby" 9 | gem "librato-metrics" 10 | 11 | -------------------------------------------------------------------------------- /config/rainbow.rb: -------------------------------------------------------------------------------- 1 | worker_processes 2 # amount of rainbow workers to spin up 2 | timeout 15 # restarts workers that hang for 30 seconds 3 | preload_app true # reduce mem footprint 4 | 5 | Rainbows! do 6 | use :EventMachine 7 | end 8 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "librato-github-annotate", 3 | "description": "Add deployment annotation to librato.", 4 | "repository": "https://github.com/polydice/librato-github-annotate", 5 | "env": { 6 | "LIBRATO_EMAIL": { 7 | "description": "Your librato email." 8 | }, 9 | "LIBRATO_API_KEY": { 10 | "description": "Your librato API key." 11 | }, 12 | "ANNOTATION_NAME": { 13 | "description": "Metrix name in librato", 14 | "value": "deployment" 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # librato-github-annotate 2 | 3 | Add deployment annotation to Librato with your GitHub-flow. 4 | 5 | ## Usage 6 | 7 | This app is designed to be used and deployed on Heroku. 8 | 9 | Set the following ENV variables during deployment: 10 | 11 | * `LIBRATO_EMAIL` 12 | * `LIBRATO_API_KEY` 13 | * `ANNOTATION_NAME` 14 | 15 | Once you've done, you can add `/annotate/:source` as GitHub webhook with `deployment_status` event enabled. 16 | 17 | Deploy it right now! 18 | 19 | [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy) 20 | 21 | ## License 22 | 23 | MIT License. See LICENSE for details. 24 | 25 | Copyright (c) 2015 [Polydice, Inc.](http://polydice.com) 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | /.config 4 | /coverage/ 5 | /InstalledFiles 6 | /pkg/ 7 | /spec/reports/ 8 | /test/tmp/ 9 | /test/version_tmp/ 10 | /tmp/ 11 | 12 | ## Specific to RubyMotion: 13 | .dat* 14 | .repl_history 15 | build/ 16 | 17 | ## Documentation cache and generated files: 18 | /.yardoc/ 19 | /_yardoc/ 20 | /doc/ 21 | /rdoc/ 22 | 23 | ## Environment normalisation: 24 | /.bundle/ 25 | /vendor/bundle 26 | /lib/bundler/man/ 27 | 28 | # for a library or gem, you might want to ignore these files since the code is 29 | # intended to run in multiple environments; otherwise, check them in: 30 | # Gemfile.lock 31 | # .ruby-version 32 | # .ruby-gemset 33 | 34 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 35 | .rvmrc 36 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | aggregate (0.2.2) 5 | eventmachine (1.0.7) 6 | faraday (0.9.1) 7 | multipart-post (>= 1.2, < 3) 8 | kgio (2.9.3) 9 | librato-metrics (1.5.0) 10 | aggregate (~> 0.2.2) 11 | faraday (~> 0.7) 12 | multi_json 13 | multi_json (1.11.0) 14 | multipart-post (2.0.0) 15 | rack (1.6.1) 16 | rack-protection (1.5.3) 17 | rack 18 | rainbows (4.6.2) 19 | kgio (~> 2.5) 20 | rack (~> 1.1) 21 | unicorn (~> 4.8) 22 | raindrops (0.13.0) 23 | sinatra (1.4.6) 24 | rack (~> 1.4) 25 | rack-protection (~> 1.4) 26 | tilt (>= 1.3, < 3) 27 | tilt (2.0.1) 28 | unicorn (4.9.0) 29 | kgio (~> 2.6) 30 | rack 31 | raindrops (~> 0.7) 32 | yajl-ruby (1.2.1) 33 | 34 | PLATFORMS 35 | ruby 36 | 37 | DEPENDENCIES 38 | eventmachine 39 | librato-metrics 40 | rainbows 41 | sinatra 42 | yajl-ruby 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Polydice, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /app.rb: -------------------------------------------------------------------------------- 1 | require "bundler" 2 | require "json" 3 | 4 | Bundler.require 5 | 6 | class App < Sinatra::Application 7 | configure do 8 | disable :method_override 9 | disable :static 10 | 11 | Librato::Metrics.authenticate ENV["LIBRATO_EMAIL"], ENV["LIBRATO_API_KEY"] 12 | end 13 | 14 | post "/annotate/:name" do 15 | payload = JSON.parse(request.body.read) 16 | state = payload["deployment_status"]["state"] 17 | 18 | if state != "pending" 19 | repo = payload["repository"]["full_name"] 20 | creator = payload["deployment"]["creator"]["login"] 21 | start_time = Time.parse(payload["deployment"]["created_at"]) 22 | end_time = Time.parse(payload["deployment_status"]["created_at"]) 23 | 24 | sha = payload["deployment"]["sha"] 25 | ref = payload["deployment"]["ref"] 26 | log_url = payload["deployment_status"]["target_url"] 27 | 28 | links = [{ 29 | rel: "github", 30 | label: "GitHub Commit", 31 | href: "https://github.com/#{repo}/commit/#{sha}" 32 | }] 33 | 34 | if log_url && !log_url.empty? 35 | links << { 36 | rel: "heaven", 37 | label: "Heaven Deployment Log", 38 | href: log_url 39 | } 40 | end 41 | 42 | Librato::Metrics.annotate ENV["ANNOTATION_NAME"], "#{ref}", 43 | start_time: start_time, end_time: end_time, 44 | description: "#{creator} deployed #{sha}", 45 | links: links, source: params[:name] 46 | return 200 47 | else 48 | return 404 49 | end 50 | end 51 | end 52 | --------------------------------------------------------------------------------