Class: AutoTagger::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/auto_tagger/base.rb

Defined Under Namespace

Classes: StageCannotBeBlankError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



15
16
17
# File 'lib/auto_tagger/base.rb', line 15

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/auto_tagger/base.rb', line 13

def options
  @options
end

Class Method Details

.items_to_remove(array, keep) ⇒ Object



7
8
9
10
11
# File 'lib/auto_tagger/base.rb', line 7

def self.items_to_remove(array, keep)
  max = array.length - keep
  max = 0 if max <= 0
  array[0...max]
end

Instance Method Details

#cleanupObject



55
56
57
58
59
60
# File 'lib/auto_tagger/base.rb', line 55

def cleanup
  refs = refs_to_remove
  delete_local_refs(refs)
  delete_remote_refs(refs) if configuration.push_refs?
  refs.length
end

#create_ref(commit = nil) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/auto_tagger/base.rb', line 31

def create_ref(commit = nil)
  ensure_stage
  fetch
  new_tag = repo.refs.create(commit || repo.latest_commit_sha, ref_name)
  push
  new_tag
end

#delete_locallyObject



62
63
64
65
66
# File 'lib/auto_tagger/base.rb', line 62

def delete_locally
  refs = refs_to_remove
  refs.each { |ref| ref.delete_locally }
  refs.length
end

#delete_on_remoteObject



74
75
76
77
78
# File 'lib/auto_tagger/base.rb', line 74

def delete_on_remote
  refs = refs_to_remove
  delete_remote_refs(refs)
  refs.length
end

#fetchObject



39
40
41
# File 'lib/auto_tagger/base.rb', line 39

def fetch
  repo.refs.fetch(pattern, configuration.remote) if configuration.fetch_refs?
end

#last_ref_from_previous_stageObject



26
27
28
29
# File 'lib/auto_tagger/base.rb', line 26

def last_ref_from_previous_stage
  return unless previous_stage
  refs_for_stage(previous_stage).last
end

#listObject



90
91
92
93
94
# File 'lib/auto_tagger/base.rb', line 90

def list
  ensure_stage
  fetch
  refs_for_stage(configuration.stage)
end

#refs_for_stage(stage) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/auto_tagger/base.rb', line 102

def refs_for_stage(stage)
  raise StageCannotBeBlankError if stage.to_s.strip == ""
  ref_path = Regexp.escape(configuration.ref_path)
  matcher = /refs\/#{ref_path}\/#{Regexp.escape(stage)}\/(.*)/
  select_refs_for_stage(stage).sort do |ref1, ref2|
    name1 = ref1.name.match(matcher)[1].gsub(configuration.date_separator, "")
    name2 = ref2.name.match(matcher)[1].gsub(configuration.date_separator, "")
    name1.to_i <=> name2.to_i
  end
end

#release_tag_entriesObject



96
97
98
99
100
# File 'lib/auto_tagger/base.rb', line 96

def release_tag_entries
  configuration.stages.map do |stage|
    refs_for_stage(stage).last
  end
end

#repoObject



19
20
21
22
23
24
# File 'lib/auto_tagger/base.rb', line 19

def repo
  @repo ||= AutoTagger::Git::Repo.new configuration.working_directory,
                                      :execute_commands => !configuration.dry_run?,
                                      :verbose => configuration.verbose?,
                                      :executable => configuration.executable
end