Class: Fastlane::Helper::SemanticReleaseHelper

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

Class Method Summary collapse

Class Method Details

.git_log(pretty, start) ⇒ Object

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



11
12
13
14
# File 'lib/fastlane/plugin/semantic_release/helper/semantic_release_helper.rb', line 11

def self.git_log(pretty, start)
  command = "git log --pretty='#{pretty}' --reverse #{start}..HEAD"
  Actions.sh(command, log: false).chomp
end

.parse_commit(params) ⇒ Object



16
17
18
19
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
# File 'lib/fastlane/plugin/semantic_release/helper/semantic_release_helper.rb', line 16

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

  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 commit_body.nil?
      breaking_change_matched = commit_body.match(breaking_change_pattern)

      unless breaking_change_matched.nil?
        result[:is_breaking_change] = true
        result[:breaking_change] = breaking_change_matched[1]
      end
    end
  end

  result
end

.semver_gt(first, second) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fastlane/plugin/semantic_release/helper/semantic_release_helper.rb', line 58

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



83
84
85
# File 'lib/fastlane/plugin/semantic_release/helper/semantic_release_helper.rb', line 83

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