forked from Shopify/doggy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
664 additions
and
961 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: ruby | ||
rvm: | ||
- 2.2.2 | ||
before_install: gem install bundler -v 1.10.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Contributor Code of Conduct | ||
|
||
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. | ||
|
||
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. | ||
|
||
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in doggy.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
require "bundler/gem_tasks" | ||
require "rake/testtask" | ||
|
||
Rake::TestTask.new do |t| | ||
t.libs << 'test' | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << "test" | ||
t.libs << "lib" | ||
t.test_files = FileList['test/**/*_test.rb'] | ||
end | ||
|
||
desc "Run tests" | ||
task :default => :test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ set -euo pipefail | |
IFS=$'\n\t' | ||
|
||
bundle install | ||
|
||
# Do any other automated setup that you need to do here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,23 +6,33 @@ require 'doggy/version' | |
Gem::Specification.new do |spec| | ||
spec.name = "doggy" | ||
spec.version = Doggy::VERSION | ||
spec.authors = ["Vlad Gorodetsky"] | ||
spec.email = ["[email protected]"] | ||
spec.authors = ["Vlad Gorodetsky", "Andre Medeiros"] | ||
spec.email = ["[email protected]", "[email protected]"] | ||
|
||
spec.summary = %q{Syncs DataDog dashboards, alerts, screenboards, and monitors.} | ||
spec.description = %q{Syncs DataDog dashboards, alerts, screenboards, and monitors.} | ||
spec.homepage = "http://github.com/bai/doggy" | ||
spec.license = "MIT" | ||
|
||
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or | ||
# delete this section to allow pushing this gem to any host. | ||
if spec.respond_to?(:metadata) | ||
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'" | ||
else | ||
raise "RubyGems 2.0 or newer is required to protect against public gem pushes." | ||
end | ||
|
||
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } | ||
spec.bindir = "exe" | ||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_development_dependency "bundler", "~> 1.9" | ||
spec.add_dependency "json", "~> 1.8.3" | ||
spec.add_dependency "parallel", "~> 1.6.1" | ||
spec.add_dependency "thor", "~> 0.19.1" | ||
spec.add_dependency "virtus", "~> 1.0.5" | ||
|
||
spec.add_development_dependency "bundler", "~> 1.10" | ||
spec.add_development_dependency "rake", "~> 10.0" | ||
spec.add_dependency "thor", "~> 0.19" | ||
spec.add_dependency "dogapi", "~> 1.17" | ||
spec.add_dependency "thread", "~> 0.2" | ||
spec.add_dependency "ejson", "~> 1.0" | ||
spec.add_development_dependency "minitest" | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,4 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# Exit cleanly from an early interrupt | ||
Signal.trap('INT') { exit 1 } | ||
|
||
require 'bundler/setup' | ||
require 'doggy/friendly_errors' | ||
|
||
Doggy.with_friendly_errors do | ||
require 'doggy/cli' | ||
Doggy::CLI.start(ARGV, :debug => true) | ||
end | ||
require "doggy" | ||
Doggy::CLI.start(ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,63 @@ | ||
require 'fileutils' | ||
require 'pathname' | ||
require 'json' | ||
require 'yaml' | ||
require 'dogapi' | ||
|
||
require 'doggy/friendly_errors' | ||
|
||
require 'doggy/version' | ||
require 'doggy/errors' | ||
require 'doggy/shared_helpers' | ||
require 'doggy/client' | ||
require 'doggy/worker' | ||
require 'doggy/definition' | ||
require 'doggy/dsl' | ||
require 'doggy/serializer/json' | ||
require 'doggy/serializer/yaml' | ||
require 'doggy/model/dash' | ||
require 'doggy/model/monitor' | ||
require 'doggy/model/screen' | ||
require "pathname" | ||
require "net/http" | ||
|
||
require "doggy/cli" | ||
require "doggy/cli/edit" | ||
require "doggy/cli/mute" | ||
require "doggy/cli/pull" | ||
require "doggy/cli/push" | ||
require "doggy/cli/unmute" | ||
require "doggy/model" | ||
require "doggy/models/dashboard" | ||
require "doggy/models/monitor" | ||
require "doggy/models/screen" | ||
require "doggy/version" | ||
|
||
module Doggy | ||
DOG_SKIP_REGEX = /😱|:scream:/i.freeze | ||
MANAGED_BY_DOGGY_REGEX = /🐶|\:dog\:/i.freeze | ||
DEFAULT_SERIALIZER_CLASS = Doggy::Serializer::Json | ||
DOG_SKIP_REGEX = /\xF0\x9F\x98\xB1|:scream:/i.freeze | ||
MANAGED_BY_DOGGY_REGEX = /\xF0\x9F\x90\xB6|:dog:/i.freeze | ||
|
||
class << self | ||
# @option arguments [Constant] :serializer A specific serializer class to use, will be initialized by doggy and passed the object instance | ||
def serializer(options = {}) | ||
@serializer ||= options[:serializer] ? options[:serializer] : DEFAULT_SERIALIZER_CLASS | ||
end | ||
extend self | ||
|
||
def client | ||
Doggy::Client.new | ||
end | ||
def ui | ||
(defined?(@ui) && @ui) || (self.ui = Thor::Shell::Color.new) | ||
end | ||
|
||
def objects_path | ||
@objects_path ||= Pathname.new('objects').expand_path(SharedHelpers.find_root).expand_path.tap { |path| FileUtils.mkdir_p(path) } | ||
end | ||
def ui=(ui) | ||
@ui = ui | ||
end | ||
|
||
def load_item(f) | ||
item = case File.extname(f) | ||
when '.yaml', '.yml' then Doggy::Serializer::Yaml.load(File.read(f)) | ||
when '.json' then Doggy::Serializer::Json.load(File.read(f)) | ||
when '.rb' then Doggy::Dsl.evaluate(f).obj | ||
else raise InvalidItemType | ||
end | ||
def object_root | ||
@object_root ||= Pathname.new('objects').expand_path(repo_root) | ||
end | ||
|
||
# Hackery to support legacy dash format | ||
{ | ||
[ | ||
determine_type(item), item['id'] || item['dash']['id'] | ||
] => item['dash'] ? item['dash'] : item | ||
} | ||
end | ||
def repo_root | ||
# TODO: Raise error when root can't be found | ||
current_dir = Dir.pwd | ||
|
||
def edit(id_or_filename) | ||
if id_or_filename =~ /json|yml|yaml/ | ||
item_from_filename = Doggy.load_item(Doggy.objects_path.join(id_or_filename)) | ||
id = item_from_filename.keys[0][1] | ||
while current_dir != '/' do | ||
if File.exists?(File.join(current_dir, 'Gemfile')) then | ||
return Pathname.new(current_dir) | ||
else | ||
id = id_or_filename | ||
current_dir = File.expand_path('../', current_dir) | ||
end | ||
|
||
object = (item_from_filename || all_local_items).detect { |(type, object_id), object| object_id.to_s == id.to_s } | ||
if object && object[0] && object[0][0] && type = object[0][0].sub(/^[a-z\d]*/) { $&.capitalize } | ||
Object.const_get("Doggy::#{type}").edit(id) | ||
end | ||
end | ||
|
||
def determine_type(item) | ||
return 'dash' if item['graphs'] || item['dash'] | ||
return 'monitor' if item['message'] | ||
return 'screen' if item['board_title'] | ||
raise InvalidItemType | ||
end | ||
end | ||
|
||
def emit_shipit_deployment | ||
Doggy.client.dog.emit_event( | ||
Dogapi::Event.new(ENV['REVISION'], msg_title: "ShipIt Deployment by #{ENV['USER']}", tags: %w(audit shipit), source_type_name: 'shipit') | ||
) | ||
rescue => e | ||
puts "Exception: #{e.message}" | ||
end | ||
def api_key | ||
ENV['DATADOG_API_KEY'] || secrets['datadog_api_key'] | ||
end | ||
|
||
def current_sha | ||
now = Time.now.to_i | ||
month_ago = now - 3600 * 24 * 30 | ||
events = Doggy.client.dog.stream(month_ago, now, tags: %w(audit shipit))[1]['events'] | ||
def application_key | ||
ENV['DATADOG_APP_KEY'] || secrets['datadog_app_key'] | ||
end | ||
|
||
events[0]['text'] # most recetly deployed SHA | ||
rescue => e | ||
puts "Exception: #{e.message}" | ||
end | ||
protected | ||
|
||
def all_local_items | ||
@all_local_items ||= Dir[Doggy.objects_path.join('**/*')].inject({}) do |memo, file| | ||
next if File.directory?(file) | ||
memo.merge!(load_item(file)) | ||
end | ||
end | ||
def secrets | ||
@secrets ||= begin | ||
raw = File.read(repo_root.join('secrets.json')) | ||
JSON.parse(raw) | ||
end | ||
end | ||
end | ||
end # Doggy |
Oops, something went wrong.