From b2ce3643e27db4cc0ad30cc09d651c00ec799887 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 26 Mar 2021 17:34:57 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-10-stable-ee --- app/controllers/projects/jobs_controller.rb | 4 +- app/models/project_services/hipchat_service.rb | 166 +------------------------ app/uploaders/content_type_whitelist.rb | 2 +- 3 files changed, 5 insertions(+), 167 deletions(-) (limited to 'app') 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} #{ref}"\ - " to #{project_link}\n" - elsif Gitlab::Git.blank_ref?(after) - message << "removed #{ref_type} #{ref} from #{project_name} \n" - else - message << "pushed to #{ref_type} #{ref} " - message << "of #{project.full_name.gsub!(/\s/, '')} " - message << "(Compare changes)" - - push[:commits].take(MAX_COMMITS).each do |commit| - message << "
- #{render_line(commit[:message])} (#{commit[:id][0..5]})" - end - - if push[:commits].count > MAX_COMMITS - message << "
... #{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 = "issue ##{issue_iid}" - - message = ["#{user_name} #{state} #{issue_link} in #{project_link}: #{title}"] - message << "
#{markdown(description)}
" - - 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 = "merge request !#{merge_request_id}" - message = ["#{user_name} #{state} #{merge_request_link} in " \ - "#{project_link}: #{title}"] - - message << "
#{markdown(description)}
" - message.join - end - def format_title(title) "#{render_line(title)}" 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 = "#{subject_type} #{subject_desc}" - message = ["#{user_name} commented on #{subject_html} in #{project_link}: "] - message << title - - message << "
#{markdown(note, ref: commit_id)}
" - 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 = "#{ref}" - pipeline_url = "##{pipeline_id}" - - "#{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 -- cgit v1.2.3