Class: AutoTagger::Base
- Inherits:
-
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
#options ⇒ Object
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
#cleanup ⇒ Object
57
58
59
60
61
62
|
# File 'lib/auto_tagger/base.rb', line 57
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_locally ⇒ Object
64
65
66
67
68
|
# File 'lib/auto_tagger/base.rb', line 64
def delete_locally
refs = refs_to_remove
refs.each { |ref| ref.delete_locally }
refs.length
end
|
#delete_on_remote ⇒ Object
76
77
78
79
80
|
# File 'lib/auto_tagger/base.rb', line 76
def delete_on_remote
refs = refs_to_remove
delete_remote_refs(refs)
refs.length
end
|
#last_ref_from_previous_stage ⇒ Object
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
|
#list ⇒ Object
92
93
94
95
96
|
# File 'lib/auto_tagger/base.rb', line 92
def list
ensure_stage
fetch
refs_for_stage(configuration.stage)
end
|
#refs_for_stage(stage) ⇒ Object
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/auto_tagger/base.rb', line 104
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_entries ⇒ Object
98
99
100
101
102
|
# File 'lib/auto_tagger/base.rb', line 98
def release_tag_entries
configuration.stages.map do |stage|
refs_for_stage(stage).last
end
end
|
#repo ⇒ Object
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
|