Class: Pantograph::Actions::EnsureGitBranchAction

Inherits:
Pantograph::Action show all
Defined in:
pantograph/lib/pantograph/actions/ensure_git_branch.rb

Overview

Raises an exception and stop the lane execution if the repo is not on a specific branch

Constant Summary

Constants inherited from Pantograph::Action

Pantograph::Action::AVAILABLE_CATEGORIES, Pantograph::Action::RETURN_TYPES

Documentation collapse

Class Method Summary collapse

Methods inherited from Pantograph::Action

action_name, authors, deprecated_notes, lane_context, method_missing, other_action, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



47
48
49
# File 'pantograph/lib/pantograph/actions/ensure_git_branch.rb', line 47

def self.author
  ['dbachrach', 'Liquidsoul', 'johnknapprs']
end

.available_optionsObject



31
32
33
34
35
36
37
38
39
40
41
# File 'pantograph/lib/pantograph/actions/ensure_git_branch.rb', line 31

def self.available_options
  [
    PantographCore::ConfigItem.new(
      key: :branch,
      env_name: 'ENSURE_GIT_BRANCH_NAME',
      description: 'The branch that should be checked for. String that can be either the full name of the branch or a regex to match',
      type: String,
      default_value: 'master'
    )
  ]
end

.categoryObject



60
61
62
# File 'pantograph/lib/pantograph/actions/ensure_git_branch.rb', line 60

def self.category
  :source_control
end

.descriptionObject



20
21
22
# File 'pantograph/lib/pantograph/actions/ensure_git_branch.rb', line 20

def self.description
  'Raises an exception if not on a specific git branch'
end

.detailsObject



24
25
26
27
28
29
# File 'pantograph/lib/pantograph/actions/ensure_git_branch.rb', line 24

def self.details
  [
    'This action will check if your git repo is checked out to a specific branch.',
    'You may only want to make releases from a specific branch, so `ensure_git_branch` will stop a lane if it was accidentally executed on an incorrect branch.'
  ].join("\n")
end

.example_codeObject



51
52
53
54
55
56
57
58
# File 'pantograph/lib/pantograph/actions/ensure_git_branch.rb', line 51

def self.example_code
  [
    "ensure_git_branch # defaults to `master` branch",
    "ensure_git_branch(
      branch: 'develop'
    )"
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



64
65
66
# File 'pantograph/lib/pantograph/actions/ensure_git_branch.rb', line 64

def self.is_supported?(platform)
  true
end

.outputObject



43
44
45
# File 'pantograph/lib/pantograph/actions/ensure_git_branch.rb', line 43

def self.output
  []
end

.run(params) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'pantograph/lib/pantograph/actions/ensure_git_branch.rb', line 5

def self.run(params)
  target_branch  = params[:branch]
  current_branch = Helper::Git.current_branch

  if current_branch =~ /#{target_branch}/
    UI.success("Git branch matches `#{target_branch}`, all good! 💪")
  else
    UI.user_error!("Git is not on a branch matching `#{target_branch}`. Current branch is `#{current_branch}`!")
  end
end