Class: Milestoner::Tagger

Inherits:
Object
  • Object
show all
Includes:
Aids::Git
Defined in:
lib/milestoner/tagger.rb

Overview

Handles the tagging of a project repository.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Aids::Git

#git_supported?

Constructor Details

#initialize(version = nil, commit_prefixes: []) ⇒ Tagger

Returns a new instance of Tagger.



12
13
14
15
# File 'lib/milestoner/tagger.rb', line 12

def initialize version = nil, commit_prefixes: []
  @version_number = version
  @commit_prefixes = commit_prefixes
end

Instance Attribute Details

#commit_prefixesObject (readonly)

Returns the value of attribute commit_prefixes.



6
7
8
# File 'lib/milestoner/tagger.rb', line 6

def commit_prefixes
  @commit_prefixes
end

#version_numberObject (readonly)

Returns the value of attribute version_number.



6
7
8
# File 'lib/milestoner/tagger.rb', line 6

def version_number
  @version_number
end

Class Method Details

.version_regexObject



8
9
10
# File 'lib/milestoner/tagger.rb', line 8

def self.version_regex
  /\A\d{1}\.\d{1}\.\d{1}\z/
end

Instance Method Details

#commit_listObject



49
50
51
# File 'lib/milestoner/tagger.rb', line 49

def commit_list
  commits.map { |commit| "- #{commit}" }
end

#commit_prefix_regexObject



25
26
27
28
# File 'lib/milestoner/tagger.rb', line 25

def commit_prefix_regex
  return // if commit_prefixes.empty?
  Regexp.union commit_prefixes
end

#commitsObject



41
42
43
44
45
46
47
# File 'lib/milestoner/tagger.rb', line 41

def commits
  fail(Errors::Git) unless git_supported?
  groups = build_commit_prefix_groups
  group_by_commit_prefix! groups
  sort_by_commit_prefix! groups
  groups.values.flatten.uniq
end

#create(version = version_number, sign: false) ⇒ Object



53
54
55
56
57
58
# File 'lib/milestoner/tagger.rb', line 53

def create version = version_number, sign: false
  fail(Errors::Git) unless git_supported?
  @version_number = validate_version version
  fail(Errors::DuplicateTag, "Duplicate tag exists: #{version_label}.") if duplicate?
  create_tag sign: sign
end

#destroyObject



60
61
62
63
# File 'lib/milestoner/tagger.rb', line 60

def destroy
  fail(Errors::Git) unless git_supported?
  `git tag --delete #{version_label}`
end

#duplicate?Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/milestoner/tagger.rb', line 36

def duplicate?
  fail(Errors::Git) unless git_supported?
  system "git rev-parse #{version_label} > /dev/null 2>&1"
end

#tagged?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/milestoner/tagger.rb', line 30

def tagged?
  fail(Errors::Git) unless git_supported?
  response = `git tag`
  !(response.nil? || response.empty?)
end

#version_labelObject



17
18
19
# File 'lib/milestoner/tagger.rb', line 17

def version_label
  "v#{version_number}"
end

#version_messageObject



21
22
23
# File 'lib/milestoner/tagger.rb', line 21

def version_message
  "Version #{version_number}."
end