Commit afc637ff authored by Stan Hu's avatar Stan Hu

Relax Danger commit linter to allow values surrounded by backticks

Previously the commit linter would flag `%20` or other escaped
characters as references. We now ignore any references surrounded
by backticks using negative look-behind expressions.
parent d487b9e2
...@@ -10,7 +10,7 @@ module Gitlab ...@@ -10,7 +10,7 @@ module Gitlab
MAX_LINE_LENGTH = 72 MAX_LINE_LENGTH = 72
MAX_CHANGED_FILES_IN_COMMIT = 3 MAX_CHANGED_FILES_IN_COMMIT = 3
MAX_CHANGED_LINES_IN_COMMIT = 30 MAX_CHANGED_LINES_IN_COMMIT = 30
SHORT_REFERENCE_REGEX = %r{([\w\-\/]+)?(#|!|&|%)\d+\b}.freeze SHORT_REFERENCE_REGEX = %r{([\w\-\/]+)?(?<!`)(#|!|&|%)\d+(?<!`)}.freeze
DEFAULT_SUBJECT_DESCRIPTION = 'commit subject' DEFAULT_SUBJECT_DESCRIPTION = 'commit subject'
WIP_PREFIX = 'WIP: ' WIP_PREFIX = 'WIP: '
PROBLEMS = { PROBLEMS = {
......
...@@ -323,6 +323,16 @@ RSpec.describe Gitlab::Danger::CommitLinter do ...@@ -323,6 +323,16 @@ RSpec.describe Gitlab::Danger::CommitLinter do
end end
end end
context 'when message includes a value that is surrounded by backticks' do
let(:commit_message) { "A commit message `%20`" }
it 'does not add a problem' do
expect(commit_linter).not_to receive(:add_problem)
commit_linter.lint
end
end
context 'when message includes a short reference' do context 'when message includes a short reference' do
[ [
'A commit message to fix #1234', 'A commit message to fix #1234',
...@@ -336,7 +346,9 @@ RSpec.describe Gitlab::Danger::CommitLinter do ...@@ -336,7 +346,9 @@ RSpec.describe Gitlab::Danger::CommitLinter do
'A commit message to fix gitlab-org/gitlab#1234', 'A commit message to fix gitlab-org/gitlab#1234',
'A commit message to fix gitlab-org/gitlab!1234', 'A commit message to fix gitlab-org/gitlab!1234',
'A commit message to fix gitlab-org/gitlab&1234', 'A commit message to fix gitlab-org/gitlab&1234',
'A commit message to fix gitlab-org/gitlab%1234' 'A commit message to fix gitlab-org/gitlab%1234',
'A commit message to fix "gitlab-org/gitlab%1234"',
'A commit message to fix `gitlab-org/gitlab%1234'
].each do |message| ].each do |message|
let(:commit_message) { message } let(:commit_message) { message }
......
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