Class: Hillary::Repo::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/hillary/repo/version.rb

Constant Summary collapse

BRANCHES =
[
  DEV = ENV['DEV_BRANCH'] || 'dev',
  MASTER = ENV['MASTER_BRANCH'] || 'master'
]
InvalidRepositoryState =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, options = {}) ⇒ Version

Returns a new instance of Version.



33
34
35
36
# File 'lib/hillary/repo/version.rb', line 33

def initialize(repo, options = {})
  @repo = repo
  @options = options
end

Class Method Details

.create!(repo = Repo.new('.'), options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hillary/repo/version.rb', line 14

def create!(repo = Repo.new('.'), options = {})
  options = {production: ENV['PRODUCTION']}.merge(options)

  version = new(repo, options)

  if version.master?
    if version.production?
      repo.create_production_tag
    else
      repo.create_rc_tag
    end

    version.validate!
  end

  version
end

Instance Method Details

#branchObject



42
43
44
# File 'lib/hillary/repo/version.rb', line 42

def branch
  @branch ||= @repo.head.name
end

#dev?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/hillary/repo/version.rb', line 78

def dev?
  branch == DEV
end

#master?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/hillary/repo/version.rb', line 74

def master?
  branch == MASTER
end

#nameObject



38
39
40
# File 'lib/hillary/repo/version.rb', line 38

def name
  master? ? tag : sha
end

#production?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/hillary/repo/version.rb', line 82

def production?
  @options[:production]
end

#production_tagObject Also known as: production_tag?



62
63
64
65
66
67
# File 'lib/hillary/repo/version.rb', line 62

def production_tag
  @production_tag ||= begin
    production_tag = @repo.last_production_tag
    production_tag.name if production_tag && production_tag.commit.sha == @repo.last_rc_tag.commit.sha
  end
end

#rc_tagObject Also known as: rc_tag?



54
55
56
57
58
59
# File 'lib/hillary/repo/version.rb', line 54

def rc_tag
  @rc_tag ||= begin
    rc_tag = @repo.last_rc_tag
    rc_tag.name if rc_tag && rc_tag.commit.sha == sha
  end
end

#shaObject



50
51
52
# File 'lib/hillary/repo/version.rb', line 50

def sha
  @sha ||= @repo.head.commit.sha
end

#sluggable?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/hillary/repo/version.rb', line 70

def sluggable?
  BRANCHES.include?(branch)
end

#tagObject



46
47
48
# File 'lib/hillary/repo/version.rb', line 46

def tag
  @tag ||= production? ? production_tag : rc_tag
end

#validate!Object



86
87
88
89
90
91
# File 'lib/hillary/repo/version.rb', line 86

def validate!
  if !@options[:production] && !rc_tag?
    raise InvalidRepositoryState,
          "Last RC tag '#{@repo.last_rc_tag.name}' did not point to the current head '#{branch}' (#{sha})"
  end
end