kennel 1.91.2 → 1.92.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78b7b57805cf2c4730b6a1320342240fe03e9cf786f07380210bb558361b7192
4
- data.tar.gz: e56d5211430862f20dc92e4d3538be0befdd630a401bf1605de064b6ab9468b8
3
+ metadata.gz: 1e94541bcdef70aa7074e902576e22ffff456e11f04c55bed2567f2074273f38
4
+ data.tar.gz: 2eb1d620e5a4dfe57041e8252d06746ff5bb067aa6d0e375093278218e09662a
5
5
  SHA512:
6
- metadata.gz: 2631017430f4d33639317f56be0d639d1d60cf33e568f5b0b4f8031a4cc0d981ca2cc793a18864049cdfc7bb3cf9d852a8ca5f90e6a37779faa37a5cafdb3212
7
- data.tar.gz: 9fa908dd061892c13b40e5cf1ab1de7d406ec7a99ed6a718c1cadee5ca5ecd17ec72e8c498c3b4bdf977542a51e1871fbb743e2b4296bcc5d0d071be6aba7d3c
6
+ metadata.gz: 3404e5804b142f2f96b35ceaf9d51f3e7fb5c6e29c2573ef603f090e04653d77cd201081147c272d0648f0fac24f532b3a648d356755faa3973364997193367a
7
+ data.tar.gz: d8dcc7f3ea50824d6cbff9c3e29b83ecfd59559f25345e2ad7b468dea30f8423703879b9517823bc565d4e15b3a2fbb55f6c88a4727a20b98292f12958a17e3f
@@ -8,13 +8,15 @@ module Kennel
8
8
  class << self
9
9
  def report(token, &block)
10
10
  return yield unless token
11
- new(token, Utils.capture_sh("git rev-parse HEAD").strip).report(&block)
11
+ new(token).report(&block)
12
12
  end
13
13
  end
14
14
 
15
- def initialize(token, git_sha)
15
+ def initialize(token, ref: "HEAD")
16
16
  @token = token
17
- @git_sha = git_sha
17
+ commit = Utils.capture_sh("git show #{ref}")
18
+ @sha = commit[/^Merge: \S+ (\S+)/, 1] || commit[/\Acommit (\S+)/, 1] || raise("Unable to find commit")
19
+ @pr = commit[/^\s+.*\(#(\d+)\)/, 1] # from squash
18
20
  @repo_part = ENV["GITHUB_REPOSITORY"] || begin
19
21
  origin = ENV["PROJECT_REPOSITORY"] || Utils.capture_sh("git remote -v").split("\n").first
20
22
  origin[%r{github\.com[:/](\S+?)(\.git|$)}, 1] || raise("no origin found in #{origin}")
@@ -37,13 +39,14 @@ module Kennel
37
39
  body = body.byteslice(0, MAX_COMMENT_SIZE - TRUNCATED_MSG.bytesize) + TRUNCATED_MSG
38
40
  end
39
41
 
40
- post "commits/#{@git_sha}/comments", body: body
42
+ path = (@pr ? "/repos/#{@repo_part}/issues/#{@pr}/comments" : "/repos/#{@repo_part}/commits/#{@sha}/comments")
43
+ post path, body: body
41
44
  end
42
45
 
43
46
  private
44
47
 
45
48
  def post(path, data)
46
- url = "https://api.github.com/repos/#{@repo_part}/#{path}"
49
+ url = "https://api.github.com#{path}"
47
50
  response = Faraday.post(url, data.to_json, authorization: "token #{@token}")
48
51
  raise "failed to POST to github:\n#{url} -> #{response.status}\n#{response.body}" unless response.status == 201
49
52
  end
@@ -106,10 +106,11 @@ module Kennel
106
106
  end
107
107
 
108
108
  # new api format is very verbose, so use old dry format when possible
109
+ # dd randomly chooses query0 or query1
109
110
  def convert_widget_to_compact_format!(widget)
110
111
  (widget.dig(:definition, :requests) || []).each do |request|
111
112
  next unless request.is_a?(Hash)
112
- next if request[:formulas] && request[:formulas] != [{ formula: "query1" }]
113
+ next if request[:formulas] && ![[{ formula: "query1" }], [{ formula: "query0" }]].include?(request[:formulas])
113
114
  next if request[:queries]&.size != 1
114
115
  next if request[:queries].any? { |q| q[:data_source] != "metrics" }
115
116
  next if widget.dig(:definition, :type) != request[:response_format]
@@ -46,7 +46,6 @@ module Kennel
46
46
  font_size: "14"
47
47
  },
48
48
  "query_value" => {
49
- autoscale: true,
50
49
  time: {},
51
50
  title_align: "left",
52
51
  title_size: "16"
data/lib/kennel/syncer.rb CHANGED
@@ -3,6 +3,7 @@ module Kennel
3
3
  class Syncer
4
4
  DELETE_ORDER = ["dashboard", "slo", "monitor", "synthetics/tests"].freeze # dashboards references monitors + slos, slos reference monitors
5
5
  LINE_UP = "\e[1A\033[K" # go up and clear
6
+ DEFAULT_BRANCH = "master"
6
7
 
7
8
  def initialize(api, expected, project: nil)
8
9
  @api = api
@@ -26,11 +27,7 @@ module Kennel
26
27
  def confirm
27
28
  return false if noop?
28
29
  return true if ENV["CI"] || !STDIN.tty?
29
- if @delete.any? && @project_filter
30
- Kennel.out.puts(
31
- Utils.color(:red, "WARNING: deleting resources that had `id: -> { ...` breaks master branch")
32
- )
33
- end
30
+ warn_about_deleting_resources_with_id if @project_filter
34
31
  Utils.ask("Execute Plan ?")
35
32
  end
36
33
 
@@ -63,6 +60,30 @@ module Kennel
63
60
 
64
61
  private
65
62
 
63
+ # this is brittle/hacky since it relies on knowledge from the generation + git + branch knowledge
64
+ def warn_about_deleting_resources_with_id
65
+ @delete.each do |_, _, a|
66
+ tracking_id = a.fetch(:tracking_id)
67
+ api_resource = a.fetch(:klass).api_resource
68
+
69
+ file = "generated/#{tracking_id.sub(":", "/")}.json"
70
+ old = `true && git show #{DEFAULT_BRANCH}:#{file.shellescape} 2>&1` # true && to not crash on missing git
71
+
72
+ next unless $?.success?
73
+ old =
74
+ begin
75
+ JSON.parse(old)
76
+ rescue StandardError
77
+ false
78
+ end
79
+ next if !old || !old["id"]
80
+
81
+ Kennel.out.puts(
82
+ Utils.color(:red, "WARNING: deleting #{api_resource} #{tracking_id} will break #{DEFAULT_BRANCH} branch")
83
+ )
84
+ end
85
+ end
86
+
66
87
  # loop over items until everything is resolved or crash when we get stuck
67
88
  # this solves cases like composite monitors depending on each other or monitor->monitor slo->slo monitor chains
68
89
  def each_resolved(list)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.91.2"
3
+ VERSION = "1.92.2"
4
4
  end
data/lib/kennel.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require "faraday"
3
3
  require "json"
4
+ require "shellwords"
4
5
  require "English"
5
6
 
6
7
  require "kennel/version"
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: 1.91.2
4
+ version: 1.92.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-15 00:00:00.000000000 Z
11
+ date: 2021-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday