Class: Fastlane::Actions::NumberOfCommitsAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/number_of_commits.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, deprecated_notes, lane_context, method_missing, other_action, output, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authors ⇒ Object



54
55
56
# File 'fastlane/lib/fastlane/actions/number_of_commits.rb', line 54

def self.authors
  ["onevcat", "samuelbeek"]
end

.available_options ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'fastlane/lib/fastlane/actions/number_of_commits.rb', line 40

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :all,
                                 env_name: "FL_NUMBER_OF_COMMITS_ALL",
                                 optional: true,
                                 type: Boolean,
                                 description: "Returns number of all commits instead of current branch")
  ]
end

.category ⇒ Object



70
71
72
# File 'fastlane/lib/fastlane/actions/number_of_commits.rb', line 70

def self.category
  :source_control
end

.description ⇒ Object



28
29
30
# File 'fastlane/lib/fastlane/actions/number_of_commits.rb', line 28

def self.description
  "Return the number of commits in current git branch"
end

.details ⇒ Object



50
51
52
# File 'fastlane/lib/fastlane/actions/number_of_commits.rb', line 50

def self.details
  "You can use this action to get the number of commits of this branch. This is useful if you want to set the build number to the number of commits. See `fastlane actions number_of_commits` for more details."
end

.example_code ⇒ Object



62
63
64
65
66
67
68
# File 'fastlane/lib/fastlane/actions/number_of_commits.rb', line 62

def self.example_code
  [
    'increment_build_number(build_number: number_of_commits)',
    'build_number = number_of_commits(all: true)
    increment_build_number(build_number: build_number)'
  ]
end

.is_git? ⇒ Boolean

Returns:



4
5
6
7
8
9
# File 'fastlane/lib/fastlane/actions/number_of_commits.rb', line 4

def self.is_git?
  Actions.sh('git rev-parse HEAD')
  return true
rescue
  return false
end

.is_supported?(platform) ⇒ Boolean

Returns:



58
59
60
# File 'fastlane/lib/fastlane/actions/number_of_commits.rb', line 58

def self.is_supported?(platform)
  true
end

.return_type ⇒ Object



36
37
38
# File 'fastlane/lib/fastlane/actions/number_of_commits.rb', line 36

def self.return_type
  :int
end

.return_value ⇒ Object



32
33
34
# File 'fastlane/lib/fastlane/actions/number_of_commits.rb', line 32

def self.return_value
  "The total number of all commits in current git branch"
end

.run(params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'fastlane/lib/fastlane/actions/number_of_commits.rb', line 11

def self.run(params)
  if is_git?
    if params[:all]
      command = 'git rev-list --all --count'
    else
      command = 'git rev-list HEAD --count'
    end
  else
    UI.user_error!("Not in a git repository.")
  end
  return Actions.sh(command).strip.to_i
end