<commit_before>require_relative 'jira_gateway'

module Lita
  module Handlers
    class JiraIssues < Handler

      def initialize(*args)
        super(args)
        @jira = JiraGateway.new(http, config)
      end

      def self.default_config(config)
        config.enabled = true
      end

      route /[a-zA-Z]+-\d+/, :jira_message, help: {
        "KEY-123" => "Replies with information about the given JIRA key"
      }

      def jira_message(response)
        unless configured?
          raise 'Need to configure url, username, password for jira_issues ' \
            'to work'
        end
        response.matches.each do | key |
          handle_key(response, key)
        end
      end

      def configured?
        config.url && config.username && config.password
      end

      def handle_key(response, key)
        data = @jira.data_for_issue(key)
        return if data.empty?
        issue = issue_details(data)
        response.reply issue
      end

      def issue_details(data)
        key = data[:key]
        data = data[:fields]
        issue = "[#{key}] #{data[:summary]}"
        issue << "\nStatus: #{data[:status][:name]}"
        issue << assignee(data)
        issue << reporter(data)
        issue << fix_version(data)
        issue << priority(data)
        issue << issue_link(key)
      end

      def assignee(data)
        if assigned_to = data[:assignee]
          return ", assigned to #{assigned_to[:displayName]}"
        end
        ', unassigned'
      end

      def reporter(data)
        ", rep. by #{data[:reporter][:displayName]}"
      end<commit_msg>Pull status into separate method<commit_after>require_relative 'jira_gateway'

module Lita
  module Handlers
    class JiraIssues < Handler

      def initialize(*args)
        super(args)
        @jira = JiraGateway.new(http, config)
      end

      def self.default_config(config)
        config.enabled = true
      end

      route /[a-zA-Z]+-\d+/, :jira_message, help: {
        "KEY-123" => "Replies with information about the given JIRA key"
      }

      def jira_message(response)
        unless configured?
          raise 'Need to configure url, username, password for jira_issues ' \
            'to work'
        end
        response.matches.each do | key |
          handle_key(response, key)
        end
      end

      def configured?
        config.url && config.username && config.password
      end

      def handle_key(response, key)
        data = @jira.data_for_issue(key)
        return if data.empty?
        issue = issue_details(data)
        response.reply issue
      end

      def issue_details(data)
        key = data[:key]
        data = data[:fields]
        issue = summary(key, data)
        issue << status(data)
        issue << assignee(data)
        issue << reporter(data)
        issue << fix_version(data)
        issue << priority(data)
        issue << issue_link(key)
      end

      def summary(key, data)
        "[#{key}] #{data[:summary]}"
      end

      def status(data)
        "\nStatus: #{data[:status][:name]}"
      end

      def assignee(data)
        if assigned_to = data[:assignee]
          return ", assigned to #{assigned_to[:displayName]}"
        end
        ', unassigned'
      end

      def reporter(data)
        ", rep. by #{data[:reporter][:displayName]}"
      end
{'fraction_non_alphanumeric': 0.10809196775156764, 'fraction_numerical': 0.0017915795759928337, 'mean_word_length': 1.9567519858781994, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1762730', 'n_tokens_mistral': 1002, 'n_tokens_neox': 972, 'n_words': 247}