summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-12-07 14:11:15 +0200
committerValery Sizov <vsv2711@gmail.com>2015-12-07 14:14:35 +0200
commit5df2c4419c5019b5003ddfa6adb59c84c3d9910c (patch)
tree12cdcec680fb9d97431ca14d9edd138aa7627f03
parent5c1b49f494f07bf37ba3c60f3b9f70d1842d8b60 (diff)
downloadgitlab-ce-5df2c4419c5019b5003ddfa6adb59c84c3d9910c.tar.gz
fox specs
-rw-r--r--app/models/commit.rb37
-rw-r--r--app/models/merge_request.rb2
-rw-r--r--lib/gitlab/push_data_builder.rb4
-rw-r--r--spec/models/commit_spec.rb2
4 files changed, 28 insertions, 17 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 912b4dedf51..fecadfeec8e 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -135,10 +135,10 @@ class Commit
description.present?
end
- def hook_attrs
+ def hook_attrs(with_changed_files = false)
path_with_namespace = project.path_with_namespace
- {
+ data = {
id: id,
message: safe_message,
timestamp: committed_date.xmlschema,
@@ -146,11 +146,18 @@ class Commit
author: {
name: author_name,
email: author_email
- },
- added: repo_changes[:added],
- modified: repo_changes[:modified],
- removed: repo_changes[:removed]
+ }
}
+
+ if with_changed_files
+ data.merge!({
+ added: repo_changes[:added],
+ modified: repo_changes[:modified],
+ removed: repo_changes[:removed]
+ })
+ end
+
+ data
end
# Discover issues should be closed when this commit is pushed to a project's
@@ -205,14 +212,16 @@ class Commit
def repo_changes
changes = { added: [], modified: [], removed: [] }
- 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
+ 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
end
end
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 1b3d6079d2c..92a82d44c76 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -291,7 +291,7 @@ class MergeRequest < ActiveRecord::Base
work_in_progress: work_in_progress?
}
- unless last_commit.nil?
+ if last_commit
attrs.merge!(last_commit: last_commit.hook_attrs)
end
diff --git a/lib/gitlab/push_data_builder.rb b/lib/gitlab/push_data_builder.rb
index cdcdb02a052..5842b740e8e 100644
--- a/lib/gitlab/push_data_builder.rb
+++ b/lib/gitlab/push_data_builder.rb
@@ -30,7 +30,9 @@ module Gitlab
# For performance purposes maximum 20 latest commits
# will be passed as post receive hook data.
- commit_attrs = commits_limited.map(&:hook_attrs)
+ commit_attrs = commits_limited.map do |commit|
+ commit.hook_attrs(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 b417bc98fa7..6728722b503 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 }
+ let(:data) { commit.hook_attrs(true) }
it { expect(data).to be_a(Hash) }
it { expect(data[:message]).to include('Add submodule from gitlab.com') }