Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5573ea05
Commit
5573ea05
authored
Sep 08, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Danger::Helper check for renamed files
Prevent raising an error when changed file has no diff
parent
b6e5b641
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
lib/gitlab/danger/helper.rb
lib/gitlab/danger/helper.rb
+4
-1
spec/lib/gitlab/danger/helper_spec.rb
spec/lib/gitlab/danger/helper_spec.rb
+24
-0
No files found.
lib/gitlab/danger/helper.rb
View file @
5573ea05
...
...
@@ -44,7 +44,10 @@ module Gitlab
# "+ # Test change",
# "- # Old change" ]
def
changed_lines
(
changed_file
)
git
.
diff_for_file
(
changed_file
).
patch
.
split
(
"
\n
"
).
select
{
|
line
|
%r{^[+-]}
.
match?
(
line
)
}
diff
=
git
.
diff_for_file
(
changed_file
)
return
[]
unless
diff
diff
.
patch
.
split
(
"
\n
"
).
select
{
|
line
|
%r{^[+-]}
.
match?
(
line
)
}
end
def
all_ee_changes
...
...
spec/lib/gitlab/danger/helper_spec.rb
View file @
5573ea05
...
...
@@ -76,6 +76,30 @@ RSpec.describe Gitlab::Danger::Helper do
end
end
describe
'#changed_lines'
do
subject
{
helper
.
changed_lines
(
'changed_file.rb'
)
}
before
do
allow
(
fake_git
).
to
receive
(
:diff_for_file
).
with
(
'changed_file.rb'
).
and_return
(
diff
)
end
context
'when file has diff'
do
let
(
:diff
)
{
double
(
:diff
,
patch:
"+ # New change here
\n
+ # New change there"
)
}
it
'returns file changes'
do
is_expected
.
to
eq
([
'+ # New change here'
,
'+ # New change there'
])
end
end
context
'when file has no diff (renamed without changes)'
do
let
(
:diff
)
{
nil
}
it
'returns a blank array'
do
is_expected
.
to
eq
([])
end
end
end
describe
"changed_files"
do
it
'returns list of changed files matching given regex'
do
expect
(
helper
).
to
receive
(
:all_changed_files
).
and_return
(
%w[migration.rb usage_data.rb]
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment