diff options
Diffstat (limited to 'lib/gitlab/danger')
-rw-r--r-- | lib/gitlab/danger/changelog.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/danger/commit_linter.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/danger/emoji_checker.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/danger/helper.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/danger/request_helper.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/danger/teammate.rb | 31 |
6 files changed, 47 insertions, 15 deletions
diff --git a/lib/gitlab/danger/changelog.rb b/lib/gitlab/danger/changelog.rb index d64177f9565..85f386594be 100644 --- a/lib/gitlab/danger/changelog.rb +++ b/lib/gitlab/danger/changelog.rb @@ -14,10 +14,6 @@ module Gitlab @found ||= git.added_files.find { |path| path =~ %r{\A(ee/)?(changelogs/unreleased)(-ee)?/} } end - def presented_no_changelog_labels - NO_CHANGELOG_LABELS.map { |label| "~#{label}" }.join(', ') - end - def sanitized_mr_title gitlab.mr_json["title"].gsub(/^WIP: */, '').gsub(/`/, '\\\`') end diff --git a/lib/gitlab/danger/commit_linter.rb b/lib/gitlab/danger/commit_linter.rb index 616c05d0a02..58db2b58560 100644 --- a/lib/gitlab/danger/commit_linter.rb +++ b/lib/gitlab/danger/commit_linter.rb @@ -18,7 +18,7 @@ module Gitlab PROBLEMS = { subject_too_short: "The %s must contain at least #{MIN_SUBJECT_WORDS_COUNT} words", subject_too_long: "The %s may not be longer than #{MAX_LINE_LENGTH} characters", - subject_above_warning: "The %s length is acceptable, but please try to [reduce it to #{WARN_SUBJECT_LENGTH} characters](#{URL_LIMIT_SUBJECT}).", + subject_above_warning: "The %s length is acceptable, but please try to [reduce it to #{WARN_SUBJECT_LENGTH} characters](#{URL_LIMIT_SUBJECT})", subject_starts_with_lowercase: "The %s must start with a capital letter", subject_ends_with_a_period: "The %s must not end with a period", separator_missing: "The commit subject and body must be separated by a blank line", diff --git a/lib/gitlab/danger/emoji_checker.rb b/lib/gitlab/danger/emoji_checker.rb index e31a6ae5011..a2867087428 100644 --- a/lib/gitlab/danger/emoji_checker.rb +++ b/lib/gitlab/danger/emoji_checker.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'json' +require_relative '../json' module Gitlab module Danger @@ -25,8 +25,8 @@ module Gitlab )}x.freeze def initialize - names = JSON.parse(File.read(DIGESTS)).keys + - JSON.parse(File.read(ALIASES)).keys + names = Gitlab::Json.parse(File.read(DIGESTS)).keys + + Gitlab::Json.parse(File.read(ALIASES)).keys @emoji = names.map { |name| ":#{name}:" } end diff --git a/lib/gitlab/danger/helper.rb b/lib/gitlab/danger/helper.rb index aa2737262be..0f0af5f777b 100644 --- a/lib/gitlab/danger/helper.rb +++ b/lib/gitlab/danger/helper.rb @@ -191,6 +191,23 @@ module Gitlab gitlab_helper.mr_json['web_url'].include?('/gitlab-org/security/') end + def mr_has_labels?(*labels) + return false unless gitlab_helper + + labels = labels.flatten.uniq + (labels & gitlab_helper.mr_labels) == labels + end + + def labels_list(labels, sep: ', ') + labels.map { |label| %Q{~"#{label}"} }.join(sep) + end + + def prepare_labels_for_mr(labels) + return '' unless labels.any? + + "/label #{labels_list(labels, sep: ' ')}" + end + private def has_database_scoped_labels?(current_mr_labels) diff --git a/lib/gitlab/danger/request_helper.rb b/lib/gitlab/danger/request_helper.rb index 06da4ed9ad3..ef51c3f2052 100644 --- a/lib/gitlab/danger/request_helper.rb +++ b/lib/gitlab/danger/request_helper.rb @@ -16,7 +16,7 @@ module Gitlab raise HTTPError, "Failed to read #{url}: #{rsp.code} #{rsp.message}" end - JSON.parse(rsp.body) + Gitlab::Json.parse(rsp.body) end end end diff --git a/lib/gitlab/danger/teammate.rb b/lib/gitlab/danger/teammate.rb index 55476cd9789..651b002d2bf 100644 --- a/lib/gitlab/danger/teammate.rb +++ b/lib/gitlab/danger/teammate.rb @@ -1,12 +1,19 @@ # frozen_string_literal: true require 'cgi' +require 'set' module Gitlab module Danger class Teammate attr_reader :name, :username, :role, :projects + AT_CAPACITY_EMOJI = Set.new(%w[red_circle]).freeze + OOO_EMOJI = Set.new(%w[ + palm_tree + beach beach_umbrella beach_with_umbrella + ]).freeze + def initialize(options = {}) @username = options['username'] @name = options['name'] || @username @@ -37,10 +44,14 @@ module Gitlab end def status - api_endpoint = "https://gitlab.com/api/v4/users/#{CGI.escape(username)}/status" - @status ||= Gitlab::Danger::RequestHelper.http_get_json(api_endpoint) - rescue Gitlab::Danger::RequestHelper::HTTPError, JSON::ParserError - nil # better no status than a crashing Danger + return @status if defined?(@status) + + @status ||= + begin + Gitlab::Danger::RequestHelper.http_get_json(status_api_endpoint) + rescue Gitlab::Danger::RequestHelper::HTTPError, JSON::ParserError + nil # better no status than a crashing Danger + end end # @return [Boolean] @@ -50,14 +61,22 @@ module Gitlab private + def status_api_endpoint + "https://gitlab.com/api/v4/users/#{CGI.escape(username)}/status" + end + + def status_emoji + status&.dig("emoji") + end + # @return [Boolean] def out_of_office? - status&.dig("message")&.match?(/OOO/i) || false + status&.dig("message")&.match?(/OOO/i) || OOO_EMOJI.include?(status_emoji) end # @return [Boolean] def has_capacity? - status&.dig("emoji") != 'red_circle' + !AT_CAPACITY_EMOJI.include?(status_emoji) end def has_capability?(project, category, kind, labels) |