<commit_before>require 'github_api'

namespace :tddium do
  desc "tddium environment pre-run setup task"
  task :pre_hook do
    begin
      github = Github.new(:basic_auth => basic_auth)
      response = github.oauth.create(:scopes => ["repo:status"])

      if response.status == 201
        ENV['GITHUB_TOKEN'] = response.token

        github.repos.statuses.create("zendesk", "zendesk", sha,
          :state => "pending",
          :target_url => url)
      end
    rescue Github::Error::GithubError
    end
  end

  desc "Run post-build script"
  task :post_build_hook do
    token = ENV['GITHUB_TOKEN']

    if token
      github = Github.new(:oauth_token => token)

      status = case ENV['TDDIUM_BUILD_STATUS']
      when "passed"
        "success"
      when "error"
        "error"
      else
        "failure"
      end

      begin
        github.repos.statuses.create("zendesk", "zendesk", sha,
          :state => status,
          :target_url => url)
      rescue Github::Error::GithubError
      end
    end
  end

  def url
    "https://api.tddium.com/1/reports/#{ENV['TDDIUM_SESSION_ID']}"
  end

  def sha
    `git rev-parse HEAD`.strip
  end

  def basic_auth
    ENV['GITHUB_AUTH']
  end
end<commit_msg>fixes for remote; show github errors<commit_after>require 'github_api'

namespace :tddium do
  desc "tddium environment pre-run setup task"
  task :pre_hook do
    begin
      github = Github.new(:basic_auth => basic_auth)
      response = github.oauth.create(:scopes => ["repo:status"])

      if response.status == 201
        ENV['GITHUB_TOKEN'] = response.token

        github.repos.statuses.create(*remote, sha,
          :state => "pending",
          :description => session,
          :target_url => url)
      end
    rescue Github::Error::GithubError => e
      STDERR.puts("Caught Github error when updating status: #{e.message}")
    end
  end

  desc "Run post-build script"
  task :post_build_hook do
    token = ENV['GITHUB_TOKEN']

    if token
      github = Github.new(:oauth_token => token)

      status = case ENV['TDDIUM_BUILD_STATUS']
      when "passed"
        "success"
      when "error"
        "error"
      else
        "failure"
      end

      begin
        github.repos.statuses.create(*remote, sha,
          :state => status,
          :description => session,
          :target_url => url)
      rescue Github::Error::GithubError => e
        STDERR.puts("Caught Github error when updating status: #{e.message}")
      end
    end
  end

  def url
    "https://api.tddium.com/1/reports/#{session}"
  end

  def sha
    `git rev-parse HEAD`.strip
  end

  def basic_auth
    ENV['GITHUB_AUTH']
  end

  def session
    ENV['TDDIUM_SESSION_ID']
  end

  def remote
    url = `git config --get remote.origin.url`
    url =~ /.*[:\/](.*\/[^\.]*)/ && $1.split("/")
  end
end
{'fraction_non_alphanumeric': 0.12354394634662902, 'fraction_numerical': 0.0031768443346276033, 'mean_word_length': 2.3341176470588234, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 2, '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': '1032611', 'n_tokens_mistral': 968, 'n_tokens_neox': 923, 'n_words': 220}