pact_broker 2.110.0 → 2.111.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0747ca988604f56bec96bb0511242e8b3e9e2c18c823ec53742a1c58f80eee16
4
- data.tar.gz: fbdc8b9be85cf443ccd8ddcb58704a1aece12759e267aea1b4f79ba0d05fbf9c
3
+ metadata.gz: e21e3c2fc82cfe4697582921613bd435e026cf6f381c64c33d703b8c31c586be
4
+ data.tar.gz: 6b6bc75a486f936441b172c7a80a7e8541f3bbb1731be03b1e33a869327014bf
5
5
  SHA512:
6
- metadata.gz: 416b29a9c6fe749e990ce9a051e526568d1a453c78db704d68e63002bb0ba1c17f8117b1d54ec540bea609168e26d2e7583bf087394aa249d9bacd6f0ad58ea5
7
- data.tar.gz: b729576d06caac277699def3e48bfd1c75400467018da3b740fad3ff1ba84e628388369dddb60f964cf4b948d66d27096feca800f8e80314be762d327cdd1e54
6
+ metadata.gz: 2afe779170a4910f06ace0a29b8ee66fa81bc355fc1a1c22a532fb3f9f64f5775309543c23b3b7ae4c4c837c1a66d0b10ddb0f62e8e9f586b7fd4942dc29d33c
7
+ data.tar.gz: 3b2738f3785dc1c272d4e1ba24104b4786bd467780808d41bdf2dd7f2ce0e83f0f11645a8ca3b8fd16642055a897d60b573ea7fc8392751cf0a59ecafeba6130
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ <a name="v2.111.0"></a>
2
+ ### v2.111.0 (2024-07-26)
3
+
4
+ #### Features
5
+
6
+ * add new label api (#703) ([ff3f84e2](/../../commit/ff3f84e2))
7
+ * search pacticipants by display_name ([c5945801](/../../commit/c5945801))
8
+
9
+ #### Bug Fixes
10
+
11
+ * **docs**
12
+ * Update OAS with correct ref to Notice schema ([6729b7f8](/../../commit/6729b7f8))
13
+
1
14
  <a name="v2.110.0"></a>
2
15
  ### v2.110.0 (2024-04-02)
3
16
 
@@ -11,20 +11,26 @@ module PactBroker
11
11
 
12
12
  include Timestamps
13
13
 
14
- link :self do | options |
15
- {
16
- title: "Label",
17
- name: represented.name,
18
- href: label_url(represented, options[:base_url])
19
- }
20
- end
14
+ # This method is overridden to conditionally render the links based on the user_options
15
+ def to_hash(options)
16
+ hash = super
17
+
18
+ unless options.dig(:user_options, :hide_label_decorator_links)
19
+ hash[:_links] = {
20
+ self: {
21
+ title: "Label",
22
+ name: represented.name,
23
+ href: label_url(represented, options.dig(:user_options, :base_url))
24
+ },
25
+ pacticipant: {
26
+ title: "Pacticipant",
27
+ name: represented.pacticipant.name,
28
+ href: pacticipant_url(options.dig(:user_options, :base_url), represented.pacticipant)
29
+ }
30
+ }
31
+ end
21
32
 
22
- link :pacticipant do | options |
23
- {
24
- title: "Pacticipant",
25
- name: represented.pacticipant.name,
26
- href: pacticipant_url(options.fetch(:base_url), represented.pacticipant)
27
- }
33
+ hash
28
34
  end
29
35
  end
30
36
  end
@@ -0,0 +1,23 @@
1
+ require_relative "base_decorator"
2
+ require_relative "pagination_links"
3
+ require_relative "label_decorator"
4
+ require "pact_broker/domain/label"
5
+
6
+ module PactBroker
7
+ module Api
8
+ module Decorators
9
+ class LabelsDecorator < BaseDecorator
10
+ collection :entries, :as => :labels, :class => PactBroker::Domain::Label, :extend => PactBroker::Api::Decorators::LabelDecorator, embedded: true
11
+
12
+ include PaginationLinks
13
+
14
+ link :self do | options |
15
+ {
16
+ title: "Labels",
17
+ href: options.fetch(:resource_url)
18
+ }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -20,7 +20,7 @@ module PactBroker
20
20
  property :main_branch
21
21
 
22
22
  property :latest_version, as: :latestVersion, :class => PactBroker::Domain::Version, extend: PactBroker::Api::Decorators::EmbeddedVersionDecorator, embedded: true, writeable: false
23
- collection :labels, :class => PactBroker::Domain::Label, extend: PactBroker::Api::Decorators::EmbeddedLabelDecorator, embedded: true
23
+ collection :labels, :class => PactBroker::Domain::Label, extend: PactBroker::Api::Decorators::EmbeddedLabelDecorator, embedded: true, writeable: false
24
24
 
25
25
  include Timestamps
26
26
 
@@ -3,11 +3,12 @@ module PactBroker
3
3
  module Paths
4
4
  PACT_BADGE_PATH = %r{^/pacts/provider/[^/]+/consumer/.*/badge(?:\.[A-Za-z]+)?$}.freeze
5
5
  MATRIX_BADGE_PATH = %r{^/matrix/provider/[^/]+/latest/[^/]+/consumer/[^/]+/latest/[^/]+/badge(?:\.[A-Za-z]+)?$}.freeze
6
+ CAN_I_MERGE_BADGE_PATH = %r{^/pacticipants/[^/]+/main-branch/can-i-merge/badge(?:\.[A-Za-z]+)?$}.freeze
6
7
  CAN_I_DEPLOY_TAG_BADGE_PATH = %r{^/pacticipants/[^/]+/latest-version/[^/]+/can-i-deploy/to/[^/]+/badge(?:\.[A-Za-z]+)?$}.freeze
7
8
  CAN_I_DEPLOY_BRANCH_ENV_BADGE_PATH = %r{^/pacticipants/[^/]+/branches/[^/]+/latest-version/can-i-deploy/to-environment/[^/]+/badge(?:\.[A-Za-z]+)?$}.freeze
8
9
  VERIFICATION_RESULTS = %r{^/pacts/provider/[^/]+/consumer/[^/]+/pact-version/[^/]+/verification-results/[^/]+}
9
10
 
10
- BADGE_PATHS = [PACT_BADGE_PATH, MATRIX_BADGE_PATH, CAN_I_DEPLOY_TAG_BADGE_PATH, CAN_I_DEPLOY_BRANCH_ENV_BADGE_PATH]
11
+ BADGE_PATHS = [PACT_BADGE_PATH, MATRIX_BADGE_PATH, CAN_I_DEPLOY_TAG_BADGE_PATH, CAN_I_DEPLOY_BRANCH_ENV_BADGE_PATH, CAN_I_MERGE_BADGE_PATH]
11
12
 
12
13
  extend self
13
14
 
@@ -0,0 +1,36 @@
1
+ require "pact_broker/api/resources/base_resource"
2
+ require "pact_broker/api/resources/badge_methods"
3
+
4
+ module PactBroker
5
+ module Api
6
+ module Resources
7
+ class CanIMergeBadge < BaseResource
8
+ include BadgeMethods # This module contains all necessary webmachine methods for badge implementation
9
+
10
+ def badge_url
11
+ if pacticipant.nil? # pacticipant method is defined in BaseResource
12
+ # if the pacticipant is nil, we return an error badge url
13
+ badge_service.error_badge_url("pacticipant", "not found")
14
+ elsif version.nil?
15
+ # when there is no main branch version, we return an error badge url
16
+ badge_service.error_badge_url("main branch version", "not found")
17
+ else
18
+ # we call badge_service to build the badge url
19
+ badge_service.can_i_merge_badge_url(deployable: results)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def results
26
+ # can_i_merge returns true or false if the main branch version is compatible with all the integrations
27
+ @results ||= matrix_service.can_i_merge(pacticipant: pacticipant, latest_main_branch_version: version)
28
+ end
29
+
30
+ def version
31
+ @version ||= version_service.find_latest_version_from_main_branch(pacticipant)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require "pact_broker/api/resources/base_resource"
2
+ require "pact_broker/api/decorators/labels_decorator"
3
+ require "pact_broker/api/resources/pagination_methods"
4
+
5
+ module PactBroker
6
+ module Api
7
+ module Resources
8
+ class Labels < BaseResource
9
+ include PaginationMethods
10
+
11
+ def content_types_provided
12
+ [["application/hal+json", :to_json]]
13
+ end
14
+
15
+ def allowed_methods
16
+ ["GET", "OPTIONS"]
17
+ end
18
+
19
+ def policy_name
20
+ :'labels::labels'
21
+ end
22
+
23
+ def to_json
24
+ decorator_class(:labels_decorator).new(labels).to_json(
25
+ **decorator_options(
26
+ hide_label_decorator_links: true,
27
+ )
28
+ )
29
+ end
30
+
31
+ def labels
32
+ label_service.get_all_unique_labels(pagination_options)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -85,6 +85,9 @@ module PactBroker
85
85
  add ["pacticipants", :pacticipant_name], Api::Resources::Pacticipant, {resource_name: "pacticipant"}
86
86
  add ["pacticipants", :pacticipant_name, "labels", :label_name], Api::Resources::Label, {resource_name: "pacticipant_label"}
87
87
 
88
+ # Labels
89
+ add ["labels"], Api::Resources::Labels, {resource_name: "labels"}
90
+
88
91
  # Versions
89
92
  add ["pacticipants", :pacticipant_name, "versions"], Api::Resources::Versions, {resource_name: "pacticipant_versions"}
90
93
  add ["pacticipants", :pacticipant_name, "branches", :branch_name, "versions"], Api::Resources::BranchVersions, {resource_name: "pacticipant_branch_versions"}
@@ -92,6 +95,7 @@ module PactBroker
92
95
  add ["pacticipants", :pacticipant_name, "latest-version", :tag], Api::Resources::LatestVersion, {resource_name: "latest_tagged_pacticipant_version"}
93
96
  add ["pacticipants", :pacticipant_name, "latest-version", :tag, "can-i-deploy", "to", :to], Api::Resources::CanIDeployPacticipantVersionByTagToTag, { resource_name: "can_i_deploy_latest_tagged_version_to_tag" }
94
97
  add ["pacticipants", :pacticipant_name, "latest-version", :tag, "can-i-deploy", "to", :to, "badge"], Api::Resources::CanIDeployPacticipantVersionByTagToTagBadge, { resource_name: "can_i_deploy_latest_tagged_version_to_tag_badge" }
98
+ add ["pacticipants", :pacticipant_name, "main-branch", "can-i-merge", "badge"], Api::Resources::CanIMergeBadge, { resource_name: "can_i_merge_badge" }
95
99
  add ["pacticipants", :pacticipant_name, "latest-version"], Api::Resources::LatestVersion, {resource_name: "latest_pacticipant_version"}
96
100
  add ["pacticipants", :pacticipant_name, "versions", :pacticipant_version_number, "tags", :tag_name], Api::Resources::Tag, {resource_name: "pacticipant_version_tag"}
97
101
  add ["pacticipants", :pacticipant_name, "branches"], Api::Resources::PacticipantBranches, {resource_name: "pacticipant_branches"}
@@ -40,6 +40,24 @@ module PactBroker
40
40
  build_shield_io_uri(title, status, color)
41
41
  end
42
42
 
43
+ def can_i_merge_badge_url(deployable: nil)
44
+ title = "can-i-merge"
45
+
46
+ # rubocop:disable Layout/EndAlignment
47
+ color, status = case deployable
48
+ when nil
49
+ [ "lightgrey", "unknown" ]
50
+ when true
51
+ [ "brightgreen", "success" ]
52
+ else
53
+ [ "red", "failed" ]
54
+ end
55
+ # rubocop:enable Layout/EndAlignment
56
+
57
+ # left text is "can-i-merge", right text is the version number
58
+ build_shield_io_uri(title, status, color)
59
+ end
60
+
43
61
  def error_badge_url(left_text, right_text)
44
62
  build_shield_io_uri(left_text, right_text, "lightgrey")
45
63
  end
@@ -3,6 +3,11 @@ require "pact_broker/domain/label"
3
3
  module PactBroker
4
4
  module Labels
5
5
  class Repository
6
+
7
+ def get_all_unique_labels pagination_options = {}
8
+ PactBroker::Domain::Label.distinct.select(:name).all_with_pagination_options(pagination_options)
9
+ end
10
+
6
11
  def create args
7
12
  Domain::Label.new(name: args.fetch(:name), pacticipant: args.fetch(:pacticipant)).save
8
13
  end
@@ -9,6 +9,10 @@ module PactBroker
9
9
 
10
10
  extend PactBroker::Repositories
11
11
 
12
+ def get_all_unique_labels pagination_options = {}
13
+ label_repository.get_all_unique_labels(pagination_options)
14
+ end
15
+
12
16
  def create args
13
17
  pacticipant = pacticipant_repository.find_by_name_or_create args.fetch(:pacticipant_name)
14
18
  label_repository.create pacticipant: pacticipant, name: args.fetch(:label_name)
@@ -22,6 +22,32 @@ module PactBroker
22
22
  QueryResultsWithDeploymentStatusSummary.new(query_results, DeploymentStatusSummary.new(query_results))
23
23
  end
24
24
 
25
+ def can_i_merge(pacticipant_name: nil, pacticipant: nil, latest_main_branch_version: nil)
26
+ # first we find the pacticipant by name (or use the one passed in) if pacticipant is nil
27
+ if pacticipant.nil?
28
+ pacticipant = pacticipant_service.find_pacticipant_by_name(pacticipant_name)
29
+ raise PactBroker::Error.new("No pacticipant found with name '#{pacticipant_name}'") unless pacticipant
30
+ else
31
+ pacticipant_name = pacticipant.name
32
+ end
33
+
34
+ # then we find the latest version from the main branch if not passed in
35
+ if latest_main_branch_version.nil?
36
+ latest_main_branch_version = version_service.find_latest_version_from_main_branch(pacticipant)
37
+ raise PactBroker::Error.new("No main branch version found for pacticipant '#{pacticipant_name}'") unless latest_main_branch_version
38
+ end
39
+
40
+ selectors = PactBroker::Matrix::UnresolvedSelector.from_hash(
41
+ pacticipant_name: pacticipant_name,
42
+ pacticipant_version_number: latest_main_branch_version.number
43
+ )
44
+
45
+ options = { main_branch: true, latest: true, latestby: "cvp" }
46
+ query_results = can_i_deploy([selectors], options)
47
+
48
+ query_results.deployable?
49
+ end
50
+
25
51
  def find selectors, options = {}
26
52
  logger.info "Querying matrix", selectors: selectors, options: options
27
53
  matrix_repository.find(selectors, options)
@@ -102,7 +102,16 @@ module PactBroker
102
102
 
103
103
  def search_by_name(pacticipant_name)
104
104
  terms = pacticipant_name.split.map { |v| v.gsub("_", "\\_") }
105
- string_match_query = Sequel.|( *terms.map { |term| Sequel.ilike(Sequel[:pacticipants][:name], "%#{term}%") })
105
+ columns = [:name, :display_name]
106
+ string_match_query = Sequel.|(
107
+ *terms.map do |term|
108
+ Sequel.|(
109
+ *columns.map do |column|
110
+ Sequel.ilike(Sequel[:pacticipants][column], "%#{term}%")
111
+ end
112
+ )
113
+ end
114
+ )
106
115
  scope_for(PactBroker::Domain::Pacticipant).where(string_match_query)
107
116
  end
108
117
 
@@ -165,9 +165,16 @@ module PactBroker
165
165
 
166
166
  def create_pacticipant pacticipant_name, params = {}
167
167
  params.delete(:comment)
168
+ version_to_create = params.delete(:version)
169
+
168
170
  repository_url = "https://github.com/#{params[:repository_namespace] || "example-organization"}/#{params[:repository_name] || pacticipant_name}"
169
171
  merged_params = { name: pacticipant_name, repository_url: repository_url }.merge(params)
170
172
  @pacticipant = PactBroker::Domain::Pacticipant.create(merged_params)
173
+
174
+ version = create_pacticipant_version(version_to_create, @pacticipant) if version_to_create
175
+ main_branch = params[:main_branch]
176
+ PactBroker::Versions::BranchVersionRepository.new.add_branch(version, main_branch) if version && main_branch
177
+
171
178
  self
172
179
  end
173
180
 
@@ -639,8 +646,6 @@ module PactBroker
639
646
  }.to_json
640
647
  end
641
648
 
642
- private
643
-
644
649
  def create_pacticipant_version(version_number, pacticipant, params = {})
645
650
  params.delete(:comment)
646
651
  tag_names = [params.delete(:tag_names), params.delete(:tag_name)].flatten.compact
@@ -665,6 +670,8 @@ module PactBroker
665
670
  version
666
671
  end
667
672
 
673
+ private
674
+
668
675
  def create_deployed_version(uuid: , currently_deployed: , version:, environment_name: , target: nil, created_at: nil)
669
676
  env = find_environment(environment_name)
670
677
  @deployed_version = PactBroker::Deployments::DeployedVersionService.find_or_create(uuid, version, env, target)
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = "2.110.0"
2
+ VERSION = "2.111.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.110.0
4
+ version: 2.111.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bethany Skurrie
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-05-10 00:00:00.000000000 Z
13
+ date: 2024-08-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -654,6 +654,7 @@ files:
654
654
  - lib/pact_broker/api/decorators/integration_decorator.rb
655
655
  - lib/pact_broker/api/decorators/integrations_decorator.rb
656
656
  - lib/pact_broker/api/decorators/label_decorator.rb
657
+ - lib/pact_broker/api/decorators/labels_decorator.rb
657
658
  - lib/pact_broker/api/decorators/latest_pact_decorator.rb
658
659
  - lib/pact_broker/api/decorators/matrix_decorator.rb
659
660
  - lib/pact_broker/api/decorators/matrix_text_decorator.rb
@@ -720,6 +721,7 @@ files:
720
721
  - lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge.rb
721
722
  - lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_tag_to_tag.rb
722
723
  - lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_tag_to_tag_badge.rb
724
+ - lib/pact_broker/api/resources/can_i_merge_badge.rb
723
725
  - lib/pact_broker/api/resources/clean.rb
724
726
  - lib/pact_broker/api/resources/currently_deployed_versions_for_environment.rb
725
727
  - lib/pact_broker/api/resources/currently_supported_versions_for_environment.rb
@@ -739,6 +741,7 @@ files:
739
741
  - lib/pact_broker/api/resources/integration.rb
740
742
  - lib/pact_broker/api/resources/integrations.rb
741
743
  - lib/pact_broker/api/resources/label.rb
744
+ - lib/pact_broker/api/resources/labels.rb
742
745
  - lib/pact_broker/api/resources/latest_pact.rb
743
746
  - lib/pact_broker/api/resources/latest_pacts.rb
744
747
  - lib/pact_broker/api/resources/latest_provider_pacts.rb
@@ -1265,7 +1268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1265
1268
  - !ruby/object:Gem::Version
1266
1269
  version: '0'
1267
1270
  requirements: []
1268
- rubygems_version: 3.5.10
1271
+ rubygems_version: 3.5.17
1269
1272
  signing_key:
1270
1273
  specification_version: 4
1271
1274
  summary: See description