pact_broker 2.0.0.beta.6 → 2.0.0.beta.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +12 -12
  4. data/db/migrations/08_create_latest_pact_view.rb +4 -4
  5. data/db/migrations/14_add_timestamps_to_pact_views.rb +5 -4
  6. data/db/migrations/20_add_pact_version_content_sha_to_all_pacts_view.rb +12 -10
  7. data/db/migrations/28_create_all_pact_publications.rb +6 -5
  8. data/lib/pact_broker/api/decorators/verification_decorator.rb +0 -3
  9. data/lib/pact_broker/api/decorators/verification_summary_decorator.rb +36 -0
  10. data/lib/pact_broker/api/decorators/versions_decorator.rb +1 -1
  11. data/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +5 -5
  12. data/lib/pact_broker/api/resources/versions.rb +1 -1
  13. data/lib/pact_broker/app.rb +2 -0
  14. data/lib/pact_broker/configuration.rb +6 -1
  15. data/lib/pact_broker/domain/order_versions.rb +15 -5
  16. data/lib/pact_broker/domain/verification.rb +1 -1
  17. data/lib/pact_broker/domain/webhook.rb +0 -1
  18. data/lib/pact_broker/domain/webhook_request.rb +6 -4
  19. data/lib/pact_broker/logging.rb +4 -0
  20. data/lib/pact_broker/pacticipants/repository.rb +3 -2
  21. data/lib/pact_broker/pacticipants/service.rb +12 -9
  22. data/lib/pact_broker/pacts/all_pact_publications.rb +2 -2
  23. data/lib/pact_broker/pacts/repository.rb +11 -2
  24. data/lib/pact_broker/pacts/service.rb +4 -0
  25. data/lib/pact_broker/tags/repository.rb +5 -5
  26. data/lib/pact_broker/verifications/repository.rb +4 -3
  27. data/lib/pact_broker/verifications/service.rb +8 -0
  28. data/lib/pact_broker/verifications/summary_for_consumer_version.rb +41 -0
  29. data/lib/pact_broker/version.rb +1 -1
  30. data/lib/pact_broker/versions/parse_semantic_version.rb +14 -4
  31. data/lib/pact_broker/versions/repository.rb +1 -1
  32. data/lib/pact_broker/webhooks/job.rb +46 -0
  33. data/lib/pact_broker/webhooks/service.rb +9 -8
  34. data/lib/pact_broker/webhooks/webhook.rb +1 -1
  35. data/pact_broker.gemspec +4 -3
  36. data/pact_broker_client-pact_broker.json +4 -4
  37. data/script/foo-bar.json +22 -0
  38. data/script/publish-new.sh +7 -0
  39. data/script/publish.sh +2 -2
  40. data/script/recreate-pg-db.sh +10 -0
  41. data/spec/features/get_verifications_for_consumer_version_spec.rb +1 -1
  42. data/spec/fixtures/a_consumer-a_provider-2.json +1 -1
  43. data/spec/fixtures/a_consumer-a_provider-3.json +1 -1
  44. data/spec/fixtures/a_consumer-a_provider-conflict.json +1 -1
  45. data/spec/fixtures/a_consumer-a_provider-merged.json +2 -2
  46. data/spec/fixtures/a_consumer-a_provider.json +1 -1
  47. data/spec/fixtures/consumer-provider.json +1 -1
  48. data/spec/fixtures/renderer_pact.json +1 -1
  49. data/spec/lib/pact_broker/api/decorators/{verifications_decorator_spec.rb → verification_summary_decorator_spec.rb} +16 -13
  50. data/spec/lib/pact_broker/api/resources/latest_verifications_for_consumer_version_spec.rb +5 -5
  51. data/spec/lib/pact_broker/domain/order_versions_spec.rb +30 -10
  52. data/spec/lib/pact_broker/domain/webhook_request_spec.rb +3 -1
  53. data/spec/lib/pact_broker/pacticipants/repository_spec.rb +16 -0
  54. data/spec/lib/pact_broker/pacticipants/service_spec.rb +74 -24
  55. data/spec/lib/pact_broker/verifications/summary_for_consumer_version_spec.rb +72 -0
  56. data/spec/lib/pact_broker/versions/parse_semantic_version_spec.rb +5 -2
  57. data/spec/lib/pact_broker/webhooks/job_spec.rb +67 -0
  58. data/spec/lib/pact_broker/webhooks/service_spec.rb +40 -3
  59. data/spec/support/provider_state_builder.rb +3 -2
  60. data/tasks/db.rake +3 -2
  61. metadata +35 -14
  62. data/lib/pact_broker/api/decorators/verifications_decorator.rb +0 -30
  63. data/lib/pact_broker/pacts/all_pacts.rb +0 -12
  64. data/lib/pact_broker/pacts/latest_pacts.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba498f4801e7aa66d4d689a7177a3ddb7dcd2568
4
- data.tar.gz: e839365f5a50c7cac6bc676603647f20ad60b80f
3
+ metadata.gz: a23016da41a3bd4b5a3a71cd21c5ee26f34ebc15
4
+ data.tar.gz: 45cf807ca83536d65a7a75404dea32cb7407eab1
5
5
  SHA512:
6
- metadata.gz: b57d197a572c7d3713ee08dad512983c9e632fc4571b69a6c3720e584b8e3509007bb8d19b619a3ab87b1d59fdf828de1c0124b8d3bed5af596320c76b8f0f9c
7
- data.tar.gz: d5f88508286307cf7e12dfd4df6d013048cac9816278914df34e7fe065763e0f68af5835d6c85507d7150e7e5d41fc919c7c70ee1cfc88e81b8b81ed0ad5cd76
6
+ metadata.gz: 2e992dcc04ccf7453864d261f4a87a891ee23c624da4c116cbbb92d7cf3228214da2c5bc80e022d4ba2c523c31b4de0757eb8ae09c5ddcb7c1b34723c7d49998
7
+ data.tar.gz: aa4ace1b1d4032f7ebde957c9dab32023c378e41f9f950a38fdf8baa58cee6d082e3f4060b339da6032649c181bc9d1f948814eae5892c4d5e8e6250abb5567e
@@ -2,6 +2,10 @@ Do this to generate your change history
2
2
 
3
3
  $ git log --pretty=format:' * %h - %s (%an, %ad)' vX.Y.Z..HEAD
4
4
 
5
+ #### 2.0.0.beta.7 (2017-05-12)
6
+ * 741bf96 - Include information about missing verifications in the latest verifications resource. Only set success to be true when all pacts have been successfully verified. (Beth Skurrie, Fri May 12 14:59:48 2017 +1000)
7
+ * 64f20c6 - Allow one, two or three "parts" in the application version number. Eg. 12, 3.4 and 1.2.400 are all valid. (Beth Skurrie, Wed May 10 16:19:07 2017 +1000)
8
+
5
9
  #### 2.0.0.beta.6 (2017-05-09)
6
10
  * 8f1c911 - Ensure all resources provide application/hal+json. (Beth Skurrie, Tue May 9 18:32:37 2017 +1000)
7
11
 
@@ -32,6 +36,11 @@ Do this to generate your change history
32
36
  * 77eaf7b - Added pb:latest-verifications link to version resource. (Beth Skurrie, Tue Apr 11 16:25:45 2017 +1000)
33
37
  * aaf44d9 - Added endpoint to view the latest verifications for a given consumer version. (Beth Skurrie, Tue Apr 11 11:16:03 2017 +1000)
34
38
 
39
+ #### 1.18.0 (2017-05-09)
40
+ * 397060b - Display application versions in reverse order in the Versions resource. (Beth Skurrie, Tue May 9 13:59:54 2017 +1000)
41
+ * 251c878 - Allow application versions to be ordered by creation date where no consistent orderable object can be extracted from the consumer application version. (Beth Skurrie, Tue May 9 13:22:36 2017 +1000)
42
+ * 68bb6d9 - Execute webhooks using sucker punch. (Beth Skurrie, Mon May 8 10:32:45 2017 +1000)
43
+
35
44
  #### 1.17.2 (2017-05-04)
36
45
  * b8f45e1 - fix issue with pact document link not displaying #94 (Matt Fellows, Wed May 3 11:23:09 2017 +1000)
37
46
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Pact Broker
2
2
 
3
- [![Build Status](https://travis-ci.org/bethesque/pact_broker.svg?branch=master)](https://travis-ci.org/bethesque/pact_broker) [![Join the chat at https://gitter.im/bethesque/pact_broker](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bethesque/pact_broker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
3
+ [![Build Status](https://travis-ci.org/pact-foundation/pact_broker.svg?branch=master)](https://travis-ci.org/pact-foundation/pact_broker) [![Join the chat at https://gitter.im/pact-foundation/pact_broker](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pact-foundation/pact_broker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
4
 
5
5
  The Pact Broker provides a repository for consumer driven contracts created using the pact gem.
6
6
 
@@ -23,7 +23,7 @@ Features:
23
23
  * Tracks changes between Pact versions so you can tell when a consumer has changed its expectations.
24
24
  * [Docker Pact Broker][docker]
25
25
 
26
- Travis CI Status: [![Build Status](https://travis-ci.org/bethesque/pact_broker.svg?branch=master)](https://travis-ci.org/bethesque/pact_broker)
26
+ Travis CI Status: [![Build Status](https://travis-ci.org/pact-foundation/pact_broker.svg?branch=master)](https://travis-ci.org/pact-foundation/pact_broker)
27
27
 
28
28
  ### How would I use the Pact Broker?
29
29
 
@@ -41,47 +41,47 @@ If you don't have a [Pact Broker CI Nerf Gun][nerf], you'll probably want to rea
41
41
 
42
42
  ## Documentation
43
43
 
44
- See the [Pact Broker Client](https://github.com/bethesque/pact_broker-client) for documentation on how to publish a pact to the Pact Broker, and configure the URLs in the provider project.
44
+ See the [Pact Broker Client](https://github.com/pact-foundation/pact_broker-client) for documentation on how to publish a pact to the Pact Broker, and configure the URLs in the provider project.
45
45
 
46
- See the [wiki](https://github.com/bethesque/pact_broker/wiki) for documentation related to the Pact Broker itself.
46
+ See the [wiki](https://github.com/pact-foundation/pact_broker/wiki) for documentation related to the Pact Broker itself.
47
47
 
48
48
  ### Screenshots
49
49
 
50
50
  #### Index
51
51
 
52
52
  * * *
53
- <img src="https://raw.githubusercontent.com/wiki/bethesque/pact_broker/images/index.png"/>
53
+ <img src="https://raw.githubusercontent.com/wiki/pact-foundation/pact_broker/images/index.png"/>
54
54
 
55
55
  #### Autogenerated documentation
56
56
 
57
57
  Paste the pact URL into a browser to view a HTML version of the pact.
58
58
  * * *
59
- <img src="https://raw.githubusercontent.com/wiki/bethesque/pact_broker/images/autogenerated_documentation.png"/>
59
+ <img src="https://raw.githubusercontent.com/wiki/pact-foundation/pact_broker/images/autogenerated_documentation.png"/>
60
60
 
61
61
 
62
62
  #### Network diagram
63
63
 
64
64
  * * *
65
- <img src="https://raw.githubusercontent.com/wiki/bethesque/pact_broker/images/network_diagram.png"/>
65
+ <img src="https://raw.githubusercontent.com/wiki/pact-foundation/pact_broker/images/network_diagram.png"/>
66
66
 
67
67
  #### HAL browser
68
68
 
69
69
  Use the embedded HAL browser to navigate the API.
70
70
  * * *
71
- <img src="https://raw.githubusercontent.com/wiki/bethesque/pact_broker/images/hal_browser.png"/>
71
+ <img src="https://raw.githubusercontent.com/wiki/pact-foundation/pact_broker/images/hal_browser.png"/>
72
72
 
73
73
  #### HAL documentation
74
74
 
75
75
  Use the HAL browser to view documentation as you browse.
76
76
  * * *
77
- <img src="https://raw.githubusercontent.com/wiki/bethesque/pact_broker/images/hal_documentation.png"/>
77
+ <img src="https://raw.githubusercontent.com/wiki/pact-foundation/pact_broker/images/hal_documentation.png"/>
78
78
 
79
79
  ## Usage
80
80
 
81
81
  ### To have a play around on your local machine
82
82
 
83
83
  * Install ruby 2.2.0 or later and bundler >= 1.12.0
84
- * Run `git clone git@github.com:bethesque/pact_broker.git && cd pact_broker/example`
84
+ * Run `git clone git@github.com:pact-foundation/pact_broker.git && cd pact_broker/example`
85
85
  * Run `bundle`
86
86
  * Run `bundle exec rackup -p 8080`
87
87
  * Open [http://localhost:8080](http://localhost:8080) and you should see a list containing the pact between the Zoo App and the Animal Service.
@@ -100,7 +100,7 @@ the [Hosted Pact Broker](https://pact.dius.com.au/?utm_source=github&utm_campaig
100
100
  You can use the [Pact Broker Docker container][docker] or [Terraform on AWS][terraform] or to roll your own...
101
101
 
102
102
  * Create a database using a product that is supported by the Sequel gem (listed on this page http://sequel.jeremyevans.net/rdoc/files/README_rdoc.html). The migrations have been tested on MySQL and PostgreSQL - your mileage will vary on other databases.
103
- * __Note:__ It is recommended to use __PostgreSQL__ as it will support JSON search features that are planned in a future release, however MySQL the other [semi supported](https://github.com/bethesque/pact_broker/issues/33) database.
103
+ * __Note:__ It is recommended to use __PostgreSQL__ as it will support JSON search features that are planned in a future release, however MySQL the other [semi supported](https://github.com/pact-foundation/pact_broker/issues/33) database.
104
104
  * Install ruby 2.2.0 or later and bundler >= 1.12.0
105
105
  * Copy the [example](/example) directory to the location you want to install the application.
106
106
  * Modify the config.ru and Gemfile as desired (eg. choose database driver gem, set your database credentials. Use the "pg" gem if using Postgres.)
@@ -110,7 +110,7 @@ You can use the [Pact Broker Docker container][docker] or [Terraform on AWS][ter
110
110
 
111
111
  [decouple]: http://techblog.realestate.com.au/enter-the-pact-matrix-or-how-to-decouple-the-release-cycles-of-your-microservices/
112
112
  [pact]: https://github.com/realestate-com-au/pact
113
- [nerf]: https://github.com/bethesque/pact_broker/wiki/pact-broker-ci-nerf-gun
113
+ [nerf]: https://github.com/pact-foundation/pact_broker/wiki/pact-broker-ci-nerf-gun
114
114
  [different-teams]: https://github.com/realestate-com-au/pact/wiki/Using-pact-where-the-consumer-team-is-different-from-the-provider-team
115
115
  [docker]: https://hub.docker.com/r/dius/pact-broker
116
116
  [terraform]: https://github.com/nadnerb/terraform-pact-broker
@@ -1,10 +1,10 @@
1
1
  Sequel.migration do
2
2
  change do
3
3
  create_view(:all_pacts,
4
- Sequel::Model.db[:pacts].select(:pacts__id, :c__id___consumer_id, :c__name___consumer_name,
5
- :cv__number___consumer_version_number, :cv__order___consumer_version_order,
6
- :p__id___provider_id, :p__name___provider_name,
7
- :pacts__json_content).
4
+ Sequel::Model.db[:pacts].select(Sequel[:pacts][:id], Sequel[:c][:id].as(:consumer_id), Sequel[:c][:name].as(:consumer_name),
5
+ Sequel[:cv][:number].as(:consumer_version_number), Sequel[:cv][:order].as(:consumer_version_order),
6
+ Sequel[:p][:id].as(:provider_id), Sequel[:p][:name].as(:provider_name),
7
+ Sequel[:pacts][:json_content]).
8
8
  join(:versions, {:id => :version_id}, {:table_alias => :cv, implicit_qualifier: :pacts}).
9
9
  join(:pacticipants, {:id => :pacticipant_id}, {:table_alias => :c, implicit_qualifier: :cv}).
10
10
  join(:pacticipants, {:id => :provider_id}, {:table_alias => :p, implicit_qualifier: :pacts}))
@@ -1,10 +1,11 @@
1
1
  Sequel.migration do
2
2
  change do
3
3
  create_or_replace_view(:all_pacts,
4
- Sequel::Model.db[:pacts].select(:pacts__id, :c__id___consumer_id, :c__name___consumer_name,
5
- :cv__number___consumer_version_number, :cv__order___consumer_version_order,
6
- :p__id___provider_id, :p__name___provider_name,
7
- :pacts__json_content, :pacts__created_at, :pacts__updated_at).
4
+ Sequel::Model.db[:pacts].select(
5
+ Sequel[:pacts][:id], Sequel[:c][:id].as(:consumer_id), Sequel[:c][:name].as(:consumer_name),
6
+ Sequel[:cv][:number].as(:consumer_version_number), Sequel[:cv][:order].as(:consumer_version_order),
7
+ Sequel[:p][:id].as(:provider_id), Sequel[:p][:name].as(:provider_name),
8
+ Sequel[:pacts][:json_content], Sequel[:pacts][:created_at], Sequel[:pacts][:updated_at]).
8
9
  join(:versions, {:id => :version_id}, {:table_alias => :cv, implicit_qualifier: :pacts}).
9
10
  join(:pacticipants, {:id => :pacticipant_id}, {:table_alias => :c, implicit_qualifier: :cv}).
10
11
  join(:pacticipants, {:id => :provider_id}, {:table_alias => :p, implicit_qualifier: :pacts}))
@@ -4,15 +4,17 @@ require_relative 'migration_helper'
4
4
  Sequel.migration do
5
5
  change do
6
6
  create_or_replace_view(:all_pacts,
7
- Sequel::Model.db[:pacts].select(:pacts__id,
8
- :c__id___consumer_id, :c__name___consumer_name,
9
- :cv__id___consumer_version_id, :cv__number___consumer_version_number, :cv__order___consumer_version_order,
10
- :p__id___provider_id, :p__name___provider_name,
11
- :pvc__sha___pact_version_content_sha, :pacts__created_at, :pacts__updated_at).
12
- join(:versions, {:id => :version_id}, {:table_alias => :cv, implicit_qualifier: :pacts}).
13
- join(:pacticipants, {:id => :pacticipant_id}, {:table_alias => :c, implicit_qualifier: :cv}).
14
- join(:pacticipants, {:id => :provider_id}, {:table_alias => :p, implicit_qualifier: :pacts}).
15
- join(:pact_version_contents, {:sha => :pact_version_content_sha}, {:table_alias => :pvc, implicit_qualifier: :pacts})
16
- )
7
+ Sequel::Model.db[:pacts].select(
8
+ Sequel[:pacts][:id],
9
+ Sequel[:c][:id].as(:consumer_id), Sequel[:c][:name].as(:consumer_name),
10
+ Sequel[:cv][:id].as(:consumer_version_id), Sequel[:cv][:number].as(:consumer_version_number), Sequel[:cv][:order].as(:consumer_version_order),
11
+ Sequel[:p][:id].as(:provider_id), Sequel[:p][:name].as(:provider_name),
12
+ Sequel[:pvc][:sha].as(:pact_version_content_sha), Sequel[:pacts][:created_at], Sequel[:pacts][:updated_at]).
13
+ join(:versions, {:id => :version_id}, {:table_alias => :cv, implicit_qualifier: :pacts}).
14
+ join(:pacticipants, {:id => :pacticipant_id}, {:table_alias => :c, implicit_qualifier: :cv}).
15
+ join(:pacticipants, {:id => :provider_id}, {:table_alias => :p, implicit_qualifier: :pacts}).
16
+ join(:pact_version_contents, {:sha => :pact_version_content_sha}, {:table_alias => :pvc, implicit_qualifier: :pacts})
17
+ )
18
+
17
19
  end
18
20
  end
@@ -2,11 +2,12 @@ Sequel.migration do
2
2
  up do
3
3
  # The denormalised pact publication details for each publication
4
4
  create_view(:all_pact_publications,
5
- Sequel::Model.db[:pact_publications].select(:pact_publications__id,
6
- :c__id___consumer_id, :c__name___consumer_name,
7
- :cv__id___consumer_version_id, :cv__number___consumer_version_number, :cv__order___consumer_version_order,
8
- :p__id___provider_id, :p__name___provider_name,
9
- :pact_publications__revision_number, :pv__id___pact_version_id, :pv__sha___pact_version_sha, :pact_publications__created_at).
5
+ Sequel::Model.db[:pact_publications].select(
6
+ Sequel[:pact_publications][:id],
7
+ Sequel[:c][:id].as(:consumer_id), Sequel[:c][:name].as(:consumer_name),
8
+ Sequel[:cv][:id].as(:consumer_version_id), Sequel[:cv][:number].as(:consumer_version_number), Sequel[:cv][:order].as(:consumer_version_order),
9
+ Sequel[:p][:id].as(:provider_id), Sequel[:p][:name].as(:provider_name),
10
+ Sequel[:pact_publications][:revision_number], Sequel[:pv][:id].as(:pact_version_id), Sequel[:pv][:sha].as(:pact_version_sha), Sequel[:pact_publications][:created_at]).
10
11
  join(:versions, {:id => :consumer_version_id}, {:table_alias => :cv, implicit_qualifier: :pact_publications}).
11
12
  join(:pacticipants, {:id => :pacticipant_id}, {:table_alias => :c, implicit_qualifier: :cv}).
12
13
  join(:pacticipants, {:id => :provider_id}, {:table_alias => :p, implicit_qualifier: :pact_publications}).
@@ -27,9 +27,6 @@ module PactBroker
27
27
  }
28
28
  end
29
29
 
30
- def provider_name
31
- represented.provider_name
32
- end
33
30
  end
34
31
  end
35
32
  end
@@ -0,0 +1,36 @@
1
+ require_relative 'base_decorator'
2
+ require_relative 'version_decorator'
3
+ require 'ostruct'
4
+
5
+ module PactBroker
6
+ module Api
7
+ module Decorators
8
+
9
+ class VerificationSummaryDecorator < BaseDecorator
10
+
11
+ property :success
12
+ property :provider_summary, as: :providerSummary do
13
+ property :successful
14
+ property :failed
15
+ property :unknown
16
+ end
17
+
18
+ collection :verifications, as: :verificationResults, embedded: true, :extend => PactBroker::Api::Decorators::VerificationDecorator
19
+
20
+ link :self do | context |
21
+ {
22
+ href: context.fetch(:resource_url),
23
+ title: "Latest verification results for consumer #{context.fetch(:consumer_name)} version #{context.fetch(:consumer_version_number)}"
24
+ }
25
+ end
26
+
27
+ def provider_summary
28
+ OpenStruct.new(
29
+ successful: represented.select(&:success).collect(&:provider_name),
30
+ failed: represented.select{|verification| !verification.success }.collect(&:provider_name))
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -15,7 +15,7 @@ module PactBroker
15
15
  link :self do | context |
16
16
  {
17
17
  href: context[:resource_url],
18
- title: "All versions of the pacticipant #{context[:pacticipant_name]}"
18
+ title: "All application versions of #{context[:pacticipant_name]}"
19
19
  }
20
20
  end
21
21
 
@@ -2,7 +2,7 @@ require 'pact_broker/api/resources/base_resource'
2
2
  require 'pact_broker/configuration'
3
3
  require 'pact_broker/domain/verification'
4
4
  require 'pact_broker/api/contracts/verification_contract'
5
- require 'pact_broker/api/decorators/verifications_decorator'
5
+ require 'pact_broker/api/decorators/verification_summary_decorator'
6
6
 
7
7
  module PactBroker
8
8
  module Api
@@ -24,14 +24,14 @@ module PactBroker
24
24
  end
25
25
 
26
26
  def to_json
27
- verifications = verification_service.find_latest_verifications_for_consumer_version(identifier_from_path)
28
- decorator_for(verifications).to_json(user_options: decorator_context(identifier_from_path))
27
+ summary = verification_service.verification_summary_for_consumer_version(identifier_from_path)
28
+ decorator_for(summary).to_json(user_options: decorator_context(identifier_from_path))
29
29
  end
30
30
 
31
31
  private
32
32
 
33
- def decorator_for verifications
34
- PactBroker::Api::Decorators::VerificationsDecorator.new(verifications)
33
+ def decorator_for summary
34
+ PactBroker::Api::Decorators::VerificationSummaryDecorator.new(summary)
35
35
  end
36
36
  end
37
37
  end
@@ -25,7 +25,7 @@ module PactBroker
25
25
  end
26
26
 
27
27
  def versions
28
- pacticipant_service.find_all_pacticipant_versions pacticipant_name
28
+ pacticipant_service.find_all_pacticipant_versions_in_reverse_order pacticipant_name
29
29
  end
30
30
 
31
31
  end
@@ -3,6 +3,7 @@ require 'pact_broker/db'
3
3
  require 'pact_broker/project_root'
4
4
  require 'rack/hal_browser'
5
5
  require 'rack/pact_broker/convert_file_extension_to_accept_header'
6
+ require 'sucker_punch'
6
7
 
7
8
  module PactBroker
8
9
 
@@ -32,6 +33,7 @@ module PactBroker
32
33
  PactBroker::DB.connection = configuration.database_connection
33
34
  PactBroker::DB.connection.timezone = :utc
34
35
  PactBroker::DB.validate_connection_config if configuration.validate_database_connection_config
36
+ SuckerPunch.logger = configuration.logger
35
37
 
36
38
  if configuration.auto_migrate_db
37
39
  logger.info "Migrating database"
@@ -8,7 +8,8 @@ module PactBroker
8
8
 
9
9
  attr_accessor :log_dir, :database_connection, :auto_migrate_db, :use_hal_browser, :html_pact_renderer
10
10
  attr_accessor :validate_database_connection_config, :enable_diagnostic_endpoints, :version_parser
11
- attr_accessor :use_case_sensitive_resource_names
11
+ attr_accessor :use_case_sensitive_resource_names, :order_versions_by_date
12
+ attr_accessor :semver_formats
12
13
  attr_writer :logger
13
14
 
14
15
  def logger
@@ -26,6 +27,10 @@ module PactBroker
26
27
  config.use_case_sensitive_resource_names = true
27
28
  config.html_pact_renderer = default_html_pact_render
28
29
  config.version_parser = PactBroker::Versions::ParseSemanticVersion
30
+ # Not recommended to set this to true unless there is no way to
31
+ # consistently extract an orderable object from the consumer application version number.
32
+ config.order_versions_by_date = false
33
+ config.semver_formats = ["%M.%m.%p%s%d","%M.%m", "%M"]
29
34
  config
30
35
  end
31
36
 
@@ -4,9 +4,17 @@ module PactBroker
4
4
  module Domain
5
5
  class OrderVersions
6
6
 
7
+ include PactBroker::Logging
8
+ # TODO select for update
7
9
  def self.call pacticipant_id
8
- orderable_versions = PactBroker::Domain::Version.where(:pacticipant_id => pacticipant_id).all.collect{| version | OrderableVersion.new(version) }
9
- orderable_versions.sort.each_with_index{ | version, i | version.update_model(i) }
10
+
11
+ orderable_versions = PactBroker::Domain::Version.for_update.where(:pacticipant_id => pacticipant_id).order(:created_at, :id).collect{| version | OrderableVersion.new(version) }
12
+ ordered_versions = if PactBroker.configuration.order_versions_by_date
13
+ orderable_versions # already ordered in SQL
14
+ else
15
+ orderable_versions.sort
16
+ end
17
+ ordered_versions.each_with_index{ | version, i | version.update_model(i) }
10
18
  end
11
19
 
12
20
  class OrderableVersion
@@ -23,9 +31,11 @@ module PactBroker
23
31
  end
24
32
 
25
33
  def update_model new_order
26
- # Sequel will only run the update if the column value has changed, so in 99% of
27
- # cases, only one update will occur.
28
- version_model.update(:order => new_order)
34
+ if version_model.order != new_order
35
+ # Avoid modifying the updated_at flag by doing a manual update
36
+ # In 99% of cases, this will only set the order of the most recent version
37
+ PactBroker::Domain::Version.where(id: version_model.id).update(order: new_order)
38
+ end
29
39
  end
30
40
  end
31
41
  end
@@ -38,7 +38,7 @@ module PactBroker
38
38
  end
39
39
 
40
40
  def verification_number number
41
- where("`verifications`.`number` = ? ", number)
41
+ where(Sequel.qualify("verifications", "number") => number)
42
42
  end
43
43
 
44
44
  def latest
@@ -33,7 +33,6 @@ module PactBroker
33
33
  request && request.description
34
34
  end
35
35
 
36
- #TODO retries
37
36
  def execute
38
37
  logger.info "Executing #{self}"
39
38
  request.execute
@@ -22,7 +22,7 @@ module PactBroker
22
22
  include PactBroker::Logging
23
23
  include PactBroker::Messages
24
24
 
25
- attr_accessor :method, :url, :headers, :body, :username, :password
25
+ attr_accessor :method, :url, :headers, :body, :username, :password, :uuid
26
26
 
27
27
  # Reform gets confused by the :method method, as :method is a standard
28
28
  # Ruby method.
@@ -35,6 +35,7 @@ module PactBroker
35
35
  @password = attributes[:password]
36
36
  @headers = attributes[:headers] || {}
37
37
  @body = attributes[:body]
38
+ @uuid = attributes[:uuid]
38
39
  end
39
40
 
40
41
  def description
@@ -64,17 +65,18 @@ module PactBroker
64
65
  end
65
66
  end
66
67
 
67
- logger.info "Making webhook request #{to_s}"
68
+ logger.info "Making webhook #{uuid} request #{to_s}"
68
69
  response = Net::HTTP.start(uri.hostname, uri.port,
69
70
  :use_ssl => uri.scheme == 'https') do |http|
70
71
  http.request req
71
72
  end
72
73
 
73
- logger.info "Received response status=#{response.code} body=#{response.body}"
74
+ logger.info "Received response for webhook #{uuid} status=#{response.code}"
75
+ logger.debug "body=#{response.body}"
74
76
  WebhookExecutionResult.new(response)
75
77
 
76
78
  rescue StandardError => e
77
- logger.error "Error executing webhook #{e.class.name} - #{e.message}"
79
+ logger.error "Error executing webhook #{uuid} #{e.class.name} - #{e.message}"
78
80
  logger.error e.backtrace.join("\n")
79
81
  WebhookExecutionResult.new(nil, e)
80
82
  end
@@ -17,6 +17,10 @@ module PactBroker
17
17
  @@logger = logger
18
18
  end
19
19
 
20
+ def log_error e
21
+ logger.error "#{e.class} #{e.message} #{e.backtrace.join("\n")}"
22
+ end
23
+
20
24
  def logger
21
25
  @@logger ||= begin
22
26
  FileUtils.mkdir_p(LOG_DIR)
@@ -20,11 +20,12 @@ module PactBroker
20
20
  PactBroker::Domain::Pacticipant.order(:name).all
21
21
  end
22
22
 
23
- def find_all_pacticipant_versions name
23
+ def find_all_pacticipant_versions_in_reverse_order name
24
24
  PactBroker::Domain::Version
25
- .select(:versions__id, :versions__number, :versions__pacticipant_id, :versions__order, :versions__created_at, :versions__updated_at)
25
+ .select(Sequel[:versions][:id], Sequel[:versions][:number], Sequel[:versions][:pacticipant_id], Sequel[:versions][:order], Sequel[:versions][:created_at], Sequel[:versions][:updated_at])
26
26
  .join(:pacticipants, {id: :pacticipant_id})
27
27
  .where(name_like(:name, name))
28
+ .reverse_order(:order)
28
29
  end
29
30
 
30
31
  def find_by_name_or_create name