-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add repository and branch properties to pacticipant
* feat: add repository and display name properties to pacticipant * feat: add mainDevelopmentBranches to pacticipant * feat: automatically populate display name for pacticipants and migrate existing data * chore: validate put pacticipant
- Loading branch information
Showing
27 changed files
with
488 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Sequel.migration do | ||
change do | ||
alter_table(:pacticipants) do | ||
add_column(:display_name, String) | ||
add_column(:repository_name, String) | ||
add_column(:repository_namespace, String) | ||
add_column(:main_development_branches, String) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'dry-validation' | ||
require 'pact_broker/api/contracts/dry_validation_workarounds' | ||
require 'pact_broker/api/contracts/dry_validation_predicates' | ||
require 'pact_broker/messages' | ||
|
||
module PactBroker | ||
module Api | ||
module Contracts | ||
class PacticipantSchema | ||
extend DryValidationWorkarounds | ||
extend PactBroker::Messages | ||
using PactBroker::HashRefinements | ||
|
||
SCHEMA = Dry::Validation.Schema do | ||
configure do | ||
predicates(DryValidationPredicates) | ||
config.messages_file = File.expand_path("../../../locale/en.yml", __FILE__) | ||
end | ||
optional(:name).filled(:str?, :single_line?) | ||
optional(:displayName).maybe(:str?, :single_line?, :not_blank?) | ||
optional(:mainDevelopmentBranches).each(:str?, :single_line?, :no_spaces?) | ||
optional(:repositoryUrl).maybe(:str?, :single_line?) | ||
optional(:repositoryName).maybe(:str?, :single_line?) | ||
optional(:repositoryNamespace).maybe(:str?, :single_line?) | ||
end | ||
|
||
def self.call(params_with_string_keys) | ||
params = params_with_string_keys&.symbolize_keys | ||
select_first_message(flatten_indexed_messages(SCHEMA.call(params).messages(full: true))) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
lib/pact_broker/db/data_migrations/set_pacticipant_display_name.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'pact_broker/db/data_migrations/helpers' | ||
require 'pact_broker/pacticipants/generate_display_name' | ||
|
||
module PactBroker | ||
module DB | ||
module DataMigrations | ||
class SetPacticipantDisplayName | ||
extend Helpers | ||
extend PactBroker::Pacticipants::GenerateDisplayName | ||
|
||
def self.call(connection) | ||
if columns_exist?(connection, :pacticipants, [:name, :display_name]) | ||
connection[:pacticipants].where(display_name: nil).each do | row | | ||
connection[:pacticipants] | ||
.where(id: row[:id]) | ||
.update(display_name: generate_display_name(row[:name])) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'pact_broker/string_refinements' | ||
|
||
module PactBroker | ||
module Pacticipants | ||
module GenerateDisplayName | ||
using PactBroker::StringRefinements | ||
|
||
def self.call(name) | ||
return nil if name.nil? | ||
name | ||
.to_s | ||
.gsub(/([A-Z])([A-Z])([a-z])/,'\1 \2\3') | ||
.gsub(/([a-z\d])([A-Z])(\S)/,'\1 \2\3') | ||
.gsub(/(\S)([\-_\s\.])(\S)/, '\1 \3') | ||
.gsub(/\s+/, " ") | ||
.strip | ||
.split(" ") | ||
.collect{ |word| word.camelcase(true) } | ||
.join(" ") | ||
end | ||
|
||
def generate_display_name(name) | ||
GenerateDisplayName.call(name) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.