Sha256: b00b5a26055fe4e285e998977e850068e58514e824c71383eeac9dfe1568cf47

Contents?: true

Size: 1.19 KB

Versions: 31

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module CiToolkit
  # Provides utility for a build
  class Build
    def initialize(
      git = CiToolkit::Git.new,
      env = CiToolkit::BitriseEnv.new
    )
      @git = git
      @env = env
    end

    def url
      @env.build_url
    end

    def number
      @env.build_number || Time.now.to_i.to_s
    end

    def from_pull_request?
      @env.build_from_pr?
    end

    def from_develop?
      !!(@git.branch =~ /^develop$/)
    end

    def from_release?
      !!(@git.branch =~ %r{^release/.*})
    end

    def from_master?
      !!(@git.branch =~ /^master$/)
    end

    def from_cron_job?
      @env.build_from_cron_job?
    end

    def version
      version = @git.branch.split("/").last
      return version if !version.nil? && Gem::Version.correct?(version)

      return @git.latest_tag if Gem::Version.correct?(@git.latest_tag)

      raise StandardError, "Incorrect version supplied. You need to build from a valid \
release branch with semantic versioning, eg. release/x.y.z"
    end

    def tag_name(build_number = nil)
      return version.to_s if version.include?("-build.") || build_number.nil?

      "#{version}-build.#{build_number}"
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
ci_toolkit-1.6.4 lib/ci_toolkit/build.rb
ci_toolkit-1.6.3 lib/ci_toolkit/build.rb
ci_toolkit-1.6.2 lib/ci_toolkit/build.rb
ci_toolkit-1.6.1 lib/ci_toolkit/build.rb
ci_toolkit-1.6.0 lib/ci_toolkit/build.rb
ci_toolkit-1.5.24 lib/ci_toolkit/build.rb
ci_toolkit-1.5.23 lib/ci_toolkit/build.rb
ci_toolkit-1.5.22 lib/ci_toolkit/build.rb
ci_toolkit-1.5.21 lib/ci_toolkit/build.rb
ci_toolkit-1.5.20 lib/ci_toolkit/build.rb
ci_toolkit-1.5.19 lib/ci_toolkit/build.rb
ci_toolkit-1.5.17 lib/ci_toolkit/build.rb
ci_toolkit-1.5.16 lib/ci_toolkit/build.rb
ci_toolkit-1.5.15 lib/ci_toolkit/build.rb
ci_toolkit-1.5.14 lib/ci_toolkit/build.rb
ci_toolkit-1.5.13 lib/ci_toolkit/build.rb
ci_toolkit-1.5.12 lib/ci_toolkit/build.rb
ci_toolkit-1.5.11 lib/ci_toolkit/build.rb
ci_toolkit-1.5.10 lib/ci_toolkit/build.rb
ci_toolkit-1.5.9 lib/ci_toolkit/build.rb