<commit_before>require 'json'
require 'faraday'
require 'uri'

module Ruboty
  module Redmine
    class Client
      def initialize(url, api_key, options)
        @url = url
        @api_key = api_key
        @options = options
      end

      def projects
        res = JSON.parse(get('/projects.json').body)
        res['projects'].map do |project|
          OpenStruct.new(project)
        end
      end

      def trackers
        res = JSON.parse(get('/trackers.json').body)
        res['trackers'].map do |tracker|
          OpenStruct.new(tracker)
        end
      end

      def create_issue(opts)
        req = {
          issue: {
            subject: opts[:subject],
            project_id: opts[:project].id,
          },
        }
        req[:issue][:tracker_id] = opts[:tracker].id if opts[:tracker]

        OpenStruct.new(
          JSON.parse(post('/issues.json', req).body)['issue']
        )
      end

      def url_for_issue(issue)
        URI.join(@url, "/issues/#{issue.id}")
      end

      private

      def conn
        conn = Faraday.new(url: @url) do |faraday|
          faraday.request  :url_encoded
          faraday.response :logger if ENV['DEBUG']
          faraday.adapter  Faraday.default_adapter
        end

        basic_auth_user = @options[:basic_auth_user]
        basic_auth_password = @options[:basic_auth_password]

        if basic_auth_user && basic_auth_password
          conn.basic_auth(basic_auth_user, basic_auth_password)
        end
      end

      def get(path, params = {})
        conn.get do |req|
          req.url path
          req.params = params
          req.headers['X-Redmine-API-Key'] = @api_key
        end
      end<commit_msg>Oops.<commit_after>require 'json'
require 'faraday'
require 'uri'

module Ruboty
  module Redmine
    class Client
      def initialize(url, api_key, options)
        @url = url
        @api_key = api_key
        @options = options
      end

      def projects
        res = JSON.parse(get('/projects.json').body)
        res['projects'].map do |project|
          OpenStruct.new(project)
        end
      end

      def trackers
        res = JSON.parse(get('/trackers.json').body)
        res['trackers'].map do |tracker|
          OpenStruct.new(tracker)
        end
      end

      def create_issue(opts)
        req = {
          issue: {
            subject: opts[:subject],
            project_id: opts[:project].id,
          },
        }
        req[:issue][:tracker_id] = opts[:tracker].id if opts[:tracker]

        OpenStruct.new(
          JSON.parse(post('/issues.json', req).body)['issue']
        )
      end

      def url_for_issue(issue)
        URI.join(@url, "/issues/#{issue.id}")
      end

      private

      def conn
        conn = Faraday.new(url: @url) do |faraday|
          faraday.request  :url_encoded
          faraday.response :logger if ENV['DEBUG']
          faraday.adapter  Faraday.default_adapter
        end

        basic_auth_user = @options[:basic_auth_user]
        basic_auth_password = @options[:basic_auth_password]

        if basic_auth_user && basic_auth_password
          conn.basic_auth(basic_auth_user, basic_auth_password)
        end

        conn
      end

      def get(path, params = {})
        conn.get do |req|
          req.url path
          req.params = params
          req.headers['X-Redmine-API-Key'] = @api_key
        end
      end
{'fraction_non_alphanumeric': 0.10833822665883734, 'fraction_numerical': 0.0, 'mean_word_length': 1.820364238410596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4795733', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1016, 'n_words': 212}