<commit_before>require 'github-v3-api'

module Issuer
  class Notifier
    
    def self.notify(exception)
      begin
        params = {:title => exception_title(exception), :body => exception_body(exception), :labels => ["issuer"]}

        @@api ||= GitHubV3API.new(Issuer.api_token)
        # TODO detect if exists already?
        # TODO replace this by a search: http://developer.github.com/v3/search/#search-issues
        existing = @@api.issues.list(:user => Issuer.user, :repo => Issuer.repo, :labels => "issuer")
        issue = existing.select { |s| s.title == params[:title] }

        if issue
          if issue.state != 'open'
            # TODO reopen and leave a comment
          else
            # TODO leave a comment, maybe?
          end
        else
          issue = @@api.issues.create(Issuer.user, Issuer.repo, params)
          puts "New issue registered: #{issue.id} - #{issue.title}"
        end
      rescue => e
        puts "[Issuer] There was an error posting exception to GitHub: #{e.message} - the full backtrace was sent to the fallback email"
        # TODO send email
      end
    end
    
    private
    
    def self.exception_title(exception)
      exception.to_s
    end
    
    def self.exception_body(exception)
      exception.backtrace ? exception.backtrace.join("\n") : "No backtrace provided"
    end
  end
end<commit_msg>more info on the body<commit_after>require 'github-v3-api'

module Issuer
  class Notifier
    
    def self.notify(exception)
      begin
        params = {:title => exception_title(exception), :body => exception_body(exception), :labels => ["issuer"]}

        @@api ||= GitHubV3API.new(Issuer.api_token)
        # TODO replace this by a search: http://developer.github.com/v3/search/#search-issues
        existing = @@api.issues.list(:user => Issuer.user, :repo => Issuer.repo, :labels => "issuer")
        issue = existing.select { |s| s.title == params[:title] }

        if issue
          if issue.state != 'open'
            # TODO reopen and leave a comment
          else
            # TODO leave a comment, maybe?
          end
        else
          issue = @@api.issues.create(Issuer.user, Issuer.repo, params)
          puts "New issue registered: #{issue.id} - #{issue.title}"
        end
      rescue => e
        puts "[Issuer] There was an error posting exception to GitHub: #{e.message} - the full backtrace was sent to the fallback email"
        # TODO send email
      end
    end
    
    private
    
    def self.exception_title(exception)
      exception.to_s
    end
    
    def self.exception_body(exception)
      info = [
        ["Class", exception.class.to_s],
        ["Time", Time::now],
        ["Message", exception.message],
        ["Backtrace", exception.backtrace.join("\n")],
      ]
      info.collect{ |k, v| "#{k}: #{v}" }.join("\n")
    end
  end
end
{'fraction_non_alphanumeric': 0.12260536398467432, 'fraction_numerical': 0.0020898641588296763, 'mean_word_length': 2.2161254199328106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3357048', 'n_tokens_mistral': 850, 'n_tokens_neox': 835, 'n_words': 236}