<commit_before>require 'json'

module Ruboty
  module Handlers
    class GithubAssignor < Base
      env :GITHUB_ASSIGNOR_REPOS, "e.g. '#{[{repo: 'your/repo', to: 'chatroom', assignees: [{chat_name: 'name', github_name: 'name'}]}].to_json}'"
      env :GITHUB_TOKEN, "GitHub Access Token"
      env :GITHUB_ASSIGNOR_INTERVAL, "Check interval", optional: true

      def initialize(*args)
        super

        start_watching
      end

      private

      def start_watching
        octokit = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'])

        data = JSON.parse(ENV['GITHUB_ASSIGNOR_REPOS'])
        data.each do |datum|
          repo = datum['repo']
          to = datum['to']
          assignor = Ruboty::GithubAssignor::Assignor.new(datum['assignees'])

          watcher = Ruboty::GithubAssignor::RepoWatcher.new(
            robot: robot,
            repo: repo,
            octokit: octokit,
            assignor: assignor,
            to: to,
          )
          GithubAssignor.log(watcher.inspect)
          watcher.start((ENV['GITHUB_ASSIGNOR_INTERVAL'] || 60).to_i)
        end
      end
    end
  end
end<commit_msg>Fix a bug.<commit_after>require 'json'

module Ruboty
  module Handlers
    class GithubAssignor < Base
      env :GITHUB_ASSIGNOR_REPOS, "e.g. '#{[{repo: 'your/repo', to: 'chatroom', assignees: [{chat_name: 'name', github_name: 'name'}]}].to_json}'"
      env :GITHUB_TOKEN, "GitHub Access Token"
      env :GITHUB_ASSIGNOR_INTERVAL, "Check interval", optional: true

      def initialize(*args)
        super

        start_watching
      end

      private

      def start_watching
        octokit = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'])

        data = JSON.parse(ENV['GITHUB_ASSIGNOR_REPOS'])
        data.each do |datum|
          repo = datum['repo']
          to = datum['to']
          assignor = Ruboty::GithubAssignor::Assignor.new(datum['assignees'])

          watcher = Ruboty::GithubAssignor::RepoWatcher.new(
            robot: robot,
            repo: repo,
            octokit: octokit,
            assignor: assignor,
            to: to,
          )
          Ruboty::GithubAssignor.log(watcher.inspect)
          watcher.start((ENV['GITHUB_ASSIGNOR_INTERVAL'] || 60).to_i)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11808278867102397, 'fraction_numerical': 0.0017429193899782135, 'mean_word_length': 2.3567251461988303, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4808583', 'n_tokens_mistral': 785, 'n_tokens_neox': 768, 'n_words': 149}