{"id":2413,"date":"2011-11-18T10:08:05","date_gmt":"2011-11-18T08:08:05","guid":{"rendered":"http:\/\/touk.pl\/blog\/?p=2413"},"modified":"2023-03-22T12:19:29","modified_gmt":"2023-03-22T11:19:29","slug":"adding-diff-to-gitorious-push-notification-emails","status":"publish","type":"post","link":"https:\/\/touk.pl\/blog\/2011\/11\/18\/adding-diff-to-gitorious-push-notification-emails\/","title":{"rendered":"Adding diff to Gitorious push notification emails"},"content":{"rendered":"<p>One thing we were really missing in<\/p>\n<p><a title=\"Gitorious\" href=\"http:\/\/gitorious.org\" target=\"_blank\" rel=\"noopener\">Gitorious<\/a> is lack of diff in email notifications. We were using this feature in SVN for \u201cquick code review\u201d. Before we moved to Gitorious, we were using Gitolite where it was possible to configure it with <a title=\"(see post-receive hook)\" href=\"http:\/\/book.git-scm.com\/5_git_hooks.html\" target=\"_blank\" rel=\"noopener\">git .hooks<\/a>. However in Gitorious you do not have easy access to your repository directory ( it\u2019s hashed ). So I have started googling about the feature. I have found in Gitorious a misterious feature called <a title=\"webhooks\" href=\"http:\/\/gitorious.org\/gitorious\/pages\/WebHooks\" target=\"_blank\" rel=\"noopener\">webhooks<\/a>. But what it does is sending HTTP requests with JSON objects about commits, but without diff body. After loosing few more hours on google, forums and different groups I decided to try to implement this feature on my own. Few more hours to understand this mysterious ( for me ) Ruby on Rails code of Gitorious and I have localized few files that I should change to make it working. After all I have to say it was quite simple. The core are two lines that create commit diff in <em>lib\/event_rendering\/text.rb<\/em>: \u00a0 repo = Repository.find_by_name_in_project!(event.target.name, event.project) diff_content = repo.git.git.show({}, [start_sha, end_sha].join(\u201c..\u201d)) \u00a0 (If you would like to modify content of the commit diff you just have to modify this <em>git.git<\/em> call ). Rest of the code is just for putting diff_content value into email :). You can review the whole patch <a title=\"gitorious merge request 186\" href=\"https:\/\/gitorious.org\/gitorious\/mainline\/merge_requests\/186\" target=\"_blank\" rel=\"noopener\">here<\/a>. After applying the patch please remember to restart <em>git-poller<\/em>\u00a0and subscribe in Gitorious to email notification.<\/p>\n","protected":false},"excerpt":{"rendered":"One thing we were really missing in Gitorious is lack of diff in email notifications. We were using&hellip;\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,237],"tags":[212,537],"class_list":{"0":"post-2413","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-development-design","7":"category-processes-practices","8":"tag-git","9":"tag-shell"},"_links":{"self":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/2413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/comments?post=2413"}],"version-history":[{"count":7,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/2413\/revisions"}],"predecessor-version":[{"id":15480,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/2413\/revisions\/15480"}],"wp:attachment":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/media?parent=2413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/categories?post=2413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/tags?post=2413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}