Skip to content

Commit

Permalink
feat: abbreviate git shas in index and matrix UIs
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 7, 2018
1 parent 2023265 commit 9a21e10
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/pact_broker/ui/view_models/index_item.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'pact_broker/api/pact_broker_urls'
require 'pact_broker/ui/helpers/url_helper'
require 'pact_broker/date_helper'
require 'pact_broker/versions/abbreviate_number'

module PactBroker
module UI
Expand All @@ -22,11 +23,11 @@ def provider_name
end

def consumer_version_number
@relationship.consumer_version_number
PactBroker::Versions::AbbreviateNumber.call(@relationship.consumer_version_number)
end

def provider_version_number
@relationship.provider_version_number
PactBroker::Versions::AbbreviateNumber.call(@relationship.provider_version_number)
end

def tag_names
Expand Down
9 changes: 9 additions & 0 deletions lib/pact_broker/ui/view_models/matrix_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'pact_broker/ui/helpers/url_helper'
require 'pact_broker/date_helper'
require 'pact_broker/ui/view_models/matrix_tag'
require 'pact_broker/versions/abbreviate_number'

module PactBroker
module UI
Expand Down Expand Up @@ -52,6 +53,10 @@ def consumer_version_number
@line[:consumer_version_number]
end

def display_consumer_version_number
PactBroker::Versions::AbbreviateNumber.call(consumer_version_number)
end

def consumer_version_number_url
params = { pacticipant_name: consumer_name, version_number: consumer_version_number }
hal_browser_url(version_url_from_params(params))
Expand All @@ -69,6 +74,10 @@ def provider_version_number
@line[:provider_version_number]
end

def display_provider_version_number
PactBroker::Versions::AbbreviateNumber.call(provider_version_number)
end

def provider_version_order
@line[:provider_version_order]
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/ui/views/matrix/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
%td.consumer-version{'data-sort-value' => line.consumer_version_order}
%div
%a{href: line.consumer_version_number_url}
= line.consumer_version_number
= line.display_consumer_version_number
- line.latest_consumer_version_tags.each do | tag |
.tag-parent{"title": tag.tooltip, "data-toggle": "tooltip", "data-placement": "right"}
%a{href: tag.url}
Expand All @@ -127,7 +127,7 @@
%td.provider-version{'data-sort-value' => line.provider_version_order}
%div
%a{href: line.provider_version_number_url}
= line.provider_version_number
= line.display_provider_version_number
- line.latest_provider_version_tags.each do | tag |
.tag-parent{"title": tag.tooltip, "data-toggle": "tooltip", "data-placement": "right"}
%a{href: tag.url}
Expand Down
14 changes: 14 additions & 0 deletions lib/pact_broker/versions/abbreviate_number.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module PactBroker
module Versions
class AbbreviateNumber

def self.call version_number
if version_number
version_number.gsub(/[A-Za-z0-9]{40}/) do | val |
val[0..6]
end
end
end
end
end
end
22 changes: 22 additions & 0 deletions spec/lib/pact_broker/versions/abbreviate_number_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'pact_broker/versions/abbreviate_number'

module PactBroker
module Versions
describe AbbreviateNumber do
describe "#call" do
TEST_CASES = [
['202326572516dea6998a7f311fcaa161c0768fc2', '2023265'],
['1.2.3+areallyreallyreallylongexplanation', '1.2.3+areallyreallyreallylongexplanation'],
['2516dea6998a7f', '2516dea6998a7f'],
['1.2.3+202326572516dea6998a7f311fcaa161c0768fc2', '1.2.3+2023265']
]

TEST_CASES.each do |(input, output)|
it "shortens #{input} to #{output}" do
expect(AbbreviateNumber.call(input)).to eq output
end
end
end
end
end
end

0 comments on commit 9a21e10

Please sign in to comment.