-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rspec failures pipeline config v5 (gocd#5274)
* Replace all the occurances of apiv5_admin_pipeline_url with spark pipeline config v6 url * Add materials representer to ApiV1 module * Do not refer to representers from other module. * Replace all occurances of default_url_options with incoming request to construct URL
- Loading branch information
1 parent
880f5a1
commit e5bdf9e
Showing
21 changed files
with
1,207 additions
and
14 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
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
32 changes: 32 additions & 0 deletions
32
.../rails/app/presenters/api_v1/admin/pipelines/materials/dependency_material_representer.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,32 @@ | ||
########################################################################## | ||
# Copyright 2017 ThoughtWorks, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
########################################################################## | ||
|
||
module ApiV1 | ||
module Admin | ||
module Pipelines | ||
module Materials | ||
class DependencyMaterialRepresenter < BaseRepresenter | ||
alias_method :material_config, :represented | ||
|
||
property :pipeline_name, as: :pipeline, case_insensitive_string: true | ||
property :stage_name, as: :stage, case_insensitive_string: true | ||
property :name, case_insensitive_string: true | ||
property :auto_update | ||
end | ||
end | ||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
...B-INF/rails/app/presenters/api_v1/admin/pipelines/materials/encrypted_password_support.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,33 @@ | ||
########################################################################## | ||
# Copyright 2017 ThoughtWorks, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
########################################################################## | ||
|
||
module ApiV1 | ||
module Admin | ||
module Pipelines | ||
module Materials | ||
module EncryptedPasswordSupport | ||
def from_hash(data, options={}) | ||
super | ||
data = data.with_indifferent_access | ||
encrypted_password = Services.password_deserializer.deserialize(data[:password], data[:encrypted_password], represented) | ||
represented.setEncryptedPassword(encrypted_password) | ||
represented | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
39 changes: 39 additions & 0 deletions
39
...ebapp/WEB-INF/rails/app/presenters/api_v1/admin/pipelines/materials/filter_representer.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,39 @@ | ||
########################################################################## | ||
# Copyright 2017 ThoughtWorks, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
########################################################################## | ||
|
||
module ApiV1 | ||
module Admin | ||
module Pipelines | ||
module Materials | ||
class FilterRepresenter < BaseRepresenter | ||
alias_method :filter, :represented | ||
|
||
collection :ignore, exec_context: :decorator | ||
|
||
def to_hash(*options) | ||
ignored_files=filter.map { |item| item.getPattern() } | ||
{ignore: ignored_files} if !ignored_files.empty? | ||
end | ||
|
||
def ignore=(value) | ||
filter.clear() | ||
value.each { |pattern| filter.add(IgnoredFiles.new(pattern)) } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
36 changes: 36 additions & 0 deletions
36
...WEB-INF/rails/app/presenters/api_v1/admin/pipelines/materials/git_material_representer.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,36 @@ | ||
########################################################################## | ||
# Copyright 2017 ThoughtWorks, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
########################################################################## | ||
|
||
module ApiV1 | ||
module Admin | ||
module Pipelines | ||
module Materials | ||
class GitMaterialRepresenter < ScmMaterialRepresenter | ||
property :branch, | ||
getter: lambda { |args| | ||
branch = self.getBranch | ||
branch.blank? ? 'master' : branch | ||
}, | ||
setter: lambda { |value, options| | ||
value.blank? ? self.setBranch('master') : self.setBranch(value) | ||
} | ||
property :submodule_folder | ||
property :shallow_clone | ||
end | ||
end | ||
end | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
.../WEB-INF/rails/app/presenters/api_v1/admin/pipelines/materials/hg_material_representer.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,26 @@ | ||
########################################################################## | ||
# Copyright 2017 ThoughtWorks, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
########################################################################## | ||
|
||
module ApiV1 | ||
module Admin | ||
module Pipelines | ||
module Materials | ||
class HgMaterialRepresenter < ScmMaterialRepresenter | ||
end | ||
end | ||
end | ||
end | ||
end |
81 changes: 81 additions & 0 deletions
81
...app/WEB-INF/rails/app/presenters/api_v1/admin/pipelines/materials/material_representer.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,81 @@ | ||
########################################################################## | ||
# Copyright 2017 ThoughtWorks, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
########################################################################## | ||
|
||
module ApiV1 | ||
module Admin | ||
module Pipelines | ||
module Materials | ||
class MaterialRepresenter < BaseRepresenter | ||
TYPE_TO_MATERIAL_MAP = { | ||
'git' => GitMaterialConfig, | ||
'svn' => SvnMaterialConfig, | ||
'hg' => HgMaterialConfig, | ||
'p4' => P4MaterialConfig, | ||
'tfs' => TfsMaterialConfig, | ||
'dependency' => DependencyMaterialConfig, | ||
'package' => PackageMaterialConfig, | ||
'plugin' => PluggableSCMMaterialConfig | ||
} | ||
|
||
MATERIAL_TO_TYPE_MAP = TYPE_TO_MATERIAL_MAP.invert | ||
|
||
MATERIAL_TYPE_TO_REPRESENTER_MAP = { | ||
GitMaterialConfig => GitMaterialRepresenter, | ||
SvnMaterialConfig => SvnMaterialRepresenter, | ||
HgMaterialConfig => HgMaterialRepresenter, | ||
P4MaterialConfig => PerforceMaterialRepresenter, | ||
TfsMaterialConfig => TfsMaterialRepresenter, | ||
DependencyMaterialConfig => DependencyMaterialRepresenter, | ||
PackageMaterialConfig => PackageMaterialRepresenter, | ||
PluggableSCMMaterialConfig => PluggableScmMaterialRepresenter | ||
} | ||
alias_method :material_config, :represented | ||
|
||
error_representer({ | ||
"materialName" => "name", | ||
"folder" => "destination", | ||
"autoUpdate" => "auto_update", | ||
"filterAsString" => "filter", | ||
"checkexternals" => "check_externals", | ||
"serverAndPort" => "port", | ||
"useTickets" => "use_tickets", | ||
"pipelineName" => "pipeline", | ||
"stageName" => "stage", | ||
"pipelineStageName" => "pipeline", | ||
"packageId" => "ref", | ||
"scmId" => "ref", | ||
"password" => "password", | ||
"encryptedPassword" => "encrypted_password", | ||
} | ||
) | ||
|
||
property :type, getter: lambda { |options| MATERIAL_TO_TYPE_MAP[self.class] }, skip_parse: true | ||
|
||
nested :attributes, | ||
decorator: lambda { |material_config, *| | ||
MATERIAL_TYPE_TO_REPRESENTER_MAP[material_config.class] | ||
} | ||
|
||
class << self | ||
def get_material_type(type) | ||
TYPE_TO_MATERIAL_MAP[type] or (raise UnprocessableEntity, "Invalid material type '#{type}'. It has to be one of '#{TYPE_TO_MATERIAL_MAP.keys.join(' ')}'") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
...INF/rails/app/presenters/api_v1/admin/pipelines/materials/package_material_representer.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,33 @@ | ||
########################################################################## | ||
# Copyright 2017 ThoughtWorks, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
########################################################################## | ||
|
||
module ApiV1 | ||
module Admin | ||
module Pipelines | ||
module Materials | ||
class PackageMaterialRepresenter < BaseRepresenter | ||
alias_method :material_config, :represented | ||
|
||
property :packageId, as: :ref, setter: lambda { |value, options| | ||
package_definition = options[:go_config].getPackageRepositories().findPackageDefinitionWith(value) | ||
self.setPackageDefinition(package_definition) | ||
self.setPackageId(value) | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
39 changes: 39 additions & 0 deletions
39
...NF/rails/app/presenters/api_v1/admin/pipelines/materials/perforce_material_representer.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,39 @@ | ||
########################################################################## | ||
# Copyright 2017 ThoughtWorks, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
########################################################################## | ||
|
||
module ApiV1 | ||
module Admin | ||
module Pipelines | ||
module Materials | ||
class PerforceMaterialRepresenter < ScmMaterialRepresenter | ||
include EncryptedPasswordSupport | ||
|
||
property :url, skip_render: true, skip_parse: true #This is done so as to avoid setting the url property of super class ScmMaterialConfig | ||
property :server_and_port, as: :port | ||
property :user_name, as: :username | ||
property :password, | ||
skip_render: true, | ||
skip_nil: true, | ||
skip_parse: true | ||
|
||
property :encrypted_password, skip_nil: true, skip_parse: true | ||
property :use_tickets | ||
property :view | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.