From 31e76baf610e1307090a6bac3a7b3d525bce057a Mon Sep 17 00:00:00 2001 From: David Padilla Date: Mon, 29 Feb 2016 23:29:20 -0600 Subject: Fix #2364. Fall back to In-Reply-To header when reply key not available --- lib/gitlab/email/receiver.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/gitlab/email/receiver.rb b/lib/gitlab/email/receiver.rb index d4b6f6d120d..d55bacde5b0 100644 --- a/lib/gitlab/email/receiver.rb +++ b/lib/gitlab/email/receiver.rb @@ -63,6 +63,10 @@ module Gitlab end def reply_key + key_from_to_address || key_from_in_reply_to_header + end + + def key_from_to_address key = nil message.to.each do |address| key = Gitlab::IncomingEmail.key_from_address(address) @@ -72,6 +76,17 @@ module Gitlab key end + def key_from_in_reply_to_header + reply_key = nil + + message[:in_reply_to].message_ids.each do |message_id| + reply_key = Gitlab::IncomingEmail.key_from_address(message_id) + break if reply_key + end + + reply_key + end + def sent_notification return nil unless reply_key -- cgit v1.2.1 From 9f218fc184894d61c10f738c59bce97780f06e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 17 Mar 2016 20:03:51 +0100 Subject: Improve and finish the fallback to the In-Reply-To and References header for the reply-by-email feature A few things to note: - The IncomingEmail feature is now enabled even without a correctly-formatted sub-address - Message-ID for new thread mail are kept the same so that subsequent notifications to this thread are grouped in the thread by the email service that receives the notification (i.e. In-Reply-To of the answer == Message-ID of the first thread message) - To maximize our chance to be able to retrieve the reply key, we look for it in the In-Reply-To header and the References header - The pattern for the fallback reply message id is "reply-[key]@[gitlab_host]" - Improve docs thanks to Axil --- lib/gitlab/email/receiver.rb | 10 +++++----- lib/gitlab/incoming_email.rb | 16 ++++++++++------ lib/tasks/gitlab/check.rake | 15 --------------- 3 files changed, 15 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/email/receiver.rb b/lib/gitlab/email/receiver.rb index d55bacde5b0..97ef9851d71 100644 --- a/lib/gitlab/email/receiver.rb +++ b/lib/gitlab/email/receiver.rb @@ -63,10 +63,10 @@ module Gitlab end def reply_key - key_from_to_address || key_from_in_reply_to_header + key_from_to_header || key_from_additional_headers end - def key_from_to_address + def key_from_to_header key = nil message.to.each do |address| key = Gitlab::IncomingEmail.key_from_address(address) @@ -76,11 +76,11 @@ module Gitlab key end - def key_from_in_reply_to_header + def key_from_additional_headers reply_key = nil - message[:in_reply_to].message_ids.each do |message_id| - reply_key = Gitlab::IncomingEmail.key_from_address(message_id) + Array(message.references).each do |message_id| + reply_key = Gitlab::IncomingEmail.key_from_fallback_reply_message_id(message_id) break if reply_key end diff --git a/lib/gitlab/incoming_email.rb b/lib/gitlab/incoming_email.rb index 9068d79c95e..8ce9d32abe0 100644 --- a/lib/gitlab/incoming_email.rb +++ b/lib/gitlab/incoming_email.rb @@ -1,13 +1,10 @@ module Gitlab module IncomingEmail class << self - def enabled? - config.enabled && address_formatted_correctly? - end + FALLBACK_REPLY_MESSAGE_ID_REGEX = /\Areply\-(.+)@#{Gitlab.config.gitlab.host}\Z/.freeze - def address_formatted_correctly? - config.address && - config.address.include?("%{key}") + def enabled? + config.enabled && config.address end def reply_address(key) @@ -24,6 +21,13 @@ module Gitlab match[1] end + def key_from_fallback_reply_message_id(message_id) + match = message_id.match(FALLBACK_REPLY_MESSAGE_ID_REGEX) + return unless match + + match[1] + end + def config Gitlab.config.incoming_email end diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 27ed57efe55..effb8eb6001 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -623,7 +623,6 @@ namespace :gitlab do start_checking "Reply by email" if Gitlab.config.incoming_email.enabled - check_address_formatted_correctly check_imap_authentication if Rails.env.production? @@ -643,20 +642,6 @@ namespace :gitlab do # Checks ######################## - def check_address_formatted_correctly - print "Address formatted correctly? ... " - - if Gitlab::IncomingEmail.address_formatted_correctly? - puts "yes".green - else - puts "no".red - try_fixing_it( - "Make sure that the address in config/gitlab.yml includes the '%{key}' placeholder." - ) - fix_and_rerun - end - end - def check_initd_configured_correctly print "Init.d configured correctly? ... " -- cgit v1.2.1 From 4cd1b9f4d82efe3ffe810dabf6929a749c36c1bf Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 23 Mar 2016 11:24:18 +0100 Subject: Refactor builds badge, encapsulate inside a class --- lib/gitlab/badge/build.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/gitlab/badge/build.rb (limited to 'lib') diff --git a/lib/gitlab/badge/build.rb b/lib/gitlab/badge/build.rb new file mode 100644 index 00000000000..28a2391dbf8 --- /dev/null +++ b/lib/gitlab/badge/build.rb @@ -0,0 +1,24 @@ +module Gitlab + module Badge + ## + # Build badge + # + class Build + def initialize(project, ref) + @image = ::Ci::ImageForBuildService.new.execute(project, ref: ref) + end + + def to_s + @image[:name].sub(/\.svg$/, '') + end + + def type + 'image/svg+xml' + end + + def data + File.read(@image[:path]) + end + end + end +end -- cgit v1.2.1 From 5830d80b8d2b87daa9123dc248ae00e2ed90069c Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 30 Mar 2016 19:29:17 +0200 Subject: Pre-calculate Emoji digests By pre-calculating the digests we can manually construct the emoji URLs, removing the need for using Rails' asset URL helpers. The reason we don't want to use these helpers for Emojis is two-fold: 1. Rails' image_url() method is slow, really slow. For one it _might_ have to calculate digests but it also performs a lot of other intensive operations (judging by the source code and based on measuring timings). 2. We have a lot of Emoji which coupled with the above can result in it taking minutes to load Emoji autocomplete data. Using this pre-calculation setup generating the digests takes around 7 seconds (including the time it takes to start Rails/Rake), and only around 600 milliseconds to load _all_ the autocomplete data of a project (measured locally). This commit _does_ change the Emoji URLs from absolute to relative URLs as these are much easier to generate. To update the Emoji data simply run: rake gemojione:digests Then commit any changes. Fixes gitlab-org/gitlab-ce#14009 --- lib/award_emoji.rb | 19 +++++++++++++++++++ lib/tasks/gemojione.rake | 48 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/award_emoji.rb b/lib/award_emoji.rb index 783fcfb61ad..4fc3443ac68 100644 --- a/lib/award_emoji.rb +++ b/lib/award_emoji.rb @@ -48,4 +48,23 @@ class AwardEmoji JSON.parse(File.read(json_path)) end end + + # Returns an Array of Emoji names and their asset URLs. + def self.urls + @urls ||= begin + path = File.join(Rails.root, 'fixtures', 'emojis', 'digests.json') + prefix = Gitlab::Application.config.assets.prefix + digest = Gitlab::Application.config.assets.digest + + JSON.parse(File.read(path)).map do |hash| + if digest + fname = "#{hash['unicode']}-#{hash['digest']}" + else + fname = hash['unicode'] + end + + { name: hash['name'], path: "#{prefix}/#{fname}.png" } + end + end + end end diff --git a/lib/tasks/gemojione.rake b/lib/tasks/gemojione.rake index cfaf4a129b1..7ec00a898fd 100644 --- a/lib/tasks/gemojione.rake +++ b/lib/tasks/gemojione.rake @@ -1,19 +1,39 @@ -# This task will generate a standard and Retina sprite of all of the current -# Gemojione Emojis, with the accompanying SCSS map. -# -# It will not appear in `rake -T` output, and the dependent gems are not -# included in the Gemfile by default, because this task will only be needed -# occasionally, such as when new Emojis are added to Gemojione. - -begin - require 'sprite_factory' - require 'rmagick' -rescue LoadError - # noop -end - namespace :gemojione do + desc 'Generates Emoji SHA256 digests' + task digests: :environment do + require 'digest/sha2' + require 'json' + + dir = Gemojione.index.images_path + + digests = AwardEmoji.emojis.map do |name, emoji_hash| + fpath = File.join(dir, "#{emoji_hash['unicode']}.png") + digest = Digest::SHA256.file(fpath).hexdigest + + { name: name, unicode: emoji_hash['unicode'], digest: digest } + end + + out = File.join(Rails.root, 'fixtures', 'emojis', 'digests.json') + + File.open(out, 'w') do |handle| + handle.write(JSON.pretty_generate(digests)) + end + end + + # This task will generate a standard and Retina sprite of all of the current + # Gemojione Emojis, with the accompanying SCSS map. + # + # It will not appear in `rake -T` output, and the dependent gems are not + # included in the Gemfile by default, because this task will only be needed + # occasionally, such as when new Emojis are added to Gemojione. task sprite: :environment do + begin + require 'sprite_factory' + require 'rmagick' + rescue LoadError + # noop + end + check_requirements! SIZE = 20 -- cgit v1.2.1