summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-12-07 15:13:06 +0200
committerValery Sizov <vsv2711@gmail.com>2015-12-07 15:13:06 +0200
commit3c97cbc74cf87856ed7b1af197358d4e3adb1240 (patch)
treea19af710652e68c403e3dfa9dc314ba6a92da41a
parent5df2c4419c5019b5003ddfa6adb59c84c3d9910c (diff)
downloadgitlab-ce-webhook_payload_with_changes.tar.gz
-rw-r--r--app/models/commit.rb25
-rw-r--r--lib/gitlab/push_data_builder.rb2
-rw-r--r--spec/models/commit_spec.rb2
3 files changed, 11 insertions, 18 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index fecadfeec8e..14883c96f5f 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -135,7 +135,7 @@ class Commit
description.present?
end
- def hook_attrs(with_changed_files = false)
+ def hook_attrs(with_changed_files: false)
path_with_namespace = project.path_with_namespace
data = {
@@ -150,11 +150,7 @@ class Commit
}
if with_changed_files
- data.merge!({
- added: repo_changes[:added],
- modified: repo_changes[:modified],
- removed: repo_changes[:removed]
- })
+ data.merge!(repo_changes)
end
data
@@ -212,16 +208,13 @@ class Commit
def repo_changes
changes = { added: [], modified: [], removed: [] }
- if diffs.any?
- diffs.each do |diff|
- case true
- when diff.deleted_file
- changes[:removed] << diff.old_path
- when diff.renamed_file, diff.new_file
- changes[:added] << diff.new_path
- else
- changes[:modified] << diff.new_path
- end
+ diffs.each do |diff|
+ if diff.deleted_file
+ changes[:removed] << diff.old_path
+ elsif diff.renamed_file || diff.new_file
+ changes[:added] << diff.new_path
+ else
+ changes[:modified] << diff.new_path
end
end
diff --git a/lib/gitlab/push_data_builder.rb b/lib/gitlab/push_data_builder.rb
index 5842b740e8e..4f9cdef3869 100644
--- a/lib/gitlab/push_data_builder.rb
+++ b/lib/gitlab/push_data_builder.rb
@@ -31,7 +31,7 @@ module Gitlab
# For performance purposes maximum 20 latest commits
# will be passed as post receive hook data.
commit_attrs = commits_limited.map do |commit|
- commit.hook_attrs(true)
+ commit.hook_attrs(with_changed_files: true)
end
type = Gitlab::Git.tag_ref?(ref) ? "tag_push" : "push"
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index 6728722b503..0b1e2bf74d0 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -102,7 +102,7 @@ eos
end
describe '#hook_attrs' do
- let(:data) { commit.hook_attrs(true) }
+ let(:data) { commit.hook_attrs(with_changed_files: true) }
it { expect(data).to be_a(Hash) }
it { expect(data[:message]).to include('Add submodule from gitlab.com') }