Sha256: e4d4302ec28b0f029ca7cbb5c3b2336734f2864686167a0ba1097674d7178241

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

require 'open3'

module ThorSCMVersion
  class GitVersion < ScmVersion
    class << self          
      def all_from_path(path)
        Dir.chdir(path) do
          tags = Open3.popen3("git tag") { |stdin, stdout, stderr| stdout.read }.split(/\n/)
          version_tags = tags.select { |tag| tag.match(ScmVersion::VERSION_FORMAT) }
          version_tags.collect { |tag| from_tag(tag) }.sort.reverse
        end
      end

      def retrieve_tags
        ShellUtils.sh("git fetch --all")
      end
    end
        
    def tag
      ShellUtils.sh "git tag -a -m \"Version #{self}\" #{self}"
      ShellUtils.sh "git push --tags || true"
    end

    # Check the commit messages to see what type of bump is required
    def auto_bump
      last_tag = self.class.from_path.to_s
      logs = ShellUtils.sh "git log --abbrev-commit --format=oneline #{last_tag}.."
      guess = if logs =~ /\[major\]|\#major/i
                :major
              elsif logs =~ /\[minor\]|\#minor/i
                :minor
              elsif logs =~ /\[prerelease\s?(#{Prerelease::TYPE_FORMAT})?\]|\#prerelease\-?(#{Prerelease::TYPE_FORMAT})?/
                prerelease_type = $1 || $2
                :prerelease
              elsif logs =~ /\[patch\]|\#patch/i
                :patch
              else
                :build
              end
      bump!(guess, prerelease_type)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thor-scmversion-1.1.0 lib/thor-scmversion/git_version.rb
thor-scmversion-1.0.1 lib/thor-scmversion/git_version.rb
thor-scmversion-1.0.0 lib/thor-scmversion/git_version.rb