Class: RailVerdict::Repair::Packet
- Inherits:
-
Object
- Object
- RailVerdict::Repair::Packet
- Defined in:
- lib/rail_verdict/repair/packet.rb
Constant Summary collapse
- SCHEMA_VERSION =
"1.0"- PACKET_ID_PATTERN =
/\Asha256:[0-9a-f]{64}\z/
Instance Attribute Summary collapse
-
#ai_analysis ⇒ Object
readonly
Returns the value of attribute ai_analysis.
-
#base_revision ⇒ Object
readonly
Returns the value of attribute base_revision.
-
#baseline_state ⇒ Object
readonly
Returns the value of attribute baseline_state.
-
#boundary ⇒ Object
readonly
Returns the value of attribute boundary.
-
#completeness ⇒ Object
readonly
Returns the value of attribute completeness.
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#diff_context ⇒ Object
readonly
Returns the value of attribute diff_context.
-
#evidence ⇒ Object
readonly
Returns the value of attribute evidence.
-
#git_context ⇒ Object
readonly
Returns the value of attribute git_context.
-
#instructions ⇒ Object
readonly
Returns the value of attribute instructions.
-
#merge_base ⇒ Object
readonly
Returns the value of attribute merge_base.
-
#packet_id ⇒ Object
readonly
Returns the value of attribute packet_id.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
-
#rails_context ⇒ Object
readonly
Returns the value of attribute rails_context.
-
#railverdict_version ⇒ Object
readonly
Returns the value of attribute railverdict_version.
-
#source_context ⇒ Object
readonly
Returns the value of attribute source_context.
-
#source_revision ⇒ Object
readonly
Returns the value of attribute source_revision.
-
#success_criteria ⇒ Object
readonly
Returns the value of attribute success_criteria.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#verification ⇒ Object
readonly
Returns the value of attribute verification.
-
#verification_plan ⇒ Object
readonly
Returns the value of attribute verification_plan.
-
#waivers_state ⇒ Object
readonly
Returns the value of attribute waivers_state.
Class Method Summary collapse
- .packet_id_for(fingerprint:, source_revision:, base_revision:, configuration_digest:, baseline_digest:, analyzer_versions:) ⇒ Object
- .validate_hash(hash) ⇒ Object
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ Packet
constructor
A new instance of Packet.
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(**kwargs) ⇒ Packet
Returns a new instance of Packet.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rail_verdict/repair/packet.rb', line 40 def initialize(**kwargs) @packet_id = kwargs.fetch(:packet_id).dup.freeze @created_at = kwargs.fetch(:created_at).dup.freeze @railverdict_version = kwargs.fetch(:railverdict_version).dup.freeze @source_revision = kwargs[:source_revision]&.dup&.freeze @base_revision = kwargs[:base_revision]&.dup&.freeze @merge_base = kwargs[:merge_base]&.dup&.freeze @target = deep_freeze(kwargs.fetch(:target)) @verification = deep_freeze(kwargs.fetch(:verification)) @evidence = deep_freeze(kwargs.fetch(:evidence)) @git_context = deep_freeze(kwargs.fetch(:git_context)) @diff_context = deep_freeze(kwargs.fetch(:diff_context) { { "hunk" => "", "truncated" => false } }) @rails_context = deep_freeze(kwargs.fetch(:rails_context)) @source_context = deep_freeze(kwargs.fetch(:source_context)) @policy = deep_freeze(kwargs.fetch(:policy)) @baseline_state = deep_freeze(kwargs.fetch(:baseline_state)) @waivers_state = deep_freeze(kwargs.fetch(:waivers_state)) @ai_analysis = kwargs[:ai_analysis] ? deep_freeze(kwargs[:ai_analysis]) : nil @verification_plan = deep_freeze(kwargs.fetch(:verification_plan)) @constraints = deep_freeze(kwargs.fetch(:constraints)) @instructions = (kwargs[:instructions] || []).map(&:dup).map(&:freeze).freeze @completeness = deep_freeze(kwargs.fetch(:completeness)) @success_criteria = deep_freeze(kwargs.fetch(:success_criteria)) @boundary = deep_freeze(kwargs.fetch(:boundary)) validate! freeze end |
Instance Attribute Details
#ai_analysis ⇒ Object (readonly)
Returns the value of attribute ai_analysis.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def ai_analysis @ai_analysis end |
#base_revision ⇒ Object (readonly)
Returns the value of attribute base_revision.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def base_revision @base_revision end |
#baseline_state ⇒ Object (readonly)
Returns the value of attribute baseline_state.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def baseline_state @baseline_state end |
#boundary ⇒ Object (readonly)
Returns the value of attribute boundary.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def boundary @boundary end |
#completeness ⇒ Object (readonly)
Returns the value of attribute completeness.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def completeness @completeness end |
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def constraints @constraints end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def created_at @created_at end |
#diff_context ⇒ Object (readonly)
Returns the value of attribute diff_context.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def diff_context @diff_context end |
#evidence ⇒ Object (readonly)
Returns the value of attribute evidence.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def evidence @evidence end |
#git_context ⇒ Object (readonly)
Returns the value of attribute git_context.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def git_context @git_context end |
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def instructions @instructions end |
#merge_base ⇒ Object (readonly)
Returns the value of attribute merge_base.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def merge_base @merge_base end |
#packet_id ⇒ Object (readonly)
Returns the value of attribute packet_id.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def packet_id @packet_id end |
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def policy @policy end |
#rails_context ⇒ Object (readonly)
Returns the value of attribute rails_context.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def rails_context @rails_context end |
#railverdict_version ⇒ Object (readonly)
Returns the value of attribute railverdict_version.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def railverdict_version @railverdict_version end |
#source_context ⇒ Object (readonly)
Returns the value of attribute source_context.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def source_context @source_context end |
#source_revision ⇒ Object (readonly)
Returns the value of attribute source_revision.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def source_revision @source_revision end |
#success_criteria ⇒ Object (readonly)
Returns the value of attribute success_criteria.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def success_criteria @success_criteria end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def target @target end |
#verification ⇒ Object (readonly)
Returns the value of attribute verification.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def verification @verification end |
#verification_plan ⇒ Object (readonly)
Returns the value of attribute verification_plan.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def verification_plan @verification_plan end |
#waivers_state ⇒ Object (readonly)
Returns the value of attribute waivers_state.
33 34 35 |
# File 'lib/rail_verdict/repair/packet.rb', line 33 def waivers_state @waivers_state end |
Class Method Details
.packet_id_for(fingerprint:, source_revision:, base_revision:, configuration_digest:, baseline_digest:, analyzer_versions:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rail_verdict/repair/packet.rb', line 12 def self.packet_id_for(fingerprint:, source_revision:, base_revision:, configuration_digest:, baseline_digest:, analyzer_versions:) payload = { "packet_schema_version" => SCHEMA_VERSION, "fingerprint" => fingerprint, "source_revision" => source_revision, "base_revision" => base_revision, "configuration_digest" => configuration_digest, "baseline_digest" => baseline_digest, "analyzer_versions" => (analyzer_versions || {}).sort.to_h } sorted = payload.keys.sort.to_h { |k| [k, payload[k]] } "sha256:#{Digest::SHA256.hexdigest(JSON.generate(sorted))}" end |
.validate_hash(hash) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/rail_verdict/repair/packet.rb', line 26 def self.validate_hash(hash) errors = SchemaValidator.validate_repair_packet(hash) raise ArgumentError, "invalid repair packet: #{errors.join('; ')}" unless errors.empty? hash end |
Instance Method Details
#to_h ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rail_verdict/repair/packet.rb', line 68 def to_h h = { "schema_version" => SCHEMA_VERSION, "packet_id" => packet_id, "created_at" => created_at, "railverdict_version" => railverdict_version, "source_revision" => source_revision, "target" => target, "verification" => verification, "evidence" => evidence, "git_context" => git_context, "rails_context" => rails_context, "source_context" => source_context, "policy" => policy, "baseline_state" => baseline_state, "waivers_state" => waivers_state, "verification_plan" => verification_plan, "constraints" => constraints, "completeness" => completeness, "success_criteria" => success_criteria, "boundary" => boundary } h["base_revision"] = base_revision unless base_revision.nil? h["merge_base"] = merge_base unless merge_base.nil? h["diff_context"] = diff_context if diff_context h["ai_analysis"] = ai_analysis if ai_analysis h["instructions"] = instructions unless instructions.empty? h end |
#to_json(*args) ⇒ Object
98 99 100 |
# File 'lib/rail_verdict/repair/packet.rb', line 98 def to_json(*args) JSON.generate(to_h, *args) end |