Commit cb83b95e authored by Robert Speicher's avatar Robert Speicher

Merge branch 'master' into 'master'

Update ExternalIssue regex for JIRA integration

The pattern in the `::reference_pattern` class method in the
`ExternalIssue` model does not match all valid forms of JIRA project
names. I have updated the regex to match JIRA project names with numbers
and underscores. More information on valid JIRA project names can be
found here:

* The first character must be a letter,
* All letters used in the project key must be from the Modern Roman Alphabet and upper case, and
* Only letters, numbers or the underscore character can be used.

See merge request !2598
parents 95c644df 4be65c32
......@@ -19,6 +19,7 @@ v 8.4.1
and Nokogiri (
- Fix redirect loop during import
- Fix diff highlighting for all syntax themes
- Update the ExternalIssue regex pattern (Blake Hitchcock)
v 8.4.0
- Allow LDAP users to change their email if it was not set by the LDAP server
......@@ -31,7 +31,7 @@ def project
# Pattern used to extract `JIRA-123` issue references from text
def self.reference_pattern
def to_reference(_from_project = nil)
......@@ -176,7 +176,7 @@ def host(url)
Settings.gitlab['twitter_sharing_enabled'] ||= true if Settings.gitlab['twitter_sharing_enabled'].nil?
Settings.gitlab['restricted_visibility_levels'] = Settings.send(:verify_constant_array, Gitlab::VisibilityLevel, Settings.gitlab['restricted_visibility_levels'], [])
Settings.gitlab['username_changing_enabled'] = true if Settings.gitlab['username_changing_enabled'].nil?
Settings.gitlab['issue_closing_pattern'] = '((?:[Cc]los(?:e[sd]?|ing)|[Ff]ix(?:e[sd]|ing)?|[Rr]esolv(?:e[sd]?|ing)) +(?:(?:issues? +)?%{issue_ref}(?:(?:, *| +and +)?)|([A-Z]*-\d*))+)' if Settings.gitlab['issue_closing_pattern'].nil?
Settings.gitlab['issue_closing_pattern'] = '((?:[Cc]los(?:e[sd]?|ing)|[Ff]ix(?:e[sd]|ing)?|[Rr]esolv(?:e[sd]?|ing)) +(?:(?:issues? +)?%{issue_ref}(?:(?:, *| +and +)?)|([A-Z][A-Z0-9_]+-\d+))+)' if Settings.gitlab['issue_closing_pattern'].nil?
Settings.gitlab['default_projects_features'] ||= {}
Settings.gitlab['webhook_timeout'] ||= 10
Settings.gitlab['max_attachment_size'] ||= 10
......@@ -135,6 +135,17 @@
message = "resolve #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
context 'with an external issue tracker reference' do
it 'extracts the referenced issue' do
jira_project = create(:jira_project, name: 'JIRA_EXT1')
jira_issue ="#{}-1", project: jira_project)
closing_issue_extractor = jira_project
message = "Resolve #{jira_issue.to_reference}"
expect(closing_issue_extractor.closed_by_message(message)).to eq([jira_issue])
context "with a cross-project reference" do
......@@ -10,6 +10,21 @@
it { include_module(Referable) }
describe '.reference_pattern' do
it 'allows underscores in the project name' do
expect(ExternalIssue.reference_pattern.match('EXT_EXT-1234')[0]).to eq 'EXT_EXT-1234'
it 'allows numbers in the project name' do
expect(ExternalIssue.reference_pattern.match('EXT3_EXT-1234')[0]).to eq 'EXT3_EXT-1234'
it 'requires the project name to begin with A-Z' do
expect(ExternalIssue.reference_pattern.match('3EXT_EXT-1234')).to eq nil
expect(ExternalIssue.reference_pattern.match('EXT_EXT-1234')[0]).to eq 'EXT_EXT-1234'
describe '#to_reference' do
it 'returns a String reference to the object' do
expect(issue.to_reference).to eq
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment