peak_flow_utils 0.1.11 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/peak_flow_utils/application_controller.rb +6 -1
- data/app/controllers/peak_flow_utils/pings/postgres_connections_controller.rb +10 -0
- data/app/controllers/peak_flow_utils/pings/sidekiq_controller.rb +13 -0
- data/app/services/peak_flow_utils/database_initializer_service.rb +3 -3
- data/app/services/peak_flow_utils/deep_merger.rb +45 -0
- data/app/services/peak_flow_utils/handlers_finder_service.rb +2 -2
- data/app/services/peak_flow_utils/translations_parser_service.rb +3 -3
- data/config/routes.rb +4 -0
- data/lib/peak_flow_utils/migrations/{20150907090900_create_handlers.rb → 20150907070908_create_handlers.rb} +0 -0
- data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/application_record.rb +0 -0
- data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/group.rb +0 -0
- data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/handler.rb +0 -0
- data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/handler_text.rb +0 -0
- data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/scanned_file.rb +0 -0
- data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/translation_key.rb +0 -0
- data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/translation_value.rb +0 -0
- data/lib/peak_flow_utils/notifier.rb +62 -5
- data/lib/peak_flow_utils/notifier_rack.rb +6 -6
- data/lib/peak_flow_utils/notifier_response.rb +6 -2
- data/lib/peak_flow_utils/version.rb +1 -1
- data/lib/peak_flow_utils.rb +10 -2
- metadata +17 -25
- data/app/assets/config/peak_flow_utils_manifest.js +0 -2
- data/app/assets/javascripts/peak_flow_utils/application.js +0 -14
- data/app/assets/stylesheets/peak_flow_utils/application.css +0 -15
- data/app/controllers/peak_flow_utils/pings/sidekiq_pings_controller.rb +0 -10
- data/app/helpers/peak_flow_utils/application_helper.rb +0 -2
- data/app/jobs/peak_flow_utils/application_job.rb +0 -2
- data/app/mailers/peak_flow_utils/application_mailer.rb +0 -4
- data/app/views/layouts/peak_flow_utils/application.html.erb +0 -14
- data/bin/peak_flow_rspec_files +0 -21
- data/lib/peak_flow_utils/rspec_helper.rb +0 -195
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4fb7a276f751a58ba19b74e73955323e0f1b89215312b50ee3e3b9cf89a85f4
|
4
|
+
data.tar.gz: 29edd9b2f4225cf2ea74c67d4fccd1b21a0149781f2cacc168309ef8dd3082c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18328934879ae9fbb148e812926d68b5dca82837f929e5c3f3228bc4bc34bb140e8d42013333ef68976931819960d45110b26a8bf8bb2b37e363b8a519bf0ee9
|
7
|
+
data.tar.gz: 4251f1f1213fc0e9dfa426c7c4a1e75c53dbd23dff37ce09213f857ff7b7fba56251875d17a7baed74273d744f29b03bd9fa3e41f7a877319ada3cf9760bf9b4
|
@@ -7,7 +7,12 @@ private
|
|
7
7
|
|
8
8
|
def authenticate
|
9
9
|
authenticate_or_request_with_http_basic do |username, password|
|
10
|
-
|
10
|
+
if ENV["PEAKFLOW_PINGS_USERNAME"].blank? || ENV["PEAKFLOW_PINGS_PASSWORD"].blank?
|
11
|
+
Rails.logger.error "Peakflow utils: Pings called but PEAKFLOW_PINGS_USERNAME or PEAKFLOW_PINGS_PASSWORD wasn't set"
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
username == ENV.fetch("PEAKFLOW_PINGS_USERNAME") && password == ENV.fetch("PEAKFLOW_PINGS_PASSWORD")
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class PeakFlowUtils::Pings::PostgresConnectionsController < PeakFlowUtils::ApplicationController
|
2
|
+
def count
|
3
|
+
postgres_connections_count = ActiveRecord::Base.connection.execute("SELECT SUM(numbackends) AS connections_count FROM pg_stat_database").to_a.first
|
4
|
+
|
5
|
+
render json: {
|
6
|
+
check_json_status: "OK",
|
7
|
+
postgres_connections_count: postgres_connections_count.fetch("connections_count")
|
8
|
+
}
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "sidekiq/api"
|
2
|
+
|
3
|
+
class PeakFlowUtils::Pings::SidekiqController < PeakFlowUtils::ApplicationController
|
4
|
+
def index
|
5
|
+
sidekiq_queue = Sidekiq::Queue.new
|
6
|
+
|
7
|
+
render json: {
|
8
|
+
check_json_status: "OK",
|
9
|
+
latency: sidekiq_queue.latency,
|
10
|
+
queue_size: sidekiq_queue.size
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class PeakFlowUtils::DatabaseInitializerService < PeakFlowUtils::ApplicationService
|
2
|
-
def
|
3
|
-
path = File.realpath("#{
|
2
|
+
def perform
|
3
|
+
path = File.realpath("#{__dir__}/../../../lib/peak_flow_utils/migrations")
|
4
4
|
create_schema_table unless schema_table_exists?
|
5
5
|
|
6
6
|
Dir["#{path}/[0-9]*_*.rb"].sort.map do |filename|
|
@@ -22,7 +22,7 @@ class PeakFlowUtils::DatabaseInitializerService < PeakFlowUtils::ApplicationServ
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def create_schema_table
|
25
|
-
PeakFlowUtils::ApplicationRecord.connection.execute("CREATE TABLE schema_migrations (version
|
25
|
+
PeakFlowUtils::ApplicationRecord.connection.execute("CREATE TABLE schema_migrations (version VARCHAR)")
|
26
26
|
end
|
27
27
|
|
28
28
|
def register_migration_migrated(version)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class PeakFlowUtils::DeepMerger < PeakFlowUtils::ApplicationService
|
2
|
+
def initialize(hashes:)
|
3
|
+
@hashes = hashes
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
merged = {}
|
8
|
+
|
9
|
+
@hashes.each do |hash|
|
10
|
+
merge_hash(hash, merged)
|
11
|
+
end
|
12
|
+
|
13
|
+
succeed! merged
|
14
|
+
end
|
15
|
+
|
16
|
+
def merge_something(object, merged)
|
17
|
+
if object.is_a?(Array)
|
18
|
+
merge_array(object, merged)
|
19
|
+
elsif object.is_a?(Hash)
|
20
|
+
merge_hash(object, merged)
|
21
|
+
else
|
22
|
+
raise "Unknown object: #{object.class.name}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def merge_array(array, merged)
|
27
|
+
array.each do |value|
|
28
|
+
merged << value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def merge_hash(hash, merged)
|
33
|
+
hash.each do |key, value|
|
34
|
+
if !merged.key?(key)
|
35
|
+
merged[key] = value
|
36
|
+
elsif value.is_a?(Array)
|
37
|
+
merge_array(value, merged[key])
|
38
|
+
elsif value.is_a?(Hash)
|
39
|
+
merge_hash(value, merged[key])
|
40
|
+
else
|
41
|
+
raise "Unknown object: #{object.class.name}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class PeakFlowUtils::HandlersFinderService < PeakFlowUtils::ApplicationService
|
2
|
-
def
|
2
|
+
def perform
|
3
3
|
handlers = []
|
4
4
|
|
5
|
-
Dir.foreach("#{
|
5
|
+
Dir.foreach("#{__dir__}/../../handlers/peak_flow_utils") do |file|
|
6
6
|
match = file.match(/\A(.+)_handler\.rb\Z/)
|
7
7
|
next unless match
|
8
8
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class PeakFlowUtils::TranslationsParserService < PeakFlowUtils::ApplicationService
|
2
2
|
attr_reader :db
|
3
3
|
|
4
|
-
def
|
4
|
+
def perform
|
5
5
|
PeakFlowUtils::DatabaseInitializerService.execute!
|
6
6
|
|
7
7
|
cache_translations_in_dir(Rails.root.join("config/locales"))
|
@@ -103,11 +103,11 @@ private
|
|
103
103
|
puts message.to_s if @debug # rubocop:disable Rails/Output
|
104
104
|
end
|
105
105
|
|
106
|
-
def
|
106
|
+
def perform_migrations
|
107
107
|
require "baza_migrations"
|
108
108
|
|
109
109
|
executor = BazaMigrations::MigrationsExecutor.new(db: @db)
|
110
|
-
executor.add_dir "#{
|
110
|
+
executor.add_dir "#{__dir__}/../../db/baza_translations_migrations"
|
111
111
|
executor.execute_migrations
|
112
112
|
end
|
113
113
|
|
data/config/routes.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class PeakFlowUtils::Notifier
|
2
|
+
class FailedToReportError < RuntimeError; end
|
2
3
|
class NotConfiguredError < RuntimeError; end
|
3
4
|
|
4
5
|
attr_reader :auth_token
|
@@ -8,13 +9,46 @@ class PeakFlowUtils::Notifier
|
|
8
9
|
end
|
9
10
|
|
10
11
|
def self.current
|
11
|
-
raise PeakFlowUtils::Notifier::NotConfiguredError, "Hasn't been configured"
|
12
|
+
raise PeakFlowUtils::Notifier::NotConfiguredError, "Hasn't been configured" if !@current && Rails.env.test?
|
12
13
|
|
13
14
|
@current
|
14
15
|
end
|
15
16
|
|
16
|
-
def self.
|
17
|
-
PeakFlowUtils::Notifier.
|
17
|
+
def self.current_parameters(parameters: nil)
|
18
|
+
hashes = PeakFlowUtils::Notifier.current_parameters_hashes
|
19
|
+
hashes << parameters if parameters
|
20
|
+
|
21
|
+
PeakFlowUtils::DeepMerger.execute!(hashes: hashes)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.current_parameters_hashes
|
25
|
+
hashes = []
|
26
|
+
|
27
|
+
Thread.current[:peakflow_utils] ||= {}
|
28
|
+
Thread.current[:peakflow_utils].dig(:notifier, :with_parameters)&.each_value do |more_parameters|
|
29
|
+
hashes << more_parameters
|
30
|
+
end
|
31
|
+
|
32
|
+
hashes
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.notify(*args, **opts, &blk)
|
36
|
+
PeakFlowUtils::Notifier.current.notify(*args, **opts, &blk)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.with_parameters(parameters)
|
40
|
+
random_id = SecureRandom.hex(16)
|
41
|
+
|
42
|
+
Thread.current[:peakflow_utils] ||= {}
|
43
|
+
Thread.current[:peakflow_utils][:notifier] ||= {}
|
44
|
+
Thread.current[:peakflow_utils][:notifier][:with_parameters] ||= {}
|
45
|
+
Thread.current[:peakflow_utils][:notifier][:with_parameters][random_id] = parameters
|
46
|
+
|
47
|
+
begin
|
48
|
+
yield
|
49
|
+
ensure
|
50
|
+
Thread.current[:peakflow_utils][:notifier][:with_parameters].delete(random_id)
|
51
|
+
end
|
18
52
|
end
|
19
53
|
|
20
54
|
def initialize(auth_token:)
|
@@ -28,6 +62,8 @@ class PeakFlowUtils::Notifier
|
|
28
62
|
error: error
|
29
63
|
)
|
30
64
|
|
65
|
+
merged_parameters = PeakFlowUtils::Notifier.current_parameters(parameters: parameters)
|
66
|
+
|
31
67
|
uri = URI("https://www.peakflow.io/errors/reports")
|
32
68
|
|
33
69
|
https = Net::HTTP.new(uri.host, uri.port)
|
@@ -42,7 +78,7 @@ class PeakFlowUtils::Notifier
|
|
42
78
|
file_path: error_parser.file_path,
|
43
79
|
line_number: error_parser.line_number,
|
44
80
|
message: error.message,
|
45
|
-
parameters:
|
81
|
+
parameters: merged_parameters,
|
46
82
|
remote_ip: error_parser.remote_ip,
|
47
83
|
url: error_parser.url,
|
48
84
|
user_agent: error_parser.user_agent
|
@@ -54,8 +90,29 @@ class PeakFlowUtils::Notifier
|
|
54
90
|
request.body = JSON.generate(data)
|
55
91
|
|
56
92
|
response = https.request(request)
|
93
|
+
|
94
|
+
raise FailedToReportError, error_message_from_response(response) unless response.code == "200"
|
95
|
+
|
57
96
|
response_data = JSON.parse(response.body)
|
58
97
|
|
59
|
-
|
98
|
+
# Data not always present so dont use fetch
|
99
|
+
PeakFlowUtils::NotifierResponse.new(
|
100
|
+
bug_report_id: response_data["bug_report_id"],
|
101
|
+
bug_report_instance_id: response_data["bug_report_instance_id"],
|
102
|
+
project_id: response_data["project_id"],
|
103
|
+
project_slug: response_data["project_slug"],
|
104
|
+
url: response_data["url"]
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
def error_message_from_response(response)
|
109
|
+
message = "Couldn't report error to Peakflow (code #{response.code})"
|
110
|
+
|
111
|
+
if response["content-type"]&.starts_with?("application/json")
|
112
|
+
response_data = JSON.parse(response.body)
|
113
|
+
message << ": #{response_data.fetch("errors").join(". ")}" if response_data["errors"]
|
114
|
+
end
|
115
|
+
|
116
|
+
message
|
60
117
|
end
|
61
118
|
end
|
@@ -9,13 +9,13 @@ class PeakFlowUtils::NotifierRack
|
|
9
9
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
10
10
|
controller = env["action_controller.instance"]
|
11
11
|
request = controller&.request
|
12
|
-
parameters = {}.merge(request.GET).merge(request.POST)
|
13
12
|
|
14
|
-
PeakFlowUtils::Notifier.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
PeakFlowUtils::Notifier.with_parameters(rack: {get: request.GET, post: request.POST}) do
|
14
|
+
PeakFlowUtils::Notifier.notify(
|
15
|
+
environment: env,
|
16
|
+
error: e
|
17
|
+
)
|
18
|
+
end
|
19
19
|
|
20
20
|
raise e
|
21
21
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
class PeakFlowUtils::NotifierResponse
|
2
|
-
attr_reader :url
|
2
|
+
attr_reader :bug_report_id, :bug_report_instance_id, :project_id, :project_slug, :url
|
3
3
|
|
4
|
-
def initialize(url:)
|
4
|
+
def initialize(bug_report_id:, bug_report_instance_id:, project_id:, project_slug:, url:)
|
5
|
+
@bug_report_id = bug_report_id
|
6
|
+
@bug_report_instance_id = bug_report_instance_id
|
7
|
+
@project_id = project_id
|
8
|
+
@project_slug = project_slug
|
5
9
|
@url = url
|
6
10
|
end
|
7
11
|
end
|
data/lib/peak_flow_utils.rb
CHANGED
@@ -4,7 +4,8 @@ require "array_enumerator"
|
|
4
4
|
require "service_pattern"
|
5
5
|
|
6
6
|
module PeakFlowUtils
|
7
|
-
path = "#{
|
7
|
+
path = "#{__dir__}/peak_flow_utils"
|
8
|
+
models_path = "#{__dir__}/peak_flow_utils/models"
|
8
9
|
|
9
10
|
autoload :Notifier, "#{path}/notifier"
|
10
11
|
autoload :NotifierErrorParser, "#{path}/notifier_error_parser"
|
@@ -12,6 +13,13 @@ module PeakFlowUtils
|
|
12
13
|
autoload :NotifierRails, "#{path}/notifier_rails"
|
13
14
|
autoload :NotifierResponse, "#{path}/notifier_response"
|
14
15
|
autoload :NotifierSidekiq, "#{path}/notifier_sidekiq"
|
15
|
-
autoload :RspecHelper, "#{path}/rspec_helper"
|
16
16
|
autoload :HandlerHelper, "#{path}/handler_helper"
|
17
|
+
|
18
|
+
autoload :ApplicationRecord, "#{models_path}/application_record"
|
19
|
+
autoload :Group, "#{models_path}/group"
|
20
|
+
autoload :HandlerText, "#{models_path}/handler_text"
|
21
|
+
autoload :Handler, "#{models_path}/handler"
|
22
|
+
autoload :ScannedFile, "#{models_path}/scanned_file"
|
23
|
+
autoload :TranslationKey, "#{models_path}/translation_key"
|
24
|
+
autoload :TranslationValue, "#{models_path}/translation_value"
|
17
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peak_flow_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaspernj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.0.5
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 1.0.5
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: redis
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,19 +111,16 @@ dependencies:
|
|
111
111
|
description: Utilities to be used with PeakFlow.
|
112
112
|
email:
|
113
113
|
- kaspernj@gmail.com
|
114
|
-
executables:
|
115
|
-
- peak_flow_rspec_files
|
114
|
+
executables: []
|
116
115
|
extensions: []
|
117
116
|
extra_rdoc_files: []
|
118
117
|
files:
|
119
118
|
- MIT-LICENSE
|
120
119
|
- README.md
|
121
120
|
- Rakefile
|
122
|
-
- app/assets/config/peak_flow_utils_manifest.js
|
123
|
-
- app/assets/javascripts/peak_flow_utils/application.js
|
124
|
-
- app/assets/stylesheets/peak_flow_utils/application.css
|
125
121
|
- app/controllers/peak_flow_utils/application_controller.rb
|
126
|
-
- app/controllers/peak_flow_utils/pings/
|
122
|
+
- app/controllers/peak_flow_utils/pings/postgres_connections_controller.rb
|
123
|
+
- app/controllers/peak_flow_utils/pings/sidekiq_controller.rb
|
127
124
|
- app/handlers/peak_flow_utils/application_handler.rb
|
128
125
|
- app/handlers/peak_flow_utils/devise_handler.rb
|
129
126
|
- app/handlers/peak_flow_utils/file_handler.rb
|
@@ -132,21 +129,12 @@ files:
|
|
132
129
|
- app/handlers/peak_flow_utils/simple_form_handler.rb
|
133
130
|
- app/handlers/peak_flow_utils/validations_handler.rb
|
134
131
|
- app/handlers/peak_flow_utils/will_paginate_handler.rb
|
135
|
-
- app/helpers/peak_flow_utils/application_helper.rb
|
136
|
-
- app/jobs/peak_flow_utils/application_job.rb
|
137
|
-
- app/mailers/peak_flow_utils/application_mailer.rb
|
138
|
-
- app/models/peak_flow_utils/application_record.rb
|
139
|
-
- app/models/peak_flow_utils/group.rb
|
140
|
-
- app/models/peak_flow_utils/handler.rb
|
141
|
-
- app/models/peak_flow_utils/handler_text.rb
|
142
|
-
- app/models/peak_flow_utils/scanned_file.rb
|
143
|
-
- app/models/peak_flow_utils/translation_key.rb
|
144
|
-
- app/models/peak_flow_utils/translation_value.rb
|
145
132
|
- app/services/peak_flow_utils/application_migration.rb
|
146
133
|
- app/services/peak_flow_utils/application_service.rb
|
147
134
|
- app/services/peak_flow_utils/attribute_service.rb
|
148
135
|
- app/services/peak_flow_utils/configuration_service.rb
|
149
136
|
- app/services/peak_flow_utils/database_initializer_service.rb
|
137
|
+
- app/services/peak_flow_utils/deep_merger.rb
|
150
138
|
- app/services/peak_flow_utils/erb_inspector.rb
|
151
139
|
- app/services/peak_flow_utils/erb_inspector/file_inspector.rb
|
152
140
|
- app/services/peak_flow_utils/erb_inspector/translation_inspector.rb
|
@@ -155,25 +143,29 @@ files:
|
|
155
143
|
- app/services/peak_flow_utils/model_inspector.rb
|
156
144
|
- app/services/peak_flow_utils/translation_service.rb
|
157
145
|
- app/services/peak_flow_utils/translations_parser_service.rb
|
158
|
-
- app/views/layouts/peak_flow_utils/application.html.erb
|
159
|
-
- bin/peak_flow_rspec_files
|
160
146
|
- config/routes.rb
|
161
147
|
- lib/peak_flow_utils.rb
|
162
148
|
- lib/peak_flow_utils/engine.rb
|
163
149
|
- lib/peak_flow_utils/handler_helper.rb
|
164
150
|
- lib/peak_flow_utils/migrations/20150902155200_create_translation_keys.rb
|
151
|
+
- lib/peak_flow_utils/migrations/20150907070908_create_handlers.rb
|
165
152
|
- lib/peak_flow_utils/migrations/20150907070909_create_groups.rb
|
166
|
-
- lib/peak_flow_utils/migrations/20150907090900_create_handlers.rb
|
167
153
|
- lib/peak_flow_utils/migrations/20150908085500_create_translation_values.rb
|
168
154
|
- lib/peak_flow_utils/migrations/20150908090800_create_handler_texts.rb
|
169
155
|
- lib/peak_flow_utils/migrations/20160411190500_create_scanned_files.rb
|
156
|
+
- lib/peak_flow_utils/models/application_record.rb
|
157
|
+
- lib/peak_flow_utils/models/group.rb
|
158
|
+
- lib/peak_flow_utils/models/handler.rb
|
159
|
+
- lib/peak_flow_utils/models/handler_text.rb
|
160
|
+
- lib/peak_flow_utils/models/scanned_file.rb
|
161
|
+
- lib/peak_flow_utils/models/translation_key.rb
|
162
|
+
- lib/peak_flow_utils/models/translation_value.rb
|
170
163
|
- lib/peak_flow_utils/notifier.rb
|
171
164
|
- lib/peak_flow_utils/notifier_error_parser.rb
|
172
165
|
- lib/peak_flow_utils/notifier_rack.rb
|
173
166
|
- lib/peak_flow_utils/notifier_rails.rb
|
174
167
|
- lib/peak_flow_utils/notifier_response.rb
|
175
168
|
- lib/peak_flow_utils/notifier_sidekiq.rb
|
176
|
-
- lib/peak_flow_utils/rspec_helper.rb
|
177
169
|
- lib/peak_flow_utils/version.rb
|
178
170
|
- lib/tasks/peak_flow_utils_tasks.rake
|
179
171
|
homepage: https://github.com/kaspernj/peak_flow_utils
|
@@ -195,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
187
|
- !ruby/object:Gem::Version
|
196
188
|
version: '0'
|
197
189
|
requirements: []
|
198
|
-
rubygems_version: 3.
|
190
|
+
rubygems_version: 3.2.32
|
199
191
|
signing_key:
|
200
192
|
specification_version: 4
|
201
193
|
summary: Utilities to be used with PeakFlow.
|
@@ -1,14 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
-
//
|
10
|
-
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
-
// about supported directives.
|
12
|
-
//
|
13
|
-
//= require activestorage
|
14
|
-
//= require_tree .
|
@@ -1,15 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
-
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
-
* It is generally better to create a new file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Peak flow utils</title>
|
5
|
-
<%= stylesheet_link_tag "peak_flow_utils/application", media: "all" %>
|
6
|
-
<%= javascript_include_tag "peak_flow_utils/application" %>
|
7
|
-
<%= csrf_meta_tags %>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
<%= yield %>
|
12
|
-
|
13
|
-
</body>
|
14
|
-
</html>
|
data/bin/peak_flow_rspec_files
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# This task detects and prints out the RSpec files for the current build group
|
4
|
-
|
5
|
-
require "#{File.dirname(__FILE__)}/../lib/peak_flow_utils"
|
6
|
-
|
7
|
-
args = {}
|
8
|
-
ARGV.each do |arg|
|
9
|
-
if (match = arg.match(/\A--(.+?)=(.+)\Z/))
|
10
|
-
args[match[1]] = match[2]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
rspec_helper = PeakFlowUtils::RspecHelper.new(
|
15
|
-
groups: args.fetch("groups").to_i,
|
16
|
-
group_number: args.fetch("group-number").to_i,
|
17
|
-
only_types: args["only-types"]&.split(","),
|
18
|
-
tags: args["tags"]&.split(",")
|
19
|
-
)
|
20
|
-
|
21
|
-
print rspec_helper.group_files.map { |group_file| group_file.fetch(:path) }.join(" ")
|
@@ -1,195 +0,0 @@
|
|
1
|
-
class PeakFlowUtils::RspecHelper
|
2
|
-
attr_reader :only_types, :tags
|
3
|
-
|
4
|
-
def initialize(groups:, group_number:, only_types: nil, tags: nil)
|
5
|
-
@groups = groups
|
6
|
-
@group_number = group_number
|
7
|
-
@example_data_exists = File.exist?("spec/examples.txt")
|
8
|
-
@only_types = only_types
|
9
|
-
@tags = tags
|
10
|
-
end
|
11
|
-
|
12
|
-
def example_data_exists?
|
13
|
-
@example_data_exists
|
14
|
-
end
|
15
|
-
|
16
|
-
def example_data
|
17
|
-
@example_data ||= begin
|
18
|
-
raw_data = File.read("spec/examples.txt")
|
19
|
-
|
20
|
-
result = []
|
21
|
-
raw_data.scan(/^\.\/(.+)\[(.+?)\]\s+\|\s+(.+?)\s+\|\s+((.+?) seconds|)\s+\|$/) do |match|
|
22
|
-
file_path = match[0]
|
23
|
-
spec_result = match[1]
|
24
|
-
seconds = match[4]&.to_f
|
25
|
-
|
26
|
-
spec_data = {
|
27
|
-
file_path: file_path,
|
28
|
-
spec_result: spec_result,
|
29
|
-
seconds: seconds
|
30
|
-
}
|
31
|
-
|
32
|
-
result << spec_data
|
33
|
-
end
|
34
|
-
|
35
|
-
result
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def example_files
|
40
|
-
@example_files ||= begin
|
41
|
-
files = {}
|
42
|
-
example_data.each do |spec_data|
|
43
|
-
file_path = spec_data.fetch(:file_path)
|
44
|
-
seconds = spec_data.fetch(:seconds)
|
45
|
-
|
46
|
-
files[file_path] ||= {examples: 0, seconds: 0.0}
|
47
|
-
files[file_path][:examples] += 1
|
48
|
-
files[file_path][:seconds] += seconds if seconds
|
49
|
-
end
|
50
|
-
|
51
|
-
files
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def example_file(path)
|
56
|
-
example_files[path]
|
57
|
-
end
|
58
|
-
|
59
|
-
def group_files
|
60
|
-
return @group_files if @group_files
|
61
|
-
|
62
|
-
sorted_files.each do |file|
|
63
|
-
file_path = file.fetch(:path)
|
64
|
-
file_data = example_file(file_path) if example_data_exists?
|
65
|
-
|
66
|
-
if file_data
|
67
|
-
examples = file_data.fetch(:examples)
|
68
|
-
seconds = file_data.fetch(:seconds)
|
69
|
-
else
|
70
|
-
examples = file.fetch(:examples)
|
71
|
-
end
|
72
|
-
|
73
|
-
group = group_with_least
|
74
|
-
group[:examples] += examples
|
75
|
-
group[:files] << file
|
76
|
-
group[:seconds] += seconds if seconds
|
77
|
-
end
|
78
|
-
|
79
|
-
@group_files = group_orders[@group_number - 1].fetch(:files)
|
80
|
-
end
|
81
|
-
|
82
|
-
def group_orders
|
83
|
-
@group_orders ||= begin
|
84
|
-
group_orders = []
|
85
|
-
@groups.times do
|
86
|
-
group_orders << {
|
87
|
-
examples: 0,
|
88
|
-
files: [],
|
89
|
-
seconds: 0.0
|
90
|
-
}
|
91
|
-
end
|
92
|
-
group_orders
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def group_with_least
|
97
|
-
group_orders.min do |group1, group2|
|
98
|
-
if example_data_exists? && group1.fetch(:seconds) != 0.0 && group2.fetch(:seconds) != 0.0
|
99
|
-
group1.fetch(:seconds) <=> group2.fetch(:seconds)
|
100
|
-
else
|
101
|
-
group1.fetch(:examples) <=> group2.fetch(:examples)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
# Sort them so that they are sorted by file path in three groups so each group have an equal amount of controller specs, features specs and so on
|
107
|
-
def sorted_files
|
108
|
-
files.values.sort do |file1, file2|
|
109
|
-
file1_path = file1.fetch(:path)
|
110
|
-
file2_path = file2.fetch(:path)
|
111
|
-
|
112
|
-
file1_data = example_file(file1_path) if example_data_exists?
|
113
|
-
file2_data = example_file(file2_path) if example_data_exists?
|
114
|
-
|
115
|
-
if file1_data && file2_data && file1_data.fetch(:seconds) != 0.0 && file2_data.fetch(:seconds) != 0.0
|
116
|
-
value1 = file1_data[:seconds]
|
117
|
-
else
|
118
|
-
value1 = file1.fetch(:points)
|
119
|
-
end
|
120
|
-
|
121
|
-
if file2_data && file1_data && file2_data.fetch(:seconds) != 0.0 && file2_data.fetch(:seconds) != 0.0
|
122
|
-
value2 = file2_data[:seconds]
|
123
|
-
else
|
124
|
-
value2 = file2.fetch(:points)
|
125
|
-
end
|
126
|
-
|
127
|
-
if value1 == value2
|
128
|
-
value2 = file1_path
|
129
|
-
value1 = file2_path
|
130
|
-
end
|
131
|
-
|
132
|
-
value2 <=> value1
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
private
|
137
|
-
|
138
|
-
def dry_result_command
|
139
|
-
command = "bundle exec rspec --dry-run --format json"
|
140
|
-
|
141
|
-
tags&.each do |tag|
|
142
|
-
command << " --tag #{tag}"
|
143
|
-
end
|
144
|
-
|
145
|
-
command
|
146
|
-
end
|
147
|
-
|
148
|
-
def dry_result
|
149
|
-
require "json"
|
150
|
-
@dry_result ||= ::JSON.parse(`#{dry_result_command}`)
|
151
|
-
end
|
152
|
-
|
153
|
-
def dry_file(path)
|
154
|
-
files.fetch(path)
|
155
|
-
end
|
156
|
-
|
157
|
-
def files
|
158
|
-
@files ||= begin
|
159
|
-
result = {}
|
160
|
-
dry_result.fetch("examples").each do |example|
|
161
|
-
file_path = example.fetch("file_path")
|
162
|
-
file_path = file_path[2, file_path.length]
|
163
|
-
type = type_from_path(file_path)
|
164
|
-
points = points_from_type(type)
|
165
|
-
|
166
|
-
next if ignore_type?(type)
|
167
|
-
|
168
|
-
result[file_path] = {examples: 0, path: file_path, points: 0, type: type} unless result.key?(file_path)
|
169
|
-
result[file_path][:examples] += 1
|
170
|
-
result[file_path][:points] += points
|
171
|
-
end
|
172
|
-
|
173
|
-
result
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
def ignore_type?(type)
|
178
|
-
only_types && !only_types.include?(type) # rubocop:disable Rails/NegateInclude:, Style/SafeNavigation
|
179
|
-
end
|
180
|
-
|
181
|
-
def type_from_path(file_path)
|
182
|
-
match = file_path.match(/^spec\/(.+?)\//)
|
183
|
-
match[1] if match
|
184
|
-
end
|
185
|
-
|
186
|
-
def points_from_type(type)
|
187
|
-
if type == "feature" || type == "system"
|
188
|
-
10
|
189
|
-
elsif type == "controllers"
|
190
|
-
3
|
191
|
-
else
|
192
|
-
1
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|