Skip to content
Snippets Groups Projects
Unverified Commit 84c9093b authored by Markus Koller's avatar Markus Koller
Browse files

Fix static translations in integrations

We need to wrap these in a proc, otherwise they're evaluated when
the class is loaded and will always be in English.

For the CI integrations this was an oversight when we refactored them
to use the DSL in
!86453.

The validation message in Jira was a pre-existing bug which we noticed
due to the improvements to the `StaticTranslationDefinition` cop in
!89945.

This also adds missing specs for all Jira validations.

Changelog: fixed
parent 90a0d592
No related branches found
No related tags found
1 merge request!89833Fix static translations in integrations
......@@ -6,13 +6,6 @@ Cop/StaticTranslationDefinition:
- 'app/models/diff_viewer/rich.rb'
- 'app/models/diff_viewer/simple.rb'
- 'app/models/group_group_link.rb'
- 'app/models/integrations/bamboo.rb'
- 'app/models/integrations/buildkite.rb'
- 'app/models/integrations/drone_ci.rb'
- 'app/models/integrations/jenkins.rb'
- 'app/models/integrations/jira.rb'
- 'app/models/integrations/mock_ci.rb'
- 'app/models/integrations/teamcity.rb'
- 'app/models/jira_import_state.rb'
- 'app/models/member.rb'
- 'app/models/project.rb'
......
......@@ -6,25 +6,25 @@ class Bamboo < BaseCi
prepend EnableSslVerification
field :bamboo_url,
title: s_('BambooService|Bamboo URL'),
placeholder: s_('https://bamboo.example.com'),
help: s_('BambooService|Bamboo service root URL.'),
title: -> { s_('BambooService|Bamboo URL') },
placeholder: -> { s_('https://bamboo.example.com') },
help: -> { s_('BambooService|Bamboo service root URL.') },
required: true
field :build_key,
help: s_('BambooService|Bamboo build plan key.'),
non_empty_password_title: s_('BambooService|Enter new build key'),
non_empty_password_help: s_('BambooService|Leave blank to use your current build key.'),
placeholder: s_('KEY'),
help: -> { s_('BambooService|Bamboo build plan key.') },
non_empty_password_title: -> { s_('BambooService|Enter new build key') },
non_empty_password_help: -> { s_('BambooService|Leave blank to use your current build key.') },
placeholder: -> { s_('KEY') },
required: true
field :username,
help: s_('BambooService|The user with API access to the Bamboo server.')
help: -> { s_('BambooService|The user with API access to the Bamboo server.') }
field :password,
type: 'password',
non_empty_password_title: s_('ProjectService|Enter new password'),
non_empty_password_help: s_('ProjectService|Leave blank to use your current password')
non_empty_password_title: -> { s_('ProjectService|Enter new password') },
non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current password') }
validates :bamboo_url, presence: true, public_url: true, if: :activated?
validates :build_key, presence: true, if: :activated?
......
......@@ -11,16 +11,18 @@ class Buildkite < BaseCi
ENDPOINT = "https://buildkite.com"
field :project_url,
title: _('Pipeline URL'),
title: -> { _('Pipeline URL') },
placeholder: "#{ENDPOINT}/example-org/test-pipeline",
required: true
field :token,
type: 'password',
title: _('Token'),
help: s_('ProjectService|The token you get after you create a Buildkite pipeline with a GitLab repository.'),
non_empty_password_title: s_('ProjectService|Enter new token'),
non_empty_password_help: s_('ProjectService|Leave blank to use your current token.'),
title: -> { _('Token') },
help: -> do
s_('ProjectService|The token you get after you create a Buildkite pipeline with a GitLab repository.')
end,
non_empty_password_title: -> { s_('ProjectService|Enter new token') },
non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current token.') },
required: true
validates :project_url, presence: true, public_url: true, if: :activated?
......
......@@ -11,15 +11,15 @@ class DroneCi < BaseCi
DRONE_SAAS_HOSTNAME = 'cloud.drone.io'
field :drone_url,
title: s_('ProjectService|Drone server URL'),
title: -> { s_('ProjectService|Drone server URL') },
placeholder: 'http://drone.example.com',
required: true
field :token,
type: 'password',
help: s_('ProjectService|Token for the Drone project.'),
non_empty_password_title: s_('ProjectService|Enter new token'),
non_empty_password_help: s_('ProjectService|Leave blank to use your current token.'),
help: -> { s_('ProjectService|Token for the Drone project.') },
non_empty_password_title: -> { s_('ProjectService|Enter new token') },
non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current token.') },
required: true
validates :drone_url, presence: true, public_url: true, if: :activated?
......
......@@ -8,24 +8,24 @@ class Jenkins < BaseCi
extend Gitlab::Utils::Override
field :jenkins_url,
title: s_('ProjectService|Jenkins server URL'),
title: -> { s_('ProjectService|Jenkins server URL') },
required: true,
placeholder: 'http://jenkins.example.com',
help: s_('The URL of the Jenkins server.')
help: -> { s_('The URL of the Jenkins server.') }
field :project_name,
required: true,
placeholder: 'my_project_name',
help: s_('The name of the Jenkins project. Copy the name from the end of the URL to the project.')
help: -> { s_('The name of the Jenkins project. Copy the name from the end of the URL to the project.') }
field :username,
help: s_('The username for the Jenkins server.')
help: -> { s_('The username for the Jenkins server.') }
field :password,
type: 'password',
help: s_('The password for the Jenkins server.'),
non_empty_password_title: s_('ProjectService|Enter new password.'),
non_empty_password_help: s_('ProjectService|Leave blank to use your current password.')
help: -> { s_('The password for the Jenkins server.') },
non_empty_password_title: -> { s_('ProjectService|Enter new password.') },
non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current password.') }
before_validation :reset_password
......
......@@ -24,7 +24,10 @@ class Jira < BaseIssueTracker
validates :password, presence: true, if: :activated?
validates :jira_issue_transition_id,
format: { with: Gitlab::Regex.jira_transition_id_regex, message: s_("JiraService|IDs must be a list of numbers that can be split with , or ;") },
format: {
with: Gitlab::Regex.jira_transition_id_regex,
message: ->(*_) { s_("JiraService|IDs must be a list of numbers that can be split with , or ;") }
},
allow_blank: true
# Jira Cloud version is deprecating authentication via username and password.
......
......@@ -8,7 +8,7 @@ class MockCi < BaseCi
ALLOWED_STATES = %w[failed canceled running pending success success-with-warnings skipped not_found].freeze
field :mock_service_url,
title: s_('ProjectService|Mock service URL'),
title: -> { s_('ProjectService|Mock service URL') },
placeholder: 'http://localhost:4004',
required: true
......
......@@ -9,21 +9,21 @@ class Teamcity < BaseCi
TEAMCITY_SAAS_HOSTNAME = /\A[^\.]+\.teamcity\.com\z/i.freeze
field :teamcity_url,
title: s_('ProjectService|TeamCity server URL'),
title: -> { s_('ProjectService|TeamCity server URL') },
placeholder: 'https://teamcity.example.com',
required: true
field :build_type,
help: s_('ProjectService|The build configuration ID of the TeamCity project.'),
help: -> { s_('ProjectService|The build configuration ID of the TeamCity project.') },
required: true
field :username,
help: s_('ProjectService|Must have permission to trigger a manual build in TeamCity.')
help: -> { s_('ProjectService|Must have permission to trigger a manual build in TeamCity.') }
field :password,
type: 'password',
non_empty_password_title: s_('ProjectService|Enter new password'),
non_empty_password_help: s_('ProjectService|Leave blank to use your current password')
non_empty_password_title: -> { s_('ProjectService|Enter new password') },
non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current password') }
validates :teamcity_url, presence: true, public_url: true, if: :activated?
validates :build_type, presence: true, if: :activated?
......
......@@ -31,6 +31,61 @@
let(:integration) { jira_integration }
end
describe 'validations' do
subject { jira_integration }
context 'when integration is active' do
before do
jira_integration.active = true
# Don't auto-fill URLs from gitlab.yml
stub_config(issues_tracker: {})
end
it { is_expected.to be_valid }
it { is_expected.to validate_presence_of(:url) }
it { is_expected.to validate_presence_of(:username) }
it { is_expected.to validate_presence_of(:password) }
it_behaves_like 'issue tracker integration URL attribute', :url
it_behaves_like 'issue tracker integration URL attribute', :api_url
end
context 'when integration is inactive' do
before do
jira_integration.active = false
end
it { is_expected.to be_valid }
it { is_expected.not_to validate_presence_of(:url) }
it { is_expected.not_to validate_presence_of(:username) }
it { is_expected.not_to validate_presence_of(:password) }
end
describe 'jira_issue_transition_id' do
it 'accepts a blank value' do
jira_integration.jira_issue_transition_id = ' '
expect(jira_integration).to be_valid
end
it 'accepts any string containing numbers' do
jira_integration.jira_issue_transition_id = 'foo 23 bar'
expect(jira_integration).to be_valid
end
it 'does not accept a string without numbers' do
jira_integration.jira_issue_transition_id = 'foo bar'
expect(jira_integration).not_to be_valid
expect(jira_integration.errors.full_messages).to eq([
'Jira issue transition IDs must be a list of numbers that can be split with , or ;'
])
end
end
end
describe '#options' do
let(:options) do
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment