<commit_before>require 'base64'
require 'github_api'
require 'memoist'

class Bimble::GitStrategy::Github
  extend Memoist
  
  def initialize(git_url, oauth_token)
    @github = Github.new oauth_token: oauth_token
    match = git_url.match /github.com[:\/]([^\/]*)\/([^\.]*)/
    if match 
      @user = match[1]
      @repo = match[2]
    end
  end

  def get_file(name)
    sha = blob_sha(default_branch, name)
    content = blob_content(sha)
  end
  
  def commit_file(name, content)    
    blob_sha = create_blob(content)
    tree_sha = add_blob_to_tree(blob_sha, name)
    commit_sha = commit(tree_sha)
    create_branch('update-dependencies', commit_sha)
    open_pr('update-dependencies', default_branch)
  end

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

  def latest_commit(branch_name)
    branch_data = @github.repos.branch @user, @repo, branch_name
    branch_data['commit']['sha']
  end<commit_msg>use date in branch name<commit_after>require 'base64'
require 'github_api'
require 'memoist'

class Bimble::GitStrategy::Github
  extend Memoist
  
  def initialize(git_url, oauth_token)
    @github = Github.new oauth_token: oauth_token
    match = git_url.match /github.com[:\/]([^\/]*)\/([^\.]*)/
    if match 
      @user = match[1]
      @repo = match[2]
    end
  end

  def get_file(name)
    sha = blob_sha(default_branch, name)
    content = blob_content(sha)
  end
  
  def commit_file(name, content)    
    blob_sha = create_blob(content)
    tree_sha = add_blob_to_tree(blob_sha, name)
    commit_sha = commit(tree_sha)
    branch_name = "update-dependencies-#{Date.today.to_s}"
    create_branch(branch_name, commit_sha)
    open_pr(branch_name, default_branch)
  end

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

  def latest_commit(branch_name)
    branch_data = @github.repos.branch @user, @repo, branch_name
    branch_data['commit']['sha']
  end
{'fraction_non_alphanumeric': 0.11741489886531821, 'fraction_numerical': 0.003946719289590528, 'mean_word_length': 3.6513761467889907, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7299499', 'n_tokens_mistral': 731, 'n_tokens_neox': 713, 'n_words': 145}