doggy 2.0.6 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9288c44fda11c987bfe247febc5b71ea2ce049f
4
- data.tar.gz: 54fbe2e4dcb403ee10c6bbbac00ed52b4bdde5b0
3
+ metadata.gz: 8cae6cac093c799f7d4f0f597d0ae8430524fd46
4
+ data.tar.gz: 90e37f1b2b5ef5ac43eb422769e6d1bc5463be98
5
5
  SHA512:
6
- metadata.gz: 05a0baa8145a97c16f0cad75c95a89bba09ad9ff3e50c60daa3f1f1b0bc1153530747deca5492c4117e88d76868b73b80a06952d2d547e7b1eebab99f4b1b617
7
- data.tar.gz: 93ae8631d1d2fe30ef76242f7059d0927fe28fbf1f8d1269f21522947821100e0ca8757f3504a19926b497035ca7f6a9312839254d7a6265a056325cef44c4e2
6
+ metadata.gz: c5a47a83410a1b1251e235c2538e5c869d81c44e3d4bbf8788737d6fa0841a9df94873a3fed3aa0b490c5a7191aa77588c6c401ae605ee73dbcd9bd9214c3f85
7
+ data.tar.gz: efd939a051d48eefeaccf2869569eed3947f0d32444ade2f2a23410a14264360d276aa5ff763ee4e4855ac5dcd368b6876878b24ad85637aa23f9ef47678ba63
data/Gemfile.lock CHANGED
@@ -4,6 +4,7 @@ PATH
4
4
  doggy (2.0.6)
5
5
  json (~> 1.8.3)
6
6
  parallel (~> 1.6.1)
7
+ rugged (~> 0.23.2)
7
8
  thor (~> 0.19.1)
8
9
  virtus (~> 1.0.5)
9
10
 
@@ -24,6 +25,7 @@ GEM
24
25
  minitest (5.8.1)
25
26
  parallel (1.6.1)
26
27
  rake (10.4.2)
28
+ rugged (0.23.2)
27
29
  thor (0.19.1)
28
30
  thread_safe (0.3.5)
29
31
  virtus (1.0.5)
data/doggy.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "parallel", "~> 1.6.1"
24
24
  spec.add_dependency "thor", "~> 0.19.1"
25
25
  spec.add_dependency "virtus", "~> 1.0.5"
26
+ spec.add_dependency "rugged", "~> 0.23.2"
26
27
 
27
28
  spec.add_development_dependency "bundler", "~> 1.10"
28
29
  spec.add_development_dependency "rake", "~> 10.0"
@@ -20,7 +20,7 @@ module Doggy
20
20
 
21
21
  def push_resources(name, klass)
22
22
  Doggy.ui.say "Pushing #{ name }"
23
- local_resources = klass.all_local
23
+ local_resources = klass.all_local(only_changed: true)
24
24
  local_resources.each(&:save)
25
25
  end
26
26
  end
data/lib/doggy/model.rb CHANGED
@@ -56,10 +56,14 @@ module Doggy
56
56
  Parallel.map(ids) { |id| find(id) }
57
57
  end
58
58
 
59
- def all_local
59
+ def all_local(only_changed: false)
60
60
  @all_local ||= begin
61
61
  # TODO: Add serializer support here
62
- files = Dir[Doggy.object_root.join("**/*.json")]
62
+ if only_changed
63
+ files = Doggy.modified(Doggy::Model.current_sha).map { |i| Doggy.object_root.join(i).to_s }
64
+ else
65
+ files = Dir[Doggy.object_root.join("**/*.json")]
66
+ end
63
67
  resources = Parallel.map(files) do |file|
64
68
  raw = File.read(file, encoding: 'utf-8')
65
69
 
@@ -90,7 +94,12 @@ module Doggy
90
94
 
91
95
  def request(method, url, body = nil)
92
96
  uri = URI(url)
93
- uri.query = "api_key=#{ Doggy.api_key }&application_key=#{ Doggy.application_key }"
97
+
98
+ if uri.query
99
+ uri.query = "api_key=#{ Doggy.api_key }&application_key=#{ Doggy.application_key }" + '&' + uri.query
100
+ else
101
+ uri.query = "api_key=#{ Doggy.api_key }&application_key=#{ Doggy.application_key }"
102
+ end
94
103
 
95
104
  http = Net::HTTP.new(uri.host, uri.port)
96
105
  http.use_ssl = (uri.scheme == 'https')
@@ -108,6 +117,24 @@ module Doggy
108
117
  JSON.parse(response.body)
109
118
  end
110
119
 
120
+ def current_sha
121
+ now = Time.now.to_i
122
+ month_ago = now - 3600 * 24 * 30
123
+ result = request(:get, "https://app.datadoghq.com/api/v1/events?start=#{ month_ago }&end=#{ now }&tags=audit,shipit")
124
+ result['events'][0]['text'] # most recetly deployed SHA
125
+ end
126
+
127
+ def emit_shipit_deployment
128
+ request(:post, 'https://app.datadoghq.com/api/v1/events', {
129
+ title: "ShipIt Deployment by #{ENV['USER']}",
130
+ text: ENV['REVISION'],
131
+ tags: %w(audit shipit),
132
+ date_happened: Time.now.to_i,
133
+ priority: 'normal',
134
+ source_type_name: 'shipit'
135
+ }.to_json)
136
+ end
137
+
111
138
  protected
112
139
 
113
140
  def resource_url(id = nil)
data/lib/doggy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Doggy
4
- VERSION = "2.0.6"
4
+ VERSION = "2.0.7"
5
5
  end
data/lib/doggy.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "pathname"
4
4
  require "net/http"
5
+ require "rugged"
5
6
 
6
7
  require "doggy/cli"
7
8
  require "doggy/cli/edit"
@@ -54,6 +55,20 @@ module Doggy
54
55
  ENV['DATADOG_APP_KEY'] || secrets['datadog_app_key']
55
56
  end
56
57
 
58
+ def modified(compare_to, all = false)
59
+ @modified ||= begin
60
+ mods = Set.new
61
+ paths = repo.diff(compare_to, 'HEAD').each_delta.map { |delta| delta.new_file[:path] }
62
+ paths.each do |path|
63
+ parts = path.split('/')
64
+ next unless parts[0] =~ /objects/
65
+ next unless File.exist?(path)
66
+ mods << path
67
+ end
68
+ mods
69
+ end
70
+ end
71
+
57
72
  protected
58
73
 
59
74
  def secrets
@@ -62,4 +77,8 @@ protected
62
77
  JSON.parse(raw)
63
78
  end
64
79
  end
80
+
81
+ def repo
82
+ @repo ||= Rugged::Repository.new(Doggy.object_root.parent.to_s)
83
+ end
65
84
  end # Doggy
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doggy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Gorodetsky
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-10-05 00:00:00.000000000 Z
12
+ date: 2015-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -67,6 +67,20 @@ dependencies:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: 1.0.5
70
+ - !ruby/object:Gem::Dependency
71
+ name: rugged
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 0.23.2
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 0.23.2
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: bundler
72
86
  requirement: !ruby/object:Gem::Requirement