kennel 1.91.3 → 1.92.3

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
  SHA256:
3
- metadata.gz: 7a85c311024f48c14e9e346eb863a47fbb67239f5d83cd82eddea6f53742ec74
4
- data.tar.gz: 672ef53f76ee577f9f976ee9432f06f1e56d426bef74020d50850863e851635a
3
+ metadata.gz: a3460bf3995d61817a7d7db0ad209012cb6cd51b1d5ba6767f4d20bc1766243f
4
+ data.tar.gz: 6a70c8e91c2bbf3e67db5f157e3c7f85d4025d2494d04026f9e7dc2007635217
5
5
  SHA512:
6
- metadata.gz: 8407d6564013f12ce1e00e1394eb742b7f721fe9302396d821c8c3441c62e4e30781b9681f430dcedb96e3c757a740b9604a2c56194afabdabd69ed52f8c1a27
7
- data.tar.gz: efceaa72bc4ff084e1d8bd54ed79dbcaa021d6a95897fa66465dbec686b0712f05a153198b3c882029df08812b93353ed3061c34c5f4c5f1303b826bc3d17711
6
+ metadata.gz: 6d3554ec738b404eb6ef6ff6e32120b86d3e65d399c7a5c0ff9c828e3beecf066fb441d941f077b9537c50347b1c5694b54d94e1c4f1d1ba19bacb5afcb1af57
7
+ data.tar.gz: d3eb584c0b15e04e38021324ce5e861740c2660f978cf9f413635a6a76fc8a4f82bba09a07343e12b0821f4b56f098fe39a8387013ffbb287065281b54bbeca5
@@ -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
@@ -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)
data/lib/kennel/tasks.rb CHANGED
@@ -48,7 +48,7 @@ namespace :kennel do
48
48
  url = Kennel::Utils.path_to_url "/account/settings"
49
49
  puts "Invalid mentions found, either ignore them by adding to `KNOWN` env var or add them via #{url}"
50
50
  bad.each { |f, v| puts "Invalid mention #{v} in monitor message of #{f}" }
51
- Kennel::Tasks.abort
51
+ Kennel::Tasks.abort ENV["KNOWN_WARNING"]
52
52
  end
53
53
  end
54
54
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.91.3"
3
+ VERSION = "1.92.3"
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.3
4
+ version: 1.92.3
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-17 00:00:00.000000000 Z
11
+ date: 2021-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday