Class: PactBroker::UI::ViewDomain::IndexItem

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Api::PactBrokerUrls
Defined in:
lib/pact_broker/ui/view_models/index_item.rb

Constant Summary

Constants included from Pacts::Metadata

Pacts::Metadata::MAPPINGS

Instance Method Summary collapse

Methods included from Api::PactBrokerUrls

#append_query_if_present, #badge_url_for_latest_pact, #consumer_webhooks_url, #dashboard_url_for_integration, #decode_pact_metadata, #encode_metadata, #group_url, #hal_browser_url, #label_url, #labels_url, #latest_pacts_url, #latest_tagged_pact_url, #latest_untagged_pact_url, #latest_verification_for_pact_url, #latest_verifications_for_consumer_version_url, #latest_version_url, #matrix_badge_url_for_selectors, #matrix_for_pact_url, #matrix_for_pacticipant_version_url, #matrix_url, #matrix_url_from_params, #new_verification_url, #pact_triggered_webhooks_url, #pact_url_from_params, #pact_version_url, #pact_version_url_with_metadata, #pact_version_url_with_webhook_metadata, #pacticipant_url, #pacticipant_url_from_params, #pacticipants_url, #previous_distinct_diff_url, #previous_distinct_pact_version_url, #provider_webhooks_url, #tag_url, #tagged_pact_versions_url, #tags_url, #templated_can_i_deploy_badge_url, #templated_can_i_deploy_url, #templated_diff_url, #templated_label_url_for_pacticipant, #templated_tag_url_for_pacticipant, #triggered_webhook_logs_url, #url_encode, #verification_publication_url, #verification_triggered_webhooks_url, #verification_url, #verification_url_from_params, #version_url, #version_url_from_params, #versions_url, #webhook_execution_url, #webhooks_for_consumer_and_provider_url, #webhooks_for_pact_url, #webhooks_status_url, #webhooks_url

Methods included from Logging

included, #log_error

Methods included from Pacts::Metadata

#build_metadata_for_latest_pact, #build_metadata_for_pact_for_verification, #build_metadata_for_webhook_triggered_by_pact_publication, #parse_hash, #parse_metadata, #parse_object

Constructor Details

#initialize(relationship, options = {}) ⇒ IndexItem

Returns a new instance of IndexItem.



19
20
21
22
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 19

def initialize relationship, options = {}
  @relationship = relationship
  @options = options
end

Instance Method Details

#<=>(other) ⇒ Object



174
175
176
177
178
179
180
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 174

def <=> other
  comp = consumer_name.downcase <=> other.consumer_name.downcase
  return comp unless comp == 0
  comp = provider_name.downcase <=> other.provider_name.downcase
  return comp unless comp == 0
  other.consumer_version_order <=> consumer_version_order
end

#any_webhooks?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 76

def any_webhooks?
  @relationship.any_webhooks?
end

#base_urlObject



191
192
193
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 191

def base_url
  @options[:base_url]
end

#consumer_group_urlObject



56
57
58
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 56

def consumer_group_url
  Helpers::URLHelper.group_url(consumer_name, base_url)
end

#consumer_nameObject



24
25
26
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 24

def consumer_name
  @relationship.consumer_name
end

#consumer_version_latest_tag_namesObject



48
49
50
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 48

def consumer_version_latest_tag_names
  @relationship.tag_names
end

#consumer_version_numberObject



32
33
34
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 32

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

#consumer_version_orderObject



36
37
38
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 36

def consumer_version_order
  @relationship.consumer_version_order
end

#integration_urlObject



84
85
86
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 84

def integration_url
  PactBroker::Api::PactBrokerUrls.integration_url(consumer_name, provider_name, base_url)
end

#last_verified_dateObject



130
131
132
133
134
135
136
137
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 130

def last_verified_date
  if @relationship.ever_verified?
    date = @relationship.latest_verification.execution_date
    PactBroker::DateHelper.distance_of_time_in_words(date, DateTime.now) + " ago"
  else
    ""
  end
end

#latest?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 44

def latest?
  @relationship.latest?
end

#latest_pact_urlObject



64
65
66
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 64

def latest_pact_url
  "#{pactigration_base_url(base_url, @relationship)}/latest"
end

#pact_matrix_urlObject



72
73
74
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 72

def pact_matrix_url
  Helpers::URLHelper.matrix_url(consumer_name, provider_name, base_url)
end

#pact_urlObject



68
69
70
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 68

def pact_url
  PactBroker::Api::PactBrokerUrls.pact_url(base_url, @relationship)
end

#pact_versions_urlObject



80
81
82
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 80

def pact_versions_url
  PactBroker::Api::PactBrokerUrls.pact_versions_url(consumer_name, provider_name, base_url)
end

#provider_group_urlObject



60
61
62
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 60

def provider_group_url
  Helpers::URLHelper.group_url(provider_name, base_url)
end

#provider_nameObject



28
29
30
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 28

def provider_name
  @relationship.provider_name
end

#provider_version_latest_tag_namesObject



52
53
54
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 52

def provider_version_latest_tag_names
  @relationship.latest_verification_latest_tags.collect(&:name)
end

#provider_version_numberObject



40
41
42
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 40

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

#pseudo_branch_verification_statusObject



148
149
150
151
152
153
154
155
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 148

def pseudo_branch_verification_status
  case @relationship.pseudo_branch_verification_status
    when :success then "success"
    when :stale then "warning"
    when :failed then "danger"
    else ""
  end
end

#publication_date_of_latest_pactObject



139
140
141
142
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 139

def publication_date_of_latest_pact
  date = @relationship.latest_pact.created_at
  PactBroker::DateHelper.distance_of_time_in_words(date, DateTime.now) + " ago"
end

#publication_date_of_latest_pact_orderObject



144
145
146
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 144

def publication_date_of_latest_pact_order
  @relationship.latest_pact.created_at.to_time.to_i
end

#short_version_number(version_number) ⇒ Object



182
183
184
185
186
187
188
189
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 182

def short_version_number version_number
  return "" if version_number.nil?
  if version_number.size > 12
    version_number[0..12] + "..."
  else
    version_number
  end
end

#show_settings?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 112

def show_settings?
  @relationship.latest?
end

#show_webhook_status?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 108

def show_webhook_status?
  @relationship.latest?
end

#verification_tooltipObject



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 161

def verification_tooltip
  case @relationship.pseudo_branch_verification_status
  when :success
    "Successfully verified by #{provider_name} (#{short_version_number(@relationship.latest_verification_provider_version_number)})"
  when :stale
    "Pact has changed since last successful verification by #{provider_name} (#{short_version_number(@relationship.latest_verification_provider_version_number)})"
  when :failed
    "Verification by #{provider_name} (#{short_version_number(@relationship.latest_verification_provider_version_number)}) failed"
  else
    nil
  end
end

#warning?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 157

def warning?
  pseudo_branch_verification_status == 'warning'
end

#webhook_labelObject



88
89
90
91
92
93
94
95
96
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 88

def webhook_label
  return "" unless show_webhook_status?
  case @relationship.webhook_status
    when :none then "Create"
    when :success, :failure then webhook_last_execution_date
    when :retrying then "Retrying"
    when :not_run then "Not run"
  end
end

#webhook_last_execution_dateObject



116
117
118
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 116

def webhook_last_execution_date
  PactBroker::DateHelper.distance_of_time_in_words(@relationship.last_webhook_execution_date, DateTime.now) + " ago"
end

#webhook_statusObject



98
99
100
101
102
103
104
105
106
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 98

def webhook_status
  return "" unless show_webhook_status?
  case @relationship.webhook_status
    when :success then "success"
    when :failure then "danger"
    when :retrying then "warning"
    else ""
  end
end

#webhook_urlObject



120
121
122
123
124
125
126
127
128
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 120

def webhook_url
  url = case @relationship.webhook_status
    when :none
      PactBroker::Api::PactBrokerUrls.webhooks_for_consumer_and_provider_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider, base_url
    else
      PactBroker::Api::PactBrokerUrls.webhooks_status_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider, base_url
  end
  PactBroker::Api::PactBrokerUrls.hal_browser_url(url, base_url)
end