username_extractor.rb 763 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# frozen_string_literal: true

module ReleaseTools
  module Qa
    class UsernameExtractor
      COMMUNITY_CONTRIBUTION_LABEL = "Community contribution"

      attr_reader :merge_request

      def initialize(merge_request)
        @merge_request = merge_request
      end

      def extract_username
        username_format(mention_for_mr)
      end

      private

      def mention_for_mr
        if merge_request.labels.include?(COMMUNITY_CONTRIBUTION_LABEL)
22 23 24
          merge_request.merged_by&.username ||
            merge_request.assignee&.username ||
            merge_request.author.username
25 26 27 28 29 30 31 32 33 34 35
        else
          merge_request.author.username
        end
      end

      def username_format(username)
        "@#{username}"
      end
    end
  end
end