diff options
author | Valery Sizov <valery@gitlab.com> | 2015-12-07 14:43:13 +0000 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2015-12-07 14:43:13 +0000 |
commit | bd5fb1b479f29df3c2150b6c375c1b7bffd28931 (patch) | |
tree | 6786dc0077d83a639753723a1ae1fadb0dfba257 /app/models/commit.rb | |
parent | e88fd58671f5407d80fafe1070d48b750b9f2e50 (diff) | |
parent | 3c97cbc74cf87856ed7b1af197358d4e3adb1240 (diff) | |
download | gitlab-ce-bd5fb1b479f29df3c2150b6c375c1b7bffd28931.tar.gz |
Merge branch 'webhook_payload_with_changes' into 'master'
Add added, modified and removed properties to commit object in webhook
https://gitlab.com/gitlab-org/gitlab-ee/issues/20
See merge request !1988
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r-- | app/models/commit.rb | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index c0998a45709..8ae5325d16a 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -147,10 +147,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, @@ -160,6 +160,12 @@ class Commit email: author_email } } + + if with_changed_files + data.merge!(repo_changes) + end + + data end # Discover issues should be closed when this commit is pushed to a project's @@ -208,4 +214,22 @@ class Commit def status ci_commit.try(:status) || :not_found end + + private + + def repo_changes + changes = { added: [], modified: [], removed: [] } + + 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 + + changes + end end |