Class: CleoQualityReview::RunArtifacts
- Inherits:
-
Object
- Object
- CleoQualityReview::RunArtifacts
- Defined in:
- lib/cleo_quality_review/run_artifacts.rb,
lib/cleo_quality_review/run_artifacts/raw_check_outputs.rb
Overview
Manages artifacts produced during a quality review run
Defined Under Namespace
Classes: RawCheckOutputs
Constant Summary collapse
- ROOT =
"tmp/quality_checks"- RawCheckOutput =
RawCheckOutputs::Record
Class Method Summary collapse
-
.load(review_id:) ⇒ RunArtifacts
Load artifacts by review ID.
Instance Method Summary collapse
-
#changes_diff ⇒ String
Read the captured git diff for changes.
-
#complete? ⇒ Boolean
Whether this artifact directory contains a complete analysis.
-
#initialize(review_id:, changes_diff: nil, **_run_metadata) ⇒ RunArtifacts
constructor
A new instance of RunArtifacts.
-
#prepare! ⇒ self
Prepare the artifact directory and capture initial data.
-
#raw_check_output_records ⇒ Array<RawCheckOutputs::Record>
Read all raw check outputs with metadata from the artifact directory.
-
#raw_check_outputs ⇒ Hash{String => String}
Read all raw check outputs from the artifact directory.
-
#to_run(format:, log: false) ⇒ Run
Reconstruct a run from persisted artifacts.
-
#to_s ⇒ String
Path to the artifacts directory.
-
#write_check_output(check_output) ⇒ void
Write raw check output to a file.
-
#write_run(run) ⇒ void
Persist run metadata for later render/publish commands.
Constructor Details
#initialize(review_id:, changes_diff: nil, **_run_metadata) ⇒ RunArtifacts
Returns a new instance of RunArtifacts.
22 23 24 25 26 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 22 def initialize(review_id:, changes_diff: nil, **) @review_id = review_id.to_s @changes_diff_content = changes_diff @path = File.join(ROOT, @review_id) end |
Class Method Details
.load(review_id:) ⇒ RunArtifacts
Load artifacts by review ID
32 33 34 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 32 def self.load(review_id:) new(review_id: review_id) end |
Instance Method Details
#changes_diff ⇒ String
Read the captured git diff for changes
96 97 98 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 96 def changes_diff File.read(artifact_path("changes.diff")) end |
#complete? ⇒ Boolean
Returns whether this artifact directory contains a complete analysis.
47 48 49 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 47 def complete? File.file?(artifact_path("complete.json")) end |
#prepare! ⇒ self
Prepare the artifact directory and capture initial data
39 40 41 42 43 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 39 def prepare! FileUtils.mkdir_p(@path) write_changes_diff self end |
#raw_check_output_records ⇒ Array<RawCheckOutputs::Record>
Read all raw check outputs with metadata from the artifact directory
110 111 112 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 110 def raw_check_output_records raw_check_output_store.records end |
#raw_check_outputs ⇒ Hash{String => String}
Read all raw check outputs from the artifact directory
103 104 105 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 103 def raw_check_outputs raw_check_output_store.to_h end |
#to_run(format:, log: false) ⇒ Run
Reconstruct a run from persisted artifacts
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 74 def to_run(format:, log: false) raise ArgumentError, "No completed quality review artifacts found for review ID #{@review_id}" unless complete? manifest = read_manifest target_files = manifest.fetch("target_files", []) Run.new( timestamp: manifest.fetch("timestamp"), review_id: manifest.fetch("review_id"), format: format, checks: manifest.fetch("checks", []), target_files: target_files, ruby_files: manifest.fetch("ruby_files", target_files), run_directory: @path, results: read_results, artifacts: self, log: log, ) end |
#to_s ⇒ String
Returns path to the artifacts directory.
116 117 118 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 116 def to_s @path end |
#write_check_output(check_output) ⇒ void
This method returns an undefined value.
Write raw check output to a file
55 56 57 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 55 def write_check_output(check_output) raw_check_output_store.write(check_output) end |
#write_run(run) ⇒ void
This method returns an undefined value.
Persist run metadata for later render/publish commands
63 64 65 66 67 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 63 def write_run(run) File.write(artifact_path("results.json"), JSON.pretty_generate(Array(run.results).map(&:to_h))) File.write(artifact_path("manifest.json"), JSON.pretty_generate(run.manifest_data)) File.write(artifact_path("complete.json"), JSON.pretty_generate({ review_id: @review_id, completed: true })) end |