<commit_before>module Toolshed
  module Git
    class Github < Base
      extend Toolshed::Git
      include HTTParty

      def initialize(options={})
        super(options)

        username = Toolshed::Client::github_username
        password = Toolshed::Client::github_password

        unless (options[:username].nil?)
          username = options[:username]
        end

        unless (options[:password].nil?)
           password = options[:password]
        end

        @auth = { username: username, password: password }
        @default_options = {
          :headers => {
              "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17"
          },
          basic_auth: @auth,
        }
      end

      def create_pull_request(title, body, options={})
        options.merge!(@default_options)
        options.merge!({
          body: {
            title: title,
             body: body,
             head: "#{Toolshed::Client.github_username}:#{Toolshed::Git::Base.branch_name}",
             base: Toolshed::Git::Base.branched_from
          }.to_json
        })

        response = HTTParty.post("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.pull_from_repository_user}/#{Toolshed::Client.pull_from_repository_name}/pulls", options).response
        response = JSON.parse(response.body)
        if (response["errors"].nil?)
          response
        else
          raise "validation errors #{response.inspect}"
        end
      end

      def list_branches(options={})
        options.merge!(@default_options)

        response = HTTParty.get("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.github_username}/#{Toolshed::Client.pull_from_repository_name}/branches", options).response
        response = JSON.parse(response.body)<commit_msg>Change options to be class variable instead of instance variable<commit_after>module Toolshed
  module Git
    class Github < Base
      extend Toolshed::Git
      include HTTParty

      attr_accessor :default_options

      def initialize(options={})
        super(options)

        username = Toolshed::Client::github_username
        password = Toolshed::Client::github_password

        unless (options[:username].nil?)
          username = options[:username]
        end

        unless (options[:password].nil?)
           password = options[:password]
        end

        @auth = { username: username, password: password }
        self.default_options = {
          :headers => {
              "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17"
          },
          basic_auth: @auth,
        }
      end

      def create_pull_request(title, body, options={})
        options.merge!(self.default_options)
        options.merge!({
          body: {
            title: title,
             body: body,
             head: "#{Toolshed::Client.github_username}:#{Toolshed::Git::Base.branch_name}",
             base: Toolshed::Git::Base.branched_from
          }.to_json
        })

        response = HTTParty.post("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.pull_from_repository_user}/#{Toolshed::Client.pull_from_repository_name}/pulls", options).response
        response = JSON.parse(response.body)
        if (response["errors"].nil?)
          response
        else
          raise "validation errors #{response.inspect}"
        end
      end

      def list_branches(options={})
        options.merge!(self.default_options)

        response = HTTParty.get("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.github_username}/#{Toolshed::Client.pull_from_repository_name}/branches", options).response
        response = JSON.parse(response.body)
{'fraction_non_alphanumeric': 0.12089049961170074, 'fraction_numerical': 0.012425575977219777, 'mean_word_length': 2.5580110497237567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1176367', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1079, 'n_words': 192}