Skip to content

Commit

Permalink
Merge pull request #659 from pact-foundation/chore/log-sha-generation…
Browse files Browse the repository at this point in the history
…-time

chore: log sha generation time
  • Loading branch information
bethesque authored Jan 24, 2024
2 parents 5d9d700 + 29c9031 commit f1df732
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 10 additions & 0 deletions lib/pact_broker/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def log_with_tag(tag)
end
end

def measure_info(message, payload: {})
if logger.respond_to?(:measure_info)
logger.measure_info(message, payload: payload) do
yield
end
else
yield
end
end

def log_error e, description = nil
if logger.instance_of?(SemanticLogger::Logger)
if description
Expand Down
13 changes: 9 additions & 4 deletions lib/pact_broker/pacts/generate_sha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@
require "pact_broker/pacts/sort_content"
require "pact_broker/pacts/parse"
require "pact_broker/pacts/content"
require "pact_broker/logging"

module PactBroker
module Pacts
class GenerateSha
include PactBroker::Logging

# @param [String] json_content
def self.call json_content, _options = {}
def self.call(json_content, _options = {})
content_for_sha = if PactBroker.configuration.base_equality_only_on_content_that_affects_verification_results
extract_verifiable_content_for_sha(json_content)
else
json_content
end
Digest::SHA1.hexdigest(content_for_sha)
measure_info("Generating SHA1 hexdigest for pact", payload: { length: content_for_sha.length } ){ Digest::SHA1.hexdigest(content_for_sha) }
end

def self.extract_verifiable_content_for_sha json_content
Content.from_json(json_content).sort.content_that_affects_verification_results.to_json
def self.extract_verifiable_content_for_sha(json_content)
objects = Content.from_json(json_content)
sorted_content = measure_info("Sorting content", payload: { length: json_content.length }){ objects.sort }
sorted_content.content_that_affects_verification_results.to_json
end
end
end
Expand Down

0 comments on commit f1df732

Please sign in to comment.