<commit_before>module Janky
  class Branch < ActiveRecord::Base
    belongs_to :repository
    has_many :builds, :dependent => :destroy

    # Is this branch green?
    #
    # Returns a Boolean.
    def green?
      if current_build
        current_build.green?
      end
    end

    # Is this branch red?
    #
    # Returns a Boolean.
    def red?
      if current_build
        current_build.red?
      end
    end

    # Is this branch building?
    #
    # Returns a Boolean.
    def building?
      if current_build
        current_build.building?
      end
    end

    # Is this branch completed?
    #
    # Returns a Boolean.
    def completed?
      if current_build
        current_build.completed?
      end
    end

    # Find all completed builds, sorted by completion date, most recent first.
    #
    # Returns an Array of Builds.
    def completed_builds
      builds.completed
    end

    # See Build.queued.
    def queued_builds
      builds.queued
    end

    # Create a build for the given commit.
    #
    # commit  - the Janky::Commit instance to build.
    # user    - The login of the GitHub user who pushed.
    # compare - optional String GitHub Compare View URL. Defaults to the
    #           commit last build, if any.
    # room_id - optional Fixnum Campfire room ID. Defaults to the room set on
    #           the repository.
    #
    # Returns the newly created Janky::Build.
    def build_for(commit, user, room_id = nil, compare = nil)
      if compare.nil? && build = commit.last_build
        compare = build.compare
      end

      if room_id.nil? || room_id.zero?
        room_id = repository.room_id
      end

      builds.create!(
        :compare => compare,
        :user    => user,
        :commit  => commit,
        :room_id => room_id
      )
    end

    # Fetch the HEAD commit of this branch using the GitHub API and create a
    # build and commit record.
    #
    # room_id - See build_for documentation. This is passed as is to the
    #           build_for method.
    # user    - Ditto.
    #
    # Returns the newly created Janky::Build.
    def head_build_for(room_id, user)
      sha_to_build = GitHub.branch_head_sha(repository.nwo, name)
      return if !sha_to_build

      commit = repository.commit_for_sha(sha_to_build)<commit_msg>Since the room id is now a string, it cannot be zero<commit_after>module Janky
  class Branch < ActiveRecord::Base
    belongs_to :repository
    has_many :builds, :dependent => :destroy

    # Is this branch green?
    #
    # Returns a Boolean.
    def green?
      if current_build
        current_build.green?
      end
    end

    # Is this branch red?
    #
    # Returns a Boolean.
    def red?
      if current_build
        current_build.red?
      end
    end

    # Is this branch building?
    #
    # Returns a Boolean.
    def building?
      if current_build
        current_build.building?
      end
    end

    # Is this branch completed?
    #
    # Returns a Boolean.
    def completed?
      if current_build
        current_build.completed?
      end
    end

    # Find all completed builds, sorted by completion date, most recent first.
    #
    # Returns an Array of Builds.
    def completed_builds
      builds.completed
    end

    # See Build.queued.
    def queued_builds
      builds.queued
    end

    # Create a build for the given commit.
    #
    # commit  - the Janky::Commit instance to build.
    # user    - The login of the GitHub user who pushed.
    # compare - optional String GitHub Compare View URL. Defaults to the
    #           commit last build, if any.
    # room_id - optional Fixnum Campfire room ID. Defaults to the room set on
    #           the repository.
    #
    # Returns the newly created Janky::Build.
    def build_for(commit, user, room_id = nil, compare = nil)
      if compare.nil? && build = commit.last_build
        compare = build.compare
      end

      if room_id.nil? || room_id.empty?
        room_id = repository.room_id
      end

      builds.create!(
        :compare => compare,
        :user    => user,
        :commit  => commit,
        :room_id => room_id
      )
    end

    # Fetch the HEAD commit of this branch using the GitHub API and create a
    # build and commit record.
    #
    # room_id - See build_for documentation. This is passed as is to the
    #           build_for method.
    # user    - Ditto.
    #
    # Returns the newly created Janky::Build.
    def head_build_for(room_id, user)
      sha_to_build = GitHub.branch_head_sha(repository.nwo, name)
      return if !sha_to_build

      commit = repository.commit_for_sha(sha_to_build)
{'fraction_non_alphanumeric': 0.06759656652360516, 'fraction_numerical': 0.0, 'mean_word_length': 1.972576530612245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '4850361', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1365, 'n_words': 467}