diff options
28 files changed, 185 insertions, 514 deletions
@@ -238,9 +238,6 @@ gem 'redis-rails', '~> 5.0.2' # Discord integration gem 'discordrb-webhooks', '~> 3.4', require: false -# HipChat integration -gem 'hipchat', '~> 1.5.0' - # Jira integration gem 'jira-ruby', '~> 2.1.4' gem 'atlassian-jwt', '~> 0.2.0' @@ -277,7 +274,10 @@ gem 'licensee', '~> 9.14.1' gem 'charlock_holmes', '~> 0.7.7' # Detect mime content type from content -gem 'mimemagic', '~> 0.3.2' +gem 'ruby-magic-static', '~> 0.3.4' + +# Fake version of the gem to trick bundler +gem 'mimemagic', '0.3.7', path: 'vendor/shims/mimemagic', require: false # Faster blank gem 'fast_blank' diff --git a/Gemfile.lock b/Gemfile.lock index 063ebc4424b..b4190c88bc4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,8 @@ +PATH + remote: vendor/shims/mimemagic + specs: + mimemagic (0.3.7) + GEM remote: https://rubygems.org/ specs: @@ -593,9 +598,6 @@ GEM railties (>= 5.0) heapy (0.2.0) thor - hipchat (1.5.2) - httparty - mimemagic html-pipeline (2.13.2) activesupport (>= 2) nokogiri (>= 1.4) @@ -731,7 +733,6 @@ GEM mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2020.0512) - mimemagic (0.3.5) mini_histogram (0.3.1) mini_magick (4.10.1) mini_mime (1.0.2) @@ -1112,6 +1113,7 @@ GEM i18n ruby-fogbugz (0.2.1) crack (~> 0.4) + ruby-magic-static (0.3.4) ruby-prof (1.3.1) ruby-progressbar (1.11.0) ruby-saml (1.7.2) @@ -1456,7 +1458,6 @@ DEPENDENCIES hashie hashie-forbidden_attributes health_check (~> 3.0) - hipchat (~> 1.5.0) html-pipeline (~> 2.13.2) html2text httparty (~> 0.16.4) @@ -1485,7 +1486,7 @@ DEPENDENCIES marginalia (~> 1.10.0) memory_profiler (~> 0.9) method_source (~> 1.0) - mimemagic (~> 0.3.2) + mimemagic (= 0.3.7)! mini_magick (~> 4.10.1) minitest (~> 5.11.0) multi_json (~> 1.14.1) @@ -1559,6 +1560,7 @@ DEPENDENCIES rspec_junit_formatter rspec_profiling (~> 0.0.6) ruby-fogbugz (~> 0.2.1) + ruby-magic-static (~> 0.3.4) ruby-prof (~> 1.3.0) ruby-progressbar (~> 1.10) ruby_parser (~> 3.15) diff --git a/app/controllers/projects/jobs_controller.rb b/app/controllers/projects/jobs_controller.rb index 8a2ea51ba9d..f19a86209fc 100644 --- a/app/controllers/projects/jobs_controller.rb +++ b/app/controllers/projects/jobs_controller.rb @@ -226,10 +226,10 @@ class Projects::JobsController < Projects::ApplicationController end def raw_trace_content_disposition(raw_data) - mime_type = MimeMagic.by_magic(raw_data) + mime_type = Gitlab::Utils::MimeType.from_string(raw_data) # if mime_type is nil can also represent 'text/plain' - return 'inline' if mime_type.nil? || mime_type.type == 'text/plain' + return 'inline' if mime_type.nil? || mime_type == 'text/plain' 'attachment' end diff --git a/app/models/project_services/hipchat_service.rb b/app/models/project_services/hipchat_service.rb index ad531412fb7..22c2aebaec3 100644 --- a/app/models/project_services/hipchat_service.rb +++ b/app/models/project_services/hipchat_service.rb @@ -52,12 +52,8 @@ class HipchatService < Service end def execute(data) - return unless supported_events.include?(data[:object_kind]) - - message = create_message(data) - return unless message.present? - - gate[room].send('GitLab', message, message_options(data)) # rubocop:disable GitlabSecurity/PublicSend + # We removed the hipchat gem due to https://gitlab.com/gitlab-org/gitlab/-/issues/325851#note_537143149 + # HipChat is unusable anyway, so do nothing in this method end def test(data) @@ -72,71 +68,14 @@ class HipchatService < Service private - def gate - options = { api_version: api_version.presence || 'v2' } - options[:server_url] = server unless server.blank? - @gate ||= HipChat::Client.new(token, options) - end - def message_options(data = nil) { notify: notify.present? && Gitlab::Utils.to_boolean(notify), color: message_color(data) } end - def create_message(data) - object_kind = data[:object_kind] - - case object_kind - when "push", "tag_push" - create_push_message(data) - when "issue" - create_issue_message(data) unless update?(data) - when "merge_request" - create_merge_request_message(data) unless update?(data) - when "note" - create_note_message(data) - when "pipeline" - create_pipeline_message(data) if should_pipeline_be_notified?(data) - end - end - def render_line(text) markdown(text.lines.first.chomp, pipeline: :single_line) if text end - def create_push_message(push) - ref_type = Gitlab::Git.tag_ref?(push[:ref]) ? 'tag' : 'branch' - ref = Gitlab::Git.ref_name(push[:ref]) - - before = push[:before] - after = push[:after] - - message = [] - message << "#{push[:user_name]} " - - if Gitlab::Git.blank_ref?(before) - message << "pushed new #{ref_type} <a href=\""\ - "#{project_url}/commits/#{CGI.escape(ref)}\">#{ref}</a>"\ - " to #{project_link}\n" - elsif Gitlab::Git.blank_ref?(after) - message << "removed #{ref_type} <b>#{ref}</b> from <a href=\"#{project.web_url}\">#{project_name}</a> \n" - else - message << "pushed to #{ref_type} <a href=\""\ - "#{project.web_url}/commits/#{CGI.escape(ref)}\">#{ref}</a> " - message << "of <a href=\"#{project.web_url}\">#{project.full_name.gsub!(/\s/, '')}</a> " - message << "(<a href=\"#{project.web_url}/compare/#{before}...#{after}\">Compare changes</a>)" - - push[:commits].take(MAX_COMMITS).each do |commit| - message << "<br /> - #{render_line(commit[:message])} (<a href=\"#{commit[:url]}\">#{commit[:id][0..5]}</a>)" - end - - if push[:commits].count > MAX_COMMITS - message << "<br />... #{push[:commits].count - MAX_COMMITS} more commits" - end - end - - message.join - end - def markdown(text, options = {}) return "" unless text @@ -155,109 +94,10 @@ class HipchatService < Service sanitized_html.truncate(200, separator: ' ', omission: '...') end - def create_issue_message(data) - user_name = data[:user][:name] - - obj_attr = data[:object_attributes] - obj_attr = HashWithIndifferentAccess.new(obj_attr) - title = render_line(obj_attr[:title]) - state = Issue.available_states.key(obj_attr[:state_id]) - issue_iid = obj_attr[:iid] - issue_url = obj_attr[:url] - description = obj_attr[:description] - - issue_link = "<a href=\"#{issue_url}\">issue ##{issue_iid}</a>" - - message = ["#{user_name} #{state} #{issue_link} in #{project_link}: <b>#{title}</b>"] - message << "<pre>#{markdown(description)}</pre>" - - message.join - end - - def create_merge_request_message(data) - user_name = data[:user][:name] - - obj_attr = data[:object_attributes] - obj_attr = HashWithIndifferentAccess.new(obj_attr) - merge_request_id = obj_attr[:iid] - state = obj_attr[:state] - description = obj_attr[:description] - title = render_line(obj_attr[:title]) - - merge_request_url = "#{project_url}/-/merge_requests/#{merge_request_id}" - merge_request_link = "<a href=\"#{merge_request_url}\">merge request !#{merge_request_id}</a>" - message = ["#{user_name} #{state} #{merge_request_link} in " \ - "#{project_link}: <b>#{title}</b>"] - - message << "<pre>#{markdown(description)}</pre>" - message.join - end - def format_title(title) "<b>#{render_line(title)}</b>" end - def create_note_message(data) - data = HashWithIndifferentAccess.new(data) - user_name = data[:user][:name] - - obj_attr = HashWithIndifferentAccess.new(data[:object_attributes]) - note = obj_attr[:note] - note_url = obj_attr[:url] - noteable_type = obj_attr[:noteable_type] - commit_id = nil - - case noteable_type - when "Commit" - commit_attr = HashWithIndifferentAccess.new(data[:commit]) - commit_id = commit_attr[:id] - subject_desc = commit_id - subject_desc = Commit.truncate_sha(subject_desc) - subject_type = "commit" - title = format_title(commit_attr[:message]) - when "Issue" - subj_attr = HashWithIndifferentAccess.new(data[:issue]) - subject_id = subj_attr[:iid] - subject_desc = "##{subject_id}" - subject_type = "issue" - title = format_title(subj_attr[:title]) - when "MergeRequest" - subj_attr = HashWithIndifferentAccess.new(data[:merge_request]) - subject_id = subj_attr[:iid] - subject_desc = "!#{subject_id}" - subject_type = "merge request" - title = format_title(subj_attr[:title]) - when "Snippet" - subj_attr = HashWithIndifferentAccess.new(data[:snippet]) - subject_id = subj_attr[:id] - subject_desc = "##{subject_id}" - subject_type = "snippet" - title = format_title(subj_attr[:title]) - end - - subject_html = "<a href=\"#{note_url}\">#{subject_type} #{subject_desc}</a>" - message = ["#{user_name} commented on #{subject_html} in #{project_link}: "] - message << title - - message << "<pre>#{markdown(note, ref: commit_id)}</pre>" - message.join - end - - def create_pipeline_message(data) - pipeline_attributes = data[:object_attributes] - pipeline_id = pipeline_attributes[:id] - ref_type = pipeline_attributes[:tag] ? 'tag' : 'branch' - ref = pipeline_attributes[:ref] - user_name = (data[:user] && data[:user][:name]) || 'API' - status = pipeline_attributes[:status] - duration = pipeline_attributes[:duration] - - branch_link = "<a href=\"#{project_url}/-/commits/#{CGI.escape(ref)}\">#{ref}</a>" - pipeline_url = "<a href=\"#{project_url}/-/pipelines/#{pipeline_id}\">##{pipeline_id}</a>" - - "#{project_link}: Pipeline #{pipeline_url} of #{branch_link} #{ref_type} by #{user_name} #{humanized_status(status)} in #{duration} second(s)" - end - def message_color(data) pipeline_status_color(data) || color || 'yellow' end @@ -309,5 +149,3 @@ class HipchatService < Service end end end - -HipchatService.prepend_if_ee('EE::HipchatService') diff --git a/app/uploaders/content_type_whitelist.rb b/app/uploaders/content_type_whitelist.rb index 3210d57b00c..64bde16cb69 100644 --- a/app/uploaders/content_type_whitelist.rb +++ b/app/uploaders/content_type_whitelist.rb @@ -43,7 +43,7 @@ module ContentTypeWhitelist def mime_magic_content_type(path) if path File.open(path) do |file| - MimeMagic.by_magic(file).try(:type) || 'invalid/invalid' + Gitlab::Utils::MimeType.from_io(file) || 'invalid/invalid' end end rescue Errno::ENOENT diff --git a/changelogs/unreleased/mimemagic_shim.yml b/changelogs/unreleased/mimemagic_shim.yml new file mode 100644 index 00000000000..0376122f0ce --- /dev/null +++ b/changelogs/unreleased/mimemagic_shim.yml @@ -0,0 +1,5 @@ +--- +title: Switch to using a fake mimemagic gem +merge_request: 57443 +author: +type: other diff --git a/changelogs/unreleased/remove-direct-mimemagic-dependency-minimal.yml b/changelogs/unreleased/remove-direct-mimemagic-dependency-minimal.yml new file mode 100644 index 00000000000..727887f7e7b --- /dev/null +++ b/changelogs/unreleased/remove-direct-mimemagic-dependency-minimal.yml @@ -0,0 +1,5 @@ +--- +title: Refactor MimeMagic calls to new MimeType class +merge_request: 57421 +author: +type: other diff --git a/changelogs/unreleased/remove-direct-mimemagic-dependency.yml b/changelogs/unreleased/remove-direct-mimemagic-dependency.yml new file mode 100644 index 00000000000..5194dfdf751 --- /dev/null +++ b/changelogs/unreleased/remove-direct-mimemagic-dependency.yml @@ -0,0 +1,5 @@ +--- +title: Remove direct mimemagic dependency +merge_request: 57387 +author: +type: other diff --git a/changelogs/unreleased/remove_hipchat_gem.yml b/changelogs/unreleased/remove_hipchat_gem.yml new file mode 100644 index 00000000000..21a5db3bb5a --- /dev/null +++ b/changelogs/unreleased/remove_hipchat_gem.yml @@ -0,0 +1,5 @@ +--- +title: Make HipChat project service do nothing +merge_request: 57434 +author: +type: removed diff --git a/config/initializers/hipchat_client_patch.rb b/config/initializers/hipchat_client_patch.rb deleted file mode 100644 index 51bd48af320..00000000000 --- a/config/initializers/hipchat_client_patch.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true -# This monkey patches the HTTParty used in https://github.com/hipchat/hipchat-rb. -module HipChat - class Client - connection_adapter ::Gitlab::HTTPConnectionAdapter - end - - class Room - connection_adapter ::Gitlab::HTTPConnectionAdapter - end - - class User - connection_adapter ::Gitlab::HTTPConnectionAdapter - end -end diff --git a/doc/user/project/integrations/hipchat.md b/doc/user/project/integrations/hipchat.md index f66fc0a0f6a..9c0eb571f66 100644 --- a/doc/user/project/integrations/hipchat.md +++ b/doc/user/project/integrations/hipchat.md @@ -4,7 +4,12 @@ group: Ecosystem info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments --- -# Atlassian HipChat **(FREE)** +# Atlassian HipChat (Deprecated) **(FREE)** + +As of [GitLab +13.11](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/57434), the +HipChat integration will not send any notifications to HipChat. This +integration is also deprecated. GitLab provides a way to send HipChat notifications upon a number of events, such as when a user pushes code, creates a branch or tag, adds a comment, and diff --git a/lib/gitlab/utils/mime_type.rb b/lib/gitlab/utils/mime_type.rb new file mode 100644 index 00000000000..d82092a2d2c --- /dev/null +++ b/lib/gitlab/utils/mime_type.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true +require 'magic' + +# This wraps calls to a gem which support mime type detection. +# We use the `ruby-magic` gem instead of `mimemagic` due to licensing issues +module Gitlab + module Utils + class MimeType + class << self + def from_io(io) + return unless io.is_a?(IO) || io.is_a?(StringIO) + + mime_type = File.magic(io, Magic::MIME_TYPE) + mime_type == 'inode/x-empty' ? nil : mime_type + end + + def from_string(string) + return unless string.is_a?(String) + + string.type + end + end + end + end +end diff --git a/spec/fixtures/rails_sample.bmp b/spec/fixtures/rails_sample.bmp Binary files differnew file mode 100644 index 00000000000..1871273cf98 --- /dev/null +++ b/spec/fixtures/rails_sample.bmp diff --git a/spec/fixtures/rails_sample.png b/spec/fixtures/rails_sample.png Binary files differnew file mode 100644 index 00000000000..d076b02bab2 --- /dev/null +++ b/spec/fixtures/rails_sample.png diff --git a/spec/fixtures/rails_sample.tif b/spec/fixtures/rails_sample.tif Binary files differnew file mode 100644 index 00000000000..04b70192ebb --- /dev/null +++ b/spec/fixtures/rails_sample.tif diff --git a/spec/fixtures/sample.ico b/spec/fixtures/sample.ico Binary files differnew file mode 100644 index 00000000000..a1fb6e91d65 --- /dev/null +++ b/spec/fixtures/sample.ico diff --git a/spec/lib/gitlab/utils/mime_type_spec.rb b/spec/lib/gitlab/utils/mime_type_spec.rb new file mode 100644 index 00000000000..b2b6bd6c4e3 --- /dev/null +++ b/spec/lib/gitlab/utils/mime_type_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require "fast_spec_helper" +require "rspec/parameterized" + +RSpec.describe Gitlab::Utils::MimeType do + describe ".from_io" do + subject { described_class.from_io(io) } + + context "input isn't an IO" do + let(:io) { "test" } + + it "returns nil" do + expect(subject).to be_nil + end + end + + context "input is a file" do + using RSpec::Parameterized::TableSyntax + + where(:fixture, :mime_type) do + "banana_sample.gif" | "image/gif" + "rails_sample.jpg" | "image/jpeg" + "rails_sample.png" | "image/png" + "rails_sample.bmp" | "image/bmp" + "rails_sample.tif" | "image/tiff" + "sample.ico" | "image/vnd.microsoft.icon" + "blockquote_fence_before.md" | "text/plain" + "csv_empty.csv" | "application/x-empty" + end + + with_them do + let(:io) { File.open(File.join(__dir__, "../../../fixtures", fixture)) } + + it { is_expected.to eq(mime_type) } + end + end + end + + describe ".from_string" do + subject { described_class.from_string(str) } + + context "input isn't a string" do + let(:str) { nil } + + it "returns nil" do + expect(subject).to be_nil + end + end + + context "input is a string" do + let(:str) { "plain text" } + + it { is_expected.to eq('text/plain') } + end + end +end diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb index 667e6cc85ab..82a4cde752b 100644 --- a/spec/models/project_services/hipchat_service_spec.rb +++ b/spec/models/project_services/hipchat_service_spec.rb @@ -49,307 +49,8 @@ RSpec.describe HipchatService do WebMock.stub_request(:post, api_url) end - it 'tests and return errors' do - allow(hipchat).to receive(:execute).and_raise(StandardError, 'no such room') - result = hipchat.test(push_sample_data) - - expect(result[:success]).to be_falsey - expect(result[:result].to_s).to eq('no such room') - end - - it 'uses v1 if version is provided' do - allow(hipchat).to receive(:api_version).and_return('v1') - expect(HipChat::Client).to receive(:new).with( - token, - api_version: 'v1', - server_url: server_url - ).and_return(double(:hipchat_service).as_null_object) - hipchat.execute(push_sample_data) - end - - it 'uses v2 as the version when nothing is provided' do - allow(hipchat).to receive(:api_version).and_return('') - expect(HipChat::Client).to receive(:new).with( - token, - api_version: 'v2', - server_url: server_url - ).and_return(double(:hipchat_service).as_null_object) - hipchat.execute(push_sample_data) - end - - context 'push events' do - it "calls Hipchat API for push events" do - hipchat.execute(push_sample_data) - - expect(WebMock).to have_requested(:post, api_url).once - end - - it "creates a push message" do - message = hipchat.send(:create_push_message, push_sample_data) - - push_sample_data[:object_attributes] - branch = push_sample_data[:ref].gsub('refs/heads/', '') - expect(message).to include("#{user.name} pushed to branch " \ - "<a href=\"#{project.web_url}/commits/#{branch}\">#{branch}</a> of " \ - "<a href=\"#{project.web_url}\">#{project_name}</a>") - end - end - - context 'tag_push events' do - let(:push_sample_data) do - Gitlab::DataBuilder::Push.build( - project: project, - user: user, - oldrev: Gitlab::Git::BLANK_SHA, - newrev: '1' * 40, - ref: 'refs/tags/test') - end - - it "calls Hipchat API for tag push events" do - hipchat.execute(push_sample_data) - - expect(WebMock).to have_requested(:post, api_url).once - end - - it "creates a tag push message" do - message = hipchat.send(:create_push_message, push_sample_data) - - push_sample_data[:object_attributes] - expect(message).to eq("#{user.name} pushed new tag " \ - "<a href=\"#{project.web_url}/commits/test\">test</a> to " \ - "<a href=\"#{project.web_url}\">#{project_name}</a>\n") - end - end - - context 'issue events' do - let(:issue) { create(:issue, title: 'Awesome issue', description: '**please** fix') } - let(:issue_service) { Issues::CreateService.new(project, user) } - let(:issues_sample_data) { issue_service.hook_data(issue, 'open') } - - it "calls Hipchat API for issue events" do - hipchat.execute(issues_sample_data) - - expect(WebMock).to have_requested(:post, api_url).once - end - - it "creates an issue message" do - message = hipchat.send(:create_issue_message, issues_sample_data) - - obj_attr = issues_sample_data[:object_attributes] - expect(message).to eq("#{user.name} opened " \ - "<a href=\"#{obj_attr[:url]}\">issue ##{obj_attr["iid"]}</a> in " \ - "<a href=\"#{project.web_url}\">#{project_name}</a>: " \ - "<b>Awesome issue</b>" \ - "<pre><strong>please</strong> fix</pre>") - end - end - - context 'merge request events' do - let(:merge_request) { create(:merge_request, description: '**please** fix', title: 'Awesome merge request', target_project: project, source_project: project) } - let(:merge_service) { MergeRequests::CreateService.new(project, user) } - let(:merge_sample_data) { merge_service.hook_data(merge_request, 'open') } - - it "calls Hipchat API for merge requests events" do - hipchat.execute(merge_sample_data) - - expect(WebMock).to have_requested(:post, api_url).once - end - - it "creates a merge request message" do - message = hipchat.send(:create_merge_request_message, - merge_sample_data) - - obj_attr = merge_sample_data[:object_attributes] - expect(message).to eq("#{user.name} opened " \ - "<a href=\"#{obj_attr[:url]}\">merge request !#{obj_attr["iid"]}</a> in " \ - "<a href=\"#{project.web_url}\">#{project_name}</a>: " \ - "<b>Awesome merge request</b>" \ - "<pre><strong>please</strong> fix</pre>") - end - end - - context "Note events" do - let(:user) { create(:user) } - let(:project) { create(:project, :repository, creator: user) } - - context 'when commit comment event triggered' do - let(:commit_note) do - create(:note_on_commit, author: user, project: project, - commit_id: project.repository.commit.id, - note: 'a comment on a commit') - end - - it "calls Hipchat API for commit comment events" do - data = Gitlab::DataBuilder::Note.build(commit_note, user) - hipchat.execute(data) - - expect(WebMock).to have_requested(:post, api_url).once - - message = hipchat.send(:create_message, data) - - obj_attr = data[:object_attributes] - commit_id = Commit.truncate_sha(data[:commit][:id]) - title = hipchat.send(:format_title, data[:commit][:message]) - - expect(message).to eq("#{user.name} commented on " \ - "<a href=\"#{obj_attr[:url]}\">commit #{commit_id}</a> in " \ - "<a href=\"#{project.web_url}\">#{project_name}</a>: " \ - "#{title}" \ - "<pre>a comment on a commit</pre>") - end - end - - context 'when merge request comment event triggered' do - let(:merge_request) do - create(:merge_request, source_project: project, - target_project: project) - end - - let(:merge_request_note) do - create(:note_on_merge_request, noteable: merge_request, - project: project, - note: "merge request **note**") - end - - it "calls Hipchat API for merge request comment events" do - data = Gitlab::DataBuilder::Note.build(merge_request_note, user) - hipchat.execute(data) - - expect(WebMock).to have_requested(:post, api_url).once - - message = hipchat.send(:create_message, data) - - obj_attr = data[:object_attributes] - merge_id = data[:merge_request]['iid'] - title = data[:merge_request]['title'] - - expect(message).to eq("#{user.name} commented on " \ - "<a href=\"#{obj_attr[:url]}\">merge request !#{merge_id}</a> in " \ - "<a href=\"#{project.web_url}\">#{project_name}</a>: " \ - "<b>#{title}</b>" \ - "<pre>merge request <strong>note</strong></pre>") - end - end - - context 'when issue comment event triggered' do - let(:issue) { create(:issue, project: project) } - let(:issue_note) do - create(:note_on_issue, noteable: issue, project: project, - note: "issue **note**") - end - - it "calls Hipchat API for issue comment events" do - data = Gitlab::DataBuilder::Note.build(issue_note, user) - hipchat.execute(data) - - message = hipchat.send(:create_message, data) - - obj_attr = data[:object_attributes] - issue_id = data[:issue]['iid'] - title = data[:issue]['title'] - - expect(message).to eq("#{user.name} commented on " \ - "<a href=\"#{obj_attr[:url]}\">issue ##{issue_id}</a> in " \ - "<a href=\"#{project.web_url}\">#{project_name}</a>: " \ - "<b>#{title}</b>" \ - "<pre>issue <strong>note</strong></pre>") - end - - context 'with confidential issue' do - before do - issue.update!(confidential: true) - end - - it 'calls Hipchat API with issue comment' do - data = Gitlab::DataBuilder::Note.build(issue_note, user) - hipchat.execute(data) - - message = hipchat.send(:create_message, data) - - expect(message).to include("<pre>issue <strong>note</strong></pre>") - end - end - end - - context 'when snippet comment event triggered' do - let(:snippet) { create(:project_snippet, project: project) } - let(:snippet_note) do - create(:note_on_project_snippet, noteable: snippet, - project: project, - note: "snippet note") - end - - it "calls Hipchat API for snippet comment events" do - data = Gitlab::DataBuilder::Note.build(snippet_note, user) - hipchat.execute(data) - - expect(WebMock).to have_requested(:post, api_url).once - - message = hipchat.send(:create_message, data) - - obj_attr = data[:object_attributes] - snippet_id = data[:snippet]['id'] - title = data[:snippet]['title'] - - expect(message).to eq("#{user.name} commented on " \ - "<a href=\"#{obj_attr[:url]}\">snippet ##{snippet_id}</a> in " \ - "<a href=\"#{project.web_url}\">#{project_name}</a>: " \ - "<b>#{title}</b>" \ - "<pre>snippet note</pre>") - end - end - end - - context 'pipeline events' do - let(:pipeline) { create(:ci_empty_pipeline, user: project.owner) } - let(:data) { Gitlab::DataBuilder::Pipeline.build(pipeline) } - - context 'for failed' do - before do - pipeline.drop - end - - it "calls Hipchat API" do - hipchat.execute(data) - - expect(WebMock).to have_requested(:post, api_url).once - end - - it "creates a build message" do - message = hipchat.__send__(:create_pipeline_message, data) - - project_url = project.web_url - project_name = project.full_name.gsub(/\s/, '') - pipeline_attributes = data[:object_attributes] - ref = pipeline_attributes[:ref] - ref_type = pipeline_attributes[:tag] ? 'tag' : 'branch' - duration = pipeline_attributes[:duration] - user_name = data[:user][:name] - - expect(message).to eq("<a href=\"#{project_url}\">#{project_name}</a>: " \ - "Pipeline <a href=\"#{project_url}/-/pipelines/#{pipeline.id}\">##{pipeline.id}</a> " \ - "of <a href=\"#{project_url}/-/commits/#{ref}\">#{ref}</a> #{ref_type} " \ - "by #{user_name} failed in #{duration} second(s)") - end - end - - context 'for succeeded' do - before do - pipeline.succeed - end - - it "calls Hipchat API" do - hipchat.notify_only_broken_pipelines = false - hipchat.execute(data) - expect(WebMock).to have_requested(:post, api_url).once - end - - it "notifies only broken" do - hipchat.notify_only_broken_pipelines = true - hipchat.execute(data) - expect(WebMock).not_to have_requested(:post, api_url).once - end - end + it 'does nothing' do + expect { hipchat.execute(push_sample_data) }.not_to raise_error end describe "#message_options" do @@ -388,22 +89,4 @@ RSpec.describe HipchatService do end end end - - context 'with UrlBlocker' do - let(:user) { create(:user) } - let(:project) { create(:project, :repository) } - let(:hipchat) { create(:hipchat_service, project: project, properties: { room: 'test' }) } - let(:push_sample_data) { Gitlab::DataBuilder::Push.build_sample(project, user) } - - describe '#execute' do - before do - hipchat.server = 'http://localhost:9123' - end - - it 'raises UrlBlocker for localhost' do - expect(Gitlab::UrlBlocker).to receive(:validate!).and_call_original - expect { hipchat.execute(push_sample_data) }.to raise_error(Gitlab::HTTP::BlockedUrlError) - end - end - end end diff --git a/spec/support/shared_contexts/upload_type_check_shared_context.rb b/spec/support/shared_contexts/upload_type_check_shared_context.rb index f168cad961c..5fce31b4a15 100644 --- a/spec/support/shared_contexts/upload_type_check_shared_context.rb +++ b/spec/support/shared_contexts/upload_type_check_shared_context.rb @@ -13,7 +13,6 @@ end # @param mime_type [String] mime type to forcibly detect. RSpec.shared_context 'force content type detection to mime_type' do before do - magic_mime_obj = MimeMagic.new(mime_type) - allow(MimeMagic).to receive(:by_magic).with(anything).and_return(magic_mime_obj) + allow(Gitlab::Utils::MimeType).to receive(:from_io).and_return(mime_type) end end diff --git a/vendor/gitignore/C++.gitignore b/vendor/gitignore/C++.gitignore index 259148fa18f..259148fa18f 100644..100755 --- a/vendor/gitignore/C++.gitignore +++ b/vendor/gitignore/C++.gitignore diff --git a/vendor/gitignore/Java.gitignore b/vendor/gitignore/Java.gitignore index a1c2a238a96..a1c2a238a96 100644..100755 --- a/vendor/gitignore/Java.gitignore +++ b/vendor/gitignore/Java.gitignore diff --git a/vendor/shims/mimemagic/Gemfile b/vendor/shims/mimemagic/Gemfile new file mode 100644 index 00000000000..ef48903d334 --- /dev/null +++ b/vendor/shims/mimemagic/Gemfile @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +# Specify your gem's dependencies in mimemagic.gemspec +gemspec + +gem "rake", "~> 12.0" diff --git a/vendor/shims/mimemagic/LICENSE.txt b/vendor/shims/mimemagic/LICENSE.txt new file mode 100644 index 00000000000..568df6132bc --- /dev/null +++ b/vendor/shims/mimemagic/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2021 GitLab B.V. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/shims/mimemagic/README.md b/vendor/shims/mimemagic/README.md new file mode 100644 index 00000000000..57ef8dc41e1 --- /dev/null +++ b/vendor/shims/mimemagic/README.md @@ -0,0 +1 @@ +This is a fake gem to prevent mimemagic from being included into GitLab. diff --git a/vendor/shims/mimemagic/Rakefile b/vendor/shims/mimemagic/Rakefile new file mode 100644 index 00000000000..43022f711e2 --- /dev/null +++ b/vendor/shims/mimemagic/Rakefile @@ -0,0 +1,2 @@ +require "bundler/gem_tasks" +task :default => :spec diff --git a/vendor/shims/mimemagic/lib/mimemagic.rb b/vendor/shims/mimemagic/lib/mimemagic.rb new file mode 100644 index 00000000000..1deab5d90a7 --- /dev/null +++ b/vendor/shims/mimemagic/lib/mimemagic.rb @@ -0,0 +1,6 @@ +require "mimemagic/version" + +module MimeMagic + class Error < StandardError; end + raise Error, 'This gem should never be required' +end diff --git a/vendor/shims/mimemagic/lib/mimemagic/version.rb b/vendor/shims/mimemagic/lib/mimemagic/version.rb new file mode 100644 index 00000000000..eab707147e7 --- /dev/null +++ b/vendor/shims/mimemagic/lib/mimemagic/version.rb @@ -0,0 +1,3 @@ +module MimeMagic + VERSION = "0.3.7" +end diff --git a/vendor/shims/mimemagic/mimemagic.gemspec b/vendor/shims/mimemagic/mimemagic.gemspec new file mode 100644 index 00000000000..86f7f824923 --- /dev/null +++ b/vendor/shims/mimemagic/mimemagic.gemspec @@ -0,0 +1,18 @@ +require_relative 'lib/mimemagic/version' + +Gem::Specification.new do |spec| + spec.name = "mimemagic" + spec.version = MimeMagic::VERSION + spec.authors = ["Marc Shaw"] + spec.email = ["mshaw@gitlab.com"] + + spec.summary = %q{MimeMagic shim} + spec.description = %q{A shim for mimemagic} + spec.homepage = "https://gitlab.com/gitlab-org/gitlab/-/tree/master/vendor/shims/mimemagic" + spec.license = "MIT" + spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0") + + spec.files = %w[lib/mimemagic.rb lib/mimemagic/version.rb] + + spec.require_paths = ["lib"] +end |