Class: Fastlane::Helper::SemanticReleaseHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/semantic_release2/helper/semantic_release_helper.rb

Class Method Summary collapse

Class Method Details

.git_log(params) ⇒ Object

class methods that you define here become available in your action as ‘Helper::SemanticReleaseHelper.your_method`



11
12
13
14
15
16
17
18
# File 'lib/fastlane/plugin/semantic_release2/helper/semantic_release_helper.rb', line 11

def self.git_log(params)
  end_hash = 'HEAD'
  if params[:end] and !params[:end].empty?
    end_hash = params[:end]
  end
  command = "git log --pretty='#{params[:pretty]}' --reverse #{params[:start]}..#{end_hash}"
  Actions.sh(command, log: params[:debug]).chomp
end

.parse_commit(params) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fastlane/plugin/semantic_release2/helper/semantic_release_helper.rb', line 20

def self.parse_commit(params)
  commit_subject = params[:commit_subject].strip
  commit_body = params[:commit_body]
  releases = params[:releases]
  codepush_friendly = params[:codepush_friendly]
  pattern = /^(docs|fix|feat|chore|style|refactor|perf|test)(\((.*)\))?(!?)\: (.*)/
  breaking_change_pattern = /BREAKING CHANGES?: (.*)/
  codepush_pattern = /codepush?: (.*)/

  matched = commit_subject.match(pattern)
  result = {
    is_valid: false,
    subject: commit_subject,
    is_merge: !(commit_subject =~ /^Merge/).nil?,
    type: 'no_type'
  }

  unless matched.nil?
    type = matched[1]
    scope = matched[3]

    result[:is_valid] = true
    result[:type] = type
    result[:scope] = scope
    result[:has_exclamation_mark] = matched[4] == '!'
    result[:subject] = matched[5]

    unless releases.nil?
      result[:release] = releases[type.to_sym]
    end
    unless codepush_friendly.nil?
      result[:is_codepush_friendly] = codepush_friendly.include?(type)
    end

    unless commit_body.nil?
      breaking_change_matched = commit_body.match(breaking_change_pattern)
      codepush_matched = commit_body.match(codepush_pattern)

      unless breaking_change_matched.nil?
        result[:is_breaking_change] = true
        result[:breaking_change] = breaking_change_matched[1]
      end
      unless codepush_matched.nil?
        result[:is_codepush_friendly] = codepush_matched[1] == 'ok'
      end
    end
  end

  result
end

.semver_gt(first, second) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fastlane/plugin/semantic_release2/helper/semantic_release_helper.rb', line 71

def self.semver_gt(first, second)
  first_major = (first.split('.')[0] || 0).to_i
  first_minor = (first.split('.')[1] || 0).to_i
  first_patch = (first.split('.')[2] || 0).to_i

  second_major = (second.split('.')[0] || 0).to_i
  second_minor = (second.split('.')[1] || 0).to_i
  second_patch = (second.split('.')[2] || 0).to_i

  # Check if next version is higher then last version
  if first_major > second_major
    return true
  elsif first_major == second_major
    if first_minor > second_minor
      return true
    elsif first_minor == second_minor
      if first_patch > second_patch
        return true
      end
    end
  end

  return false
end

.semver_lt(first, second) ⇒ Object



96
97
98
# File 'lib/fastlane/plugin/semantic_release2/helper/semantic_release_helper.rb', line 96

def self.semver_lt(first, second)
  return !semver_gt(first, second)
end