<commit_before>require 'base64'
require 'github_api'

class Bimble::Remote

  def initialize(user, repo, oauth_token)
    @github = Github.new oauth_token: oauth_token
    @user = user
    @repo = repo
  end

  def default_branch
    repo = @github.repos.get @user, @repo
    repo.default_branch
  end

  def latest_commit(branch_name)
    branch = @github.repos.branch @user, @repo, branch_name
    branch['commit']['sha']
  end

  def blob_sha(branch, path)
    tree = @github.git_data.trees.get @user, @repo, branch
    tree['tree'].find{|x| x['path'] == path && x['type'] == 'blob'}.sha rescue nil
  end
  
  def blob_content(sha)
    blob = @github.git_data.blobs.get @user, @repo, sha
    if blob['encoding'] == 'base64'
      Base64.decode64(blob['content'])
    else
      blob['content']
    end
  end

  def gemfile
    sha = blob_sha(default_branch, "Gemfile")
    blob_content(sha)
  end

  def create_blob(content)
    @github.git_data.blobs.create @user, @repo, "content" => content, "encoding" => "utf-8"
  end

end<commit_msg>extract access to tree into separate method<commit_after>require 'base64'
require 'github_api'

class Bimble::Remote

  def initialize(user, repo, oauth_token)
    @github = Github.new oauth_token: oauth_token
    @user = user
    @repo = repo
  end

  def default_branch
    repo = @github.repos.get @user, @repo
    repo.default_branch
  end

  def latest_commit(branch_name)
    branch = @github.repos.branch @user, @repo, branch_name
    branch['commit']['sha']
  end

  def tree(branch)
    @github.git_data.trees.get @user, @repo, branch
  end

  def blob_sha(branch, path)
    tree = tree branch
    tree['tree'].find{|x| x['path'] == path && x['type'] == 'blob'}.sha rescue nil
  end
  
  def blob_content(sha)
    blob = @github.git_data.blobs.get @user, @repo, sha
    if blob['encoding'] == 'base64'
      Base64.decode64(blob['content'])
    else
      blob['content']
    end
  end

  def gemfile
    sha = blob_sha(default_branch, "Gemfile")
    blob_content(sha)
  end

  def create_blob(content)
    @github.git_data.blobs.create @user, @repo, "content" => content, "encoding" => "utf-8"
  end

end
{'fraction_non_alphanumeric': 0.13543599257884972, 'fraction_numerical': 0.008348794063079777, 'mean_word_length': 3.4474226804123713, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1736733', 'n_tokens_mistral': 780, 'n_tokens_neox': 750, 'n_words': 180}