<commit_before>class TrackedBranch < ActiveRecord::Base
  belongs_to :project
  has_many :test_runs, dependent: :destroy

  delegate :status, :total_running_time, :commit_sha, to: :last_run,
    allow_nil: true

  def last_run
    test_runs.sort_by(&:created_at).last
  end

  # TODO : Write tests
  def create_test_run_and_jobs!
    repo_id = project.repository_id
    repo = client.repo(repo_id)
    branch = client.branch(repo.id, repo[:default_branch])
    c =  branch[:commit]
    run = test_runs.create!(
      commit_sha: c.sha,
      commit_message: c.commit.message,
      commit_timestamp: c.commit.committer.date,
      commit_url: c.html_url,
      commit_author_name: c.commit.author.name,
      commit_author_email: c.commit.author.email,
      commit_author_username: c.author.login,
      commit_committer_name: c.commit.committer.name,
      commit_committer_email: c.commit.committer.email,
      commit_committer_username: c.committer.login
    )
    run.build_test_jobs

    run.save!
  end

  private

  def client
    project.user.github_client
  end
end<commit_msg>Fetch branch_name instead of default branch(master)<commit_after>class TrackedBranch < ActiveRecord::Base
  belongs_to :project
  has_many :test_runs, dependent: :destroy

  delegate :status, :total_running_time, :commit_sha, to: :last_run,
    allow_nil: true

  def last_run
    test_runs.sort_by(&:created_at).last
  end

  # TODO : Write tests
  def create_test_run_and_jobs!
    repo_id = project.repository_id
    repo = client.repo(repo_id)
    branch = client.branch(repo.id, branch_name)
    c =  branch[:commit]
    run = test_runs.create!(
      commit_sha: c.sha,
      commit_message: c.commit.message,
      commit_timestamp: c.commit.committer.date,
      commit_url: c.html_url,
      commit_author_name: c.commit.author.name,
      commit_author_email: c.commit.author.email,
      commit_author_username: c.author.login,
      commit_committer_name: c.commit.committer.name,
      commit_committer_email: c.commit.committer.email,
      commit_committer_username: c.committer.login
    )
    run.build_test_jobs

    run.save!
  end

  private

  def client
    project.user.github_client
  end
end
{'fraction_non_alphanumeric': 0.0911978221415608, 'fraction_numerical': 0.0, 'mean_word_length': 3.5184426229508197, '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': '6617727', 'n_tokens_mistral': 757, 'n_tokens_neox': 743, 'n_words': 136}