Class: GitTagger::GitTag

Inherits:
Object
  • Object
show all
Defined in:
app/models/git_tag.rb

Overview

Tag holds all relevant information used to updated git tags of

semantic versioning 2.0.0 - http://semver.org/

Constant Summary collapse

SEMANTIC_VERSION_UPDATE_TYPE_MAJOR =
"major"
SEMANTIC_VERSION_UPDATE_TYPE_MINOR =
"minor"
SEMANTIC_VERSION_UPDATE_TYPE_PATCH =
"patch"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGitTag

Sets the current semantic version and the creation date of the last tag



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/git_tag.rb', line 13

def initialize
  tag_list = `git tag | gsort -V`
  if tag_list && tag_list != ""
    @semantic_version = tag_list.split("\n").last
    # disabling cop, unable to break up system commands
    # rubocop:disable Metrics/LineLength, Style/StringLiterals
    @last_tag_date = `git log --tags --simplify-by-decoration --pretty="format:%ai" -n 1`
    @last_tag_date = Time.parse(@last_tag_date) + 1
    # rubocop:enable Metrics/LineLength, Style/StringLiterals
  else
    @semantic_version = "0.0.0"
    @last_tag_date = Date.today
  end
end

Instance Attribute Details

#last_tag_dateObject (readonly)

Returns the value of attribute last_tag_date.



10
11
12
# File 'app/models/git_tag.rb', line 10

def last_tag_date
  @last_tag_date
end

#semantic_versionObject (readonly)

Returns the value of attribute semantic_version.



9
10
11
# File 'app/models/git_tag.rb', line 9

def semantic_version
  @semantic_version
end

Instance Method Details

#create_and_pushObject



48
49
50
51
52
53
# File 'app/models/git_tag.rb', line 48

def create_and_push
  `git commit -m "Tag new release. (#{@semantic_version})\n* Updating changelog for latest tag.\n* Updating version to match latest tag."`
  `git push`
  `git tag #{ @semantic_version }`
  `git push --tags --follow-tags`
end

#update(update_type) ⇒ Object

Updates the tag semantic version based on the given update type



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/git_tag.rb', line 29

def update(update_type)
  major = @semantic_version.split(".")[0].to_i
  minor = @semantic_version.split(".")[1].to_i
  patch = @semantic_version.split(".")[2].to_i

  case update_type
  when SEMANTIC_VERSION_UPDATE_TYPE_MAJOR
    major += 1
    minor = 0
    patch = 0
  when SEMANTIC_VERSION_UPDATE_TYPE_MINOR
    minor += 1
    patch = 0
  when SEMANTIC_VERSION_UPDATE_TYPE_PATCH
    patch += 1
  end
  @semantic_version = "#{ major }.#{ minor }.#{ patch }"
end