FIX: merge commits causing importer to crash

FIX: merge commits causing importer to crash

Blank diff was causing an issue where git importer would fail

diff --git a/lib/discourse_code_review/github_repo.rb b/lib/discourse_code_review/github_repo.rb
index 20c6543..a10512f 100644
--- a/lib/discourse_code_review/github_repo.rb
+++ b/lib/discourse_code_review/github_repo.rb
@@ -125,20 +125,22 @@ module DiscourseCodeReview
 
         diff = git("show --format=%b #{hash}")
 
-        diff_lines = diff[0..MAX_DIFF_LENGTH + body.length]
-          .strip
-          .split("\n")
+        if diff.present?
+          diff_lines = diff[0..MAX_DIFF_LENGTH + body.length]
+            .strip
+            .split("\n")
 
-        while !diff_lines[0].start_with?("diff --git")
-          diff_lines.delete_at(0)
-        end
+          while diff_lines[0] && !diff_lines[0].start_with?("diff --git")
+            diff_lines.delete_at(0)
+          end
 
-        truncated = diff.length > (MAX_DIFF_LENGTH + body.length)
-        if truncated
-          diff_lines.delete_at(diff_lines.length - 1)
-        end
+          truncated = diff.length > (MAX_DIFF_LENGTH + body.length)
+          if truncated
+            diff_lines.delete_at(diff_lines.length - 1)
+          end
 
-        diff = diff_lines.join("\n")
+          diff = diff_lines.join("\n")
+        end
 
         github_data = lookup[hash] || {}
 
diff --git a/spec/discourse_code_review/lib/github_repo_spec.rb b/spec/discourse_code_review/lib/github_repo_spec.rb
index 7549e81..c9a6a19 100644
--- a/spec/discourse_code_review/lib/github_repo_spec.rb
+++ b/spec/discourse_code_review/lib/github_repo_spec.rb
@@ -12,6 +12,37 @@ module DiscourseCodeReview
       FileUtils.rm_rf(@git_path)
     end
 
+    it "does not explode with merge commits" do
+
+      Dir.chdir(@git_path) do
+        `git init .`
+        File.write('a', "hello worlds\n")
+        `git add a`
+        `git commit -am 'first commit'`
+
+        `git branch test`
+        `git checkout test`
+        File.write('b', 'test')
+        `git add b`
+        `git commit -am testing`
+        `git checkout master`
+
+        File.write('a', "hello world\n")
+        `git commit -am 'second commit'`
+
+        `git merge test`
+
+        repo = GithubRepo.new('fake_repo/fake_repo', nil)
+
+        repo.path = @git_path
+        repo.last_commit = nil
+
+        commits = repo.commits_since("HEAD~2", merge_github_info: false, pull: false)
+
+        expect(commits.last[:diff]).to eq("")
+      end
+    end
+
     it "can cleanly truncate diffs" do
       Dir.chdir(@git_path) do
         `git init .`

GitHub
sha: dbddd513