doggy 2.0.17 → 2.0.18

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: bb97cb24320519a7bba30b15a873051f5948728c
4
- data.tar.gz: 327e1a6e44d4fcec59eccca3ad057587a6000604
3
+ metadata.gz: 8fffcdb181744f9d0f48b41877151bb8c39e4ed9
4
+ data.tar.gz: 576233b7f36fe9004d89f40caaa84c2dec38e5b9
5
5
  SHA512:
6
- metadata.gz: 07b2acceb8064210cb05db56b6544155a2228f7d2bc679dcbd6c773346dc436e91ad93c2400ffa344db0ab4c59ee4d9c395b93e547f29e90ccbf1bb1916e2e71
7
- data.tar.gz: f0beada455921ce51d6b4b5a387654bcf352edef0b0810988a88b91428aebc08584340f1ffa13cafedb20b8a100698bb4f3fb08946a7cbd8d5d276dfad6d87b7
6
+ metadata.gz: d4299cf9f9f02e9649c7c4e5df28f5a32e470e3ba7f49668e4523d51b5816138d972a66446311a1c6affd5562d864f5926c0526221bdb86ac299a33f7e1225dc
7
+ data.tar.gz: 8ab7493ec5d0c58b8925d393200364b457bc8fe2db40626a85a4f9c5c6e44b09cd405a1e5053d7e77cb970cb0997c54ccf6bd483806e119f971f6b5ba5f0acdb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- doggy (2.0.16)
4
+ doggy (2.0.18)
5
5
  json (~> 1.8.3)
6
6
  parallel (~> 1.6.1)
7
7
  rugged (~> 0.23.2)
@@ -2,37 +2,61 @@
2
2
 
3
3
  module Doggy
4
4
  class CLI::Pull
5
- def initialize(options, ids)
6
- @options = options
7
- @ids = ids
8
- @updated_by_last_action = false
5
+ def initialize(options, ids_or_names)
6
+ @options = options
7
+ @ids_or_names = ids_or_names
9
8
  end
10
9
 
11
10
  def run
12
- pull_resources('dashboards', Models::Dashboard, @ids) if should_pull?('dashboards')
13
- pull_resources('monitors', Models::Monitor, @ids) if should_pull?('monitors')
14
- pull_resources('screens', Models::Screen, @ids) if should_pull?('screens')
11
+ if @ids_or_names.empty?
12
+ pull_resources('dashboards', Models::Dashboard)
13
+ pull_resources('monitors', Models::Monitor)
14
+ pull_resources('screens', Models::Screen)
15
+ return
16
+ end
15
17
 
16
- Doggy.ui.say "Nothing to pull: please specify object ID or use '-a' to pull everything" unless @updated_by_last_action
18
+ @ids_or_names.each do |id_or_name|
19
+ @local_resources = Doggy::Model.all_local_resources
20
+ if id_or_name =~ /^\d+$/
21
+ pull_by_id(id_or_name.to_i)
22
+ else
23
+ pull_by_file(id_or_name)
24
+ end
25
+ end
17
26
  end
18
27
 
19
28
  private
20
29
 
21
- def should_pull?(resource)
22
- !@options.empty? || @options[resource] || @ids.any?
23
- end
30
+ def pull_by_id(id)
31
+ local_resource = @local_resources.find { |l| l.id == id }
32
+ if !local_resource
33
+ remote_resource = [Models::Dashboard, Models::Monitor, Models::Screen].map do |klass|
34
+ klass.find(id)
35
+ end.compact.first
24
36
 
25
- def pull_resources(name, klass, ids)
26
- if ids.any?
27
- Doggy.ui.say "Pulling #{ name }: #{ids.join(', ')}"
28
- remote_resources = klass.all.find_all { |m| ids.include?(m.id.to_s) }
37
+ remote_resource.save_local
29
38
  else
30
- Doggy.ui.say "Pulling #{ name }"
31
- remote_resources = klass.all
39
+ remote_resource = local_resource.class.find(local_resource.id)
40
+ remote_resource.path = local_resource.path
41
+ remote_resource.save_local
32
42
  end
43
+ end
44
+
45
+ def pull_by_file(file)
46
+ resolved_path = Doggy.resolve_path(file)
47
+ local_resource = @local_resources.find { |l| l.path == resolved_path }
48
+
49
+ remote_resource = local_resource.class.find(local_resource.id)
50
+ remote_resource.path = local_resource.path
51
+ remote_resource.save_local
52
+ end
53
+
54
+ def pull_resources(name, klass)
55
+ Doggy.ui.say "Pulling #{ name }..."
33
56
  local_resources = klass.all_local
57
+ remote_resources = klass.all
58
+
34
59
  klass.assign_paths(remote_resources, local_resources)
35
- @updated_by_last_action = true
36
60
  remote_resources.each(&:save_local)
37
61
  end
38
62
  end
data/lib/doggy/model.rb CHANGED
@@ -56,6 +56,12 @@ module Doggy
56
56
  Parallel.map(ids) { |id| find(id) }
57
57
  end
58
58
 
59
+ def all_local_resources
60
+ @resources ||= [ Models::Dashboard,
61
+ Models::Monitor,
62
+ Models::Screen ].flat_map(&:all_local)
63
+ end
64
+
59
65
  def all_local(only_changed: false)
60
66
  @all_local ||= begin
61
67
  # TODO: Add serializer support here
@@ -176,6 +182,7 @@ module Doggy
176
182
 
177
183
  def save
178
184
  ensure_managed_emoji!
185
+ ensure_renotify_interval_valid
179
186
 
180
187
  body = JSON.dump(to_h)
181
188
  if !id then
@@ -13,6 +13,7 @@ module Doggy
13
13
  attribute :no_data_timeframe, Integer
14
14
  attribute :timeout_h, Integer
15
15
  attribute :escalation_message, String
16
+ attribute :renotify_interval, Integer
16
17
 
17
18
  def to_h
18
19
  return super unless monitor.id && monitor.loading_source == :local
@@ -58,6 +59,15 @@ module Doggy
58
59
  self.name += " \xF0\x9F\x90\xB6"
59
60
  end
60
61
 
62
+ def ensure_renotify_interval_valid
63
+ return unless options && options.renotify_interval && options.renotify_interval.to_i > 0
64
+
65
+ allowed_renotify_intervals = [10,20,30,40,50,60,90,120,180,240,300,360,720,1440] # minutes
66
+ best_matching_interval = allowed_renotify_intervals.min_by { |x| (x.to_f - options.renotify_interval).abs }
67
+ puts "WARN: Monitor #{self.id} uses invalid escalation interval (renotify_interval) #{options.renotify_interval}, using #{best_matching_interval} instead"
68
+ options.renotify_interval = best_matching_interval
69
+ end
70
+
61
71
  def mute
62
72
  return unless id
63
73
  request(:post, "#{ resource_url(id) }/mute")
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.17"
4
+ VERSION = "2.0.18"
5
5
  end
data/lib/doggy.rb CHANGED
@@ -57,19 +57,28 @@ module Doggy
57
57
 
58
58
  def modified(compare_to, all = false)
59
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
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
+
72
+ def resolve_path(path)
73
+ path = Pathname.new(path)
74
+ curr_dir = Pathname.new(Dir.pwd)
75
+ resolved = object_root.relative_path_from(curr_dir)
76
+
77
+ (curr_dir.expand_path(resolved + path) + path).to_s
70
78
  end
71
79
 
72
- protected
80
+
81
+ protected
73
82
 
74
83
  def secrets
75
84
  @secrets ||= begin
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.17
4
+ version: 2.0.18
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-27 00:00:00.000000000 Z
12
+ date: 2015-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json