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.
23 24 25 26 27 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 23 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
33 34 35 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 33 def self.load(review_id:) new(review_id: review_id) end |
Instance Method Details
#changes_diff ⇒ String
Read the captured git diff for changes
98 99 100 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 98 def changes_diff File.read(artifact_path("changes.diff")) end |
#complete? ⇒ Boolean
Returns whether this artifact directory contains a complete analysis.
48 49 50 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 48 def complete? File.file?(artifact_path("complete.json")) end |
#prepare! ⇒ self
Prepare the artifact directory and capture initial data
40 41 42 43 44 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 40 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
112 113 114 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 112 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
105 106 107 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 105 def raw_check_outputs raw_check_output_store.to_h end |
#to_run(format:, log: false) ⇒ Run
Reconstruct a run from persisted artifacts
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 75 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"), base_ref: manifest.fetch("base_ref", GitDiffBase::DEFAULT_BASE_REF), 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.
118 119 120 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 118 def to_s @path end |
#write_check_output(check_output) ⇒ void
This method returns an undefined value.
Write raw check output to a file
56 57 58 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 56 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
64 65 66 67 68 |
# File 'lib/cleo_quality_review/run_artifacts.rb', line 64 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 |