From 9b72341ef22fc05e984fe7ed993fb5810ae5ccbe Mon Sep 17 00:00:00 2001 From: James Newton Date: Wed, 16 Jan 2013 02:20:55 +0000 Subject: [PATCH 1/6] add files added/removed/modified to commits object in post_receive_data --- app/models/project.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/models/project.rb b/app/models/project.rb index ac32352837a..12c18a5fdef 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -444,6 +444,17 @@ class Project < ActiveRecord::Base # will be passed as post receive hook data. # push_commits_limited.each do |commit| + diffs = commit.diffs + + files = {} + %w(added removed modified).each { |x| files[x.to_sym] = [] } + + diffs.each do |diff| + files[:added] << diff.new_path if diff.new_file + files[:removed] << diff.old_path if diff.deleted_file + files[:modified] << diff.new_path if !diff.new_file or !diff.deleted_file + end + data[:commits] << { id: commit.id, message: commit.safe_message, @@ -452,6 +463,11 @@ class Project < ActiveRecord::Base author: { name: commit.author_name, email: commit.author_email + }, + files: { + added: files[:added], + removed: files[:removed], + modified: files[:modified] } } end -- GitLab From a49ca79397f00082856ca8304c10626cfd1ef041 Mon Sep 17 00:00:00 2001 From: James Newton Date: Wed, 16 Jan 2013 03:52:21 +0000 Subject: [PATCH 2/6] only show added/removed/modified if they have files associated --- app/models/project.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 12c18a5fdef..494c4d35225 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -444,10 +444,7 @@ class Project < ActiveRecord::Base # will be passed as post receive hook data. # push_commits_limited.each do |commit| - diffs = commit.diffs - - files = {} - %w(added removed modified).each { |x| files[x.to_sym] = [] } + files, diffs = { added: [], removed: [], modified: [] }, commit.diffs diffs.each do |diff| files[:added] << diff.new_path if diff.new_file @@ -464,12 +461,10 @@ class Project < ActiveRecord::Base name: commit.author_name, email: commit.author_email }, - files: { - added: files[:added], - removed: files[:removed], - modified: files[:modified] - } + files: {} } + + files.each { |key, value| data[:commits].last[:files][key] = value unless value.count.zero? } end data -- GitLab From dfaf5835756c0a48dad6494f2d41420631bc7069 Mon Sep 17 00:00:00 2001 From: James Newton Date: Wed, 16 Jan 2013 04:09:42 +0000 Subject: [PATCH 3/6] modify webhooks help page to include files added/removed/modified --- app/views/hooks/_data_ex.html.erb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/views/hooks/_data_ex.html.erb b/app/views/hooks/_data_ex.html.erb index b4281fa18c7..1acd3bd1efe 100644 --- a/app/views/hooks/_data_ex.html.erb +++ b/app/views/hooks/_data_ex.html.erb @@ -9,7 +9,7 @@ "name": "Diaspora", "url": "git@localhost:diaspora.git", "description": "", - "homepage": "http://localhost/diaspora", + "homepage": "http://localhost/diaspora" }, "commits": [ { @@ -19,7 +19,11 @@ "url": "http://localhost/diaspora/commits/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", "author": { "name": "Jordi Mallach", - "email": "jordi@softcatala.org", + "email": "jordi@softcatala.org" + }, + "files": { + "added": ["app/assets/images/sadcat.jpg"], + "removed": ["lib/configuration.rb", "lib/configuration/methods.rb"] } }, // ... @@ -30,12 +34,15 @@ "url": "http://localhost/diaspora/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7", "author": { "name": "GitLab dev user", - "email": "gitlabdev@dv6700.(none)", + "email": "gitlabdev@dv6700.(none)" }, - }, + "files": { + "modified": ["README.md"] + } + } ], - "total_commits_count": 4, -}; + "total_commits_count": 4 +} eos %>
-- GitLab From b4fd85d673f67bdd3783125919abe8241e815972 Mon Sep 17 00:00:00 2001 From: James Newton Date: Fri, 18 Jan 2013 04:11:39 +0000 Subject: [PATCH 4/6] get rid of the files object in the output and show added/removed/modified inside the commit object - reflect changes in webhooks help --- app/models/project.rb | 6 +++--- app/views/hooks/_data_ex.html.erb | 10 +++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 494c4d35225..95e5ec853f8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -461,10 +461,10 @@ class Project < ActiveRecord::Base name: commit.author_name, email: commit.author_email }, - files: {} + added: files[:added], + removed: files[:removed], + modified: files[:modified] } - - files.each { |key, value| data[:commits].last[:files][key] = value unless value.count.zero? } end data diff --git a/app/views/hooks/_data_ex.html.erb b/app/views/hooks/_data_ex.html.erb index 1acd3bd1efe..60de80dc3fe 100644 --- a/app/views/hooks/_data_ex.html.erb +++ b/app/views/hooks/_data_ex.html.erb @@ -21,10 +21,8 @@ "name": "Jordi Mallach", "email": "jordi@softcatala.org" }, - "files": { - "added": ["app/assets/images/sadcat.jpg"], - "removed": ["lib/configuration.rb", "lib/configuration/methods.rb"] - } + "added": ["app/assets/images/sadcat.jpg"], + "removed": ["lib/configuration.rb", "lib/configuration/methods.rb"] }, // ... { @@ -36,9 +34,7 @@ "name": "GitLab dev user", "email": "gitlabdev@dv6700.(none)" }, - "files": { - "modified": ["README.md"] - } + "modified": ["README.md"] } ], "total_commits_count": 4 -- GitLab From e941e2b8818341de68bf8911047580f9c0f048d6 Mon Sep 17 00:00:00 2001 From: James Newton Date: Fri, 18 Jan 2013 05:13:00 +0000 Subject: [PATCH 5/6] test the new added/removed/modified arrays in the project_hook spec --- spec/models/project_hooks_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/models/project_hooks_spec.rb b/spec/models/project_hooks_spec.rb index 60457e20c51..fa2b643425b 100644 --- a/spec/models/project_hooks_spec.rb +++ b/spec/models/project_hooks_spec.rb @@ -111,6 +111,14 @@ describe Project, "Hooks" do it { should include(message: @commit.safe_message) } it { should include(timestamp: @commit.date.xmlschema) } it { should include(url: "#{Gitlab.config.gitlab.url}/#{project.code}/commit/#{@commit.id}") } + + its([:added]) { should be_an(Array) } + its([:added]) { should have(0).element } + its([:removed]) { should be_an(Array) } + its([:removed]) { should have(0).element } + its([:modified]) { should be_an(Array) } + its([:modified]) { should have(2).element } + its([:modified]) { should match_array(['app/assets/stylesheets/tree.scss', 'app/views/refs/_tree_item.html.haml']) } context "with a author" do subject { @data[:commits].first[:author] } -- GitLab From eb38465caf540d955f30794676f4cec9ad0929ef Mon Sep 17 00:00:00 2001 From: James Newton Date: Fri, 18 Jan 2013 17:38:03 +0000 Subject: [PATCH 6/6] forgot to include the empty arrays when there aren't any changes in the webhook example page --- app/views/hooks/_data_ex.html.erb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/hooks/_data_ex.html.erb b/app/views/hooks/_data_ex.html.erb index 60de80dc3fe..c3202bbe6da 100644 --- a/app/views/hooks/_data_ex.html.erb +++ b/app/views/hooks/_data_ex.html.erb @@ -22,7 +22,8 @@ "email": "jordi@softcatala.org" }, "added": ["app/assets/images/sadcat.jpg"], - "removed": ["lib/configuration.rb", "lib/configuration/methods.rb"] + "removed": ["lib/configuration.rb", "lib/configuration/methods.rb"], + "modified": [] }, // ... { @@ -34,6 +35,8 @@ "name": "GitLab dev user", "email": "gitlabdev@dv6700.(none)" }, + "added": [], + "removed": [], "modified": ["README.md"] } ], -- GitLab