kennel 0.3.0 → 1.0.0

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
- SHA1:
3
- metadata.gz: 1d04df6004bdc388dbb4ceed94c05e013cfee900
4
- data.tar.gz: 160234c0a44f19c710fd498ffcd1a457a0526b07
2
+ SHA256:
3
+ metadata.gz: 7f7cba17e46fe78338b0f7dea6acb87e245953879f215bf3f3186e55fddaf6af
4
+ data.tar.gz: 5b5320d4a392c264be866e053f3acf6bffc092a3067e17c906a547063ecae747
5
5
  SHA512:
6
- metadata.gz: e728b8ed2c4e9d2e3a4acc1c524c473cc12daadda8864f29ab48e6a8df1a1a67db2ab38c62c1e05b1312ebd20af230b6e3f2dffb17294917f6029d0019a329ad
7
- data.tar.gz: dc95e835d9fff8aecbcf15042449ab84d921e970f55cbe36875d4055180cb78f7d78b1f5537d6a9c5c45308f6c293d7d6e8de3972097ce9ef682f8f7578db216
6
+ metadata.gz: 450193433fd81c3fb283a976dfa5a6dd283561dede4db4f3bc0c1b2d84800d631ef26c7e6c7a5dd8aeacb1a73d4e6f876d65225bc38fa860b2e2803d485facae
7
+ data.tar.gz: 44a48ca74e20669d61b2b7a5b38e4d2b36c8f556f33bb624ebba3cdbb9df507d5b6b14345c422004295aa7962e35fcbf3a18b105bf1e91430277cc62f205b93d
@@ -44,11 +44,6 @@ module Kennel
44
44
  syncer.update if syncer.confirm
45
45
  end
46
46
 
47
- def report_plan_to_github
48
- reporter = GithubReporter.new(ENV.fetch("GITHUB_TOKEN"))
49
- reporter.report { plan }
50
- end
51
-
52
47
  private
53
48
 
54
49
  def syncer
@@ -63,9 +58,13 @@ module Kennel
63
58
  @generated ||= begin
64
59
  Progress.progress "Generating" do
65
60
  load_all
66
- Models::Project.recursive_subclasses.flat_map do |project_class|
61
+ parts = Models::Project.recursive_subclasses.flat_map do |project_class|
67
62
  project_class.new.parts
68
63
  end
64
+ parts.map(&:tracking_id).group_by { |id| id }.select do |id, same|
65
+ raise "#{id} is defined #{same.size} times" if same.size != 1
66
+ end
67
+ parts
69
68
  end
70
69
  end
71
70
  end
@@ -32,12 +32,28 @@ module Kennel
32
32
  def request(method, path, body: nil, params: {})
33
33
  params = params.merge(application_key: @app_key, api_key: @api_key)
34
34
  query = Faraday::FlatParamsEncoder.encode(params)
35
- response = @client.send(method, "#{path}?#{query}") do |request|
36
- request.body = JSON.generate(body) if body
37
- request.headers["Content-type"] = "application/json"
35
+ response = nil
36
+
37
+ 2.times do |i|
38
+ response = @client.send(method, "#{path}?#{query}") do |request|
39
+ request.body = JSON.generate(body) if body
40
+ request.headers["Content-type"] = "application/json"
41
+ end
42
+ break if i == 1 || method != :get || response.status != 500
43
+ end
44
+
45
+ unless response.success?
46
+ message = +"Error #{response.status} during #{method.upcase} #{path}\n"
47
+ message << "request:\n#{JSON.pretty_generate(body)}\nresponse:\n" if body
48
+ message << response.body
49
+ raise message
50
+ end
51
+
52
+ if response.body.empty?
53
+ {}
54
+ else
55
+ JSON.parse(response.body, symbolize_names: true)
38
56
  end
39
- raise "Error #{method} #{path} -> #{response.status}:\n#{response.body}" unless response.success?
40
- JSON.parse(response.body, symbolize_names: true)
41
57
  end
42
58
  end
43
59
  end
@@ -1,6 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
3
  class GithubReporter
4
+ class << self
5
+ def report(token, &block)
6
+ return yield unless token
7
+ new(token).report(&block)
8
+ end
9
+ end
10
+
4
11
  def initialize(token)
5
12
  @token = token
6
13
  @git_sha = Utils.capture_sh("git rev-parse HEAD").strip
@@ -8,8 +15,8 @@ module Kennel
8
15
  @repo_part = origin[%r{github\.com[:/](.+?)(\.git|$)}, 1] || raise("no origin found")
9
16
  end
10
17
 
11
- def report
12
- output = Utils.strip_shell_control(Utils.capture_stdout { yield }.strip)
18
+ def report(&block)
19
+ output = Utils.strip_shell_control(Utils.tee_stdout(&block).strip)
13
20
  ensure
14
21
  comment "```\n#{output || "Error"}\n```"
15
22
  end
@@ -66,7 +66,7 @@ module Kennel
66
66
  widgets.map do |widget|
67
67
  widget = widget_defaults(widget[:type]).merge(widget)
68
68
  if tile = widget[:tile_def]
69
- tile[:requests].each { |r| r[:conditional_formats] ||= [] }
69
+ tile.fetch(:requests).each { |r| r[:conditional_formats] ||= [] }
70
70
  tile[:autoscale] = true unless widget[:tile_def].key?(:autoscale)
71
71
  end
72
72
  widget
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require "English"
3
+ require "kennel"
3
4
 
4
5
  namespace :kennel do
5
6
  desc "Ensure there are no uncommited changes that would be hidden from PR reviewers"
@@ -25,24 +26,20 @@ namespace :kennel do
25
26
  Kennel.update
26
27
  end
27
28
 
28
- desc "comment on github commit with planned datadog changes"
29
- task report_plan_to_github: :environment do
30
- Kennel.report_plan_to_github
31
- end
32
-
33
- desc "update if this is a push to the default branch, otherwise report plan"
29
+ desc "update if this is a push to the default branch, otherwise plan (report to github with GITHUB_TOKEN)"
34
30
  task :travis do
35
31
  on_default_branch = (ENV["TRAVIS_BRANCH"] == (ENV["DEFAULT_BRANCH"] || "master"))
36
32
  is_push = (ENV["TRAVIS_PULL_REQUEST"] == "false")
37
33
  task_name =
38
34
  if on_default_branch && is_push
39
35
  "kennel:update_datadog"
40
- elsif ENV["GITHUB_TOKEN"]
41
- "kennel:report_plan_to_github"
42
36
  else
43
- "kennel:plan"
37
+ "kennel:plan" # show plan in travis logs
44
38
  end
45
- Rake::Task[task_name].invoke
39
+
40
+ Kennel::GithubReporter.report(ENV["GITHUB_TOKEN"]) do
41
+ Rake::Task[task_name].invoke
42
+ end
46
43
  end
47
44
 
48
45
  task :environment do
@@ -1,6 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
3
  module Utils
4
+ class TeeIO < IO
5
+ def initialize(ios)
6
+ @ios = ios
7
+ end
8
+
9
+ def write(string)
10
+ @ios.each { |io| io.write string }
11
+ end
12
+ end
13
+
4
14
  class << self
5
15
  def snake_case(string)
6
16
  string.gsub(/::/, "_") # Foo::Bar -> foo_bar
@@ -33,11 +43,22 @@ module Kennel
33
43
  end
34
44
 
35
45
  def capture_stdout
46
+ old = $stdout
36
47
  $stdout = StringIO.new
37
48
  yield
38
49
  $stdout.string
39
50
  ensure
40
- $stdout = STDOUT
51
+ $stdout = old
52
+ end
53
+
54
+ def tee_stdout
55
+ old = $stdout
56
+ string = StringIO.new
57
+ $stdout = TeeIO.new([$stdout, string])
58
+ yield
59
+ string.string
60
+ ensure
61
+ $stdout = old
41
62
  end
42
63
 
43
64
  def capture_sh(command)
@@ -57,11 +78,9 @@ module Kennel
57
78
  def parallel(items)
58
79
  items.map do |item|
59
80
  Thread.new do
60
- begin
61
- yield item
62
- rescue StandardError => e
63
- e
64
- end
81
+ yield item
82
+ rescue StandardError => e
83
+ e
65
84
  end
66
85
  end.map(&:value).each { |i| raise i if i.is_a?(StandardError) }
67
86
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "0.3.0"
3
+ VERSION = "1.0.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kennel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-22 00:00:00.000000000 Z
11
+ date: 2018-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -74,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - ">="
76
76
  - !ruby/object:Gem::Version
77
- version: 2.4.2
77
+ version: 2.5.0
78
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  requirements: []
84
84
  rubyforge_project:
85
- rubygems_version: 2.6.13
85
+ rubygems_version: 2.7.6
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Keep datadog monitors/dashboards/etc in version control, avoid chaotic management