From 06399b3261a4118bf5ab2d2c6fcee7aad869bc66 Mon Sep 17 00:00:00 2001
From: Douwe Maan <douwe@gitlab.com>
Date: Sat, 4 Apr 2015 14:19:05 +0200
Subject: [PATCH] Show Google Code image attachments inline.

---
 lib/gitlab/google_code_import/importer.rb           | 8 ++++++--
 spec/fixtures/GoogleCodeProjectHosting.json         | 5 +++++
 spec/lib/gitlab/google_code_import/importer_spec.rb | 3 ++-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/gitlab/google_code_import/importer.rb b/lib/gitlab/google_code_import/importer.rb
index 84ad1516571..8bdb46237fc 100644
--- a/lib/gitlab/google_code_import/importer.rb
+++ b/lib/gitlab/google_code_import/importer.rb
@@ -314,8 +314,12 @@ module Gitlab
         raw_attachments.map do |attachment|
           next if attachment["isDeleted"]
 
-          link = "https://storage.googleapis.com/google-code-attachments/#{@repo.name}/issue-#{issue_id}/comment-#{comment_id}/#{attachment["fileName"]}"
-          "[#{attachment["fileName"]}](#{link})"
+          filename = attachment["fileName"]
+          link = "https://storage.googleapis.com/google-code-attachments/#{@repo.name}/issue-#{issue_id}/comment-#{comment_id}/#{filename}"
+          
+          text = "[#{filename}](#{link})"
+          text = "!#{text}" if filename =~ /\.(png|jpg|jpeg|gif|bmp|tiff)\z/
+          text
         end.compact
       end
     end
diff --git a/spec/fixtures/GoogleCodeProjectHosting.json b/spec/fixtures/GoogleCodeProjectHosting.json
index a1d8d32adf3..85e354f8d0f 100644
--- a/spec/fixtures/GoogleCodeProjectHosting.json
+++ b/spec/fixtures/GoogleCodeProjectHosting.json
@@ -372,6 +372,11 @@
               "fileName" : "tint2_task_scrolling.diff",
               "fileSize" : 3059,
               "mimetype" : "text/x-c++; charset=us-ascii"
+            }, {
+              "attachmentId" : "000",
+              "fileName" : "screenshot.png",
+              "fileSize" : 0,
+              "mimetype" : "image/png"
             } ]
           }, {
             "id" : 1,
diff --git a/spec/lib/gitlab/google_code_import/importer_spec.rb b/spec/lib/gitlab/google_code_import/importer_spec.rb
index ee5f99c12b0..408553a98f2 100644
--- a/spec/lib/gitlab/google_code_import/importer_spec.rb
+++ b/spec/lib/gitlab/google_code_import/importer_spec.rb
@@ -49,7 +49,8 @@ describe Gitlab::GoogleCodeImport::Importer do
       expect(issue.description).to include('Patch is attached that adds two new mouse\-actions \(next\_taskprev\_task\)')
       expect(issue.description).to include('that can be used for exactly that purpose.')
       expect(issue.description).to include('all the best!')
-      expect(issue.description).to include('https://storage.googleapis.com/google-code-attachments/tint2/issue-169/comment-0/tint2_task_scrolling.diff')
+      expect(issue.description).to include('[tint2_task_scrolling.diff](https://storage.googleapis.com/google-code-attachments/tint2/issue-169/comment-0/tint2_task_scrolling.diff)')
+      expect(issue.description).to include('![screenshot.png](https://storage.googleapis.com/google-code-attachments/tint2/issue-169/comment-0/screenshot.png)')
     end
 
     it "imports issue comments" do
-- 
GitLab