Class: Pantograph::Actions::DangerAction

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

Constant Summary

Constants inherited from Pantograph::Action

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

Class Method Summary collapse

Methods inherited from Pantograph::Action

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

Class Method Details

.authorsObject



147
148
149
# File 'pantograph/lib/pantograph/actions/danger.rb', line 147

def self.authors
  ['KrauseFx', 'johnknapprs']
end

.available_optionsObject



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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'pantograph/lib/pantograph/actions/danger.rb', line 40

def self.available_options
  [
    PantographCore::ConfigItem.new(
      key: :use_bundle_exec,
      env_name: 'DANGER_USE_BUNDLE_EXEC',
      description: 'Use bundle exec when there is a Gemfile presented',
      is_string: false,
      default_value: true
    ),
    PantographCore::ConfigItem.new(
      key: :verbose,
      env_name: 'DANGER_VERBOSE',
      description: 'Show more debugging information',
      is_string: false,
      default_value: false
    ),
    PantographCore::ConfigItem.new(
      key: :danger_id,
      env_name: 'DANGER_ID',
      description: 'The identifier of this Danger instance',
      type: String,
      optional: true
    ),
    PantographCore::ConfigItem.new(
      key: :dangerfile,
      env_name: 'DANGER_DANGERFILE',
      description: 'The location of your Dangerfile',
      type: String,
      optional: false,
      default_value: 'Dangerfile'
    ),
    PantographCore::ConfigItem.new(
      key: :github_api_token,
      env_name: 'DANGER_GITHUB_API_TOKEN',
      description: 'GitHub API token for danger',
      sensitive: true,
      type: String,
      optional: true
    ),
    PantographCore::ConfigItem.new(
      key: :fail_on_errors,
      env_name: 'DANGER_FAIL_ON_ERRORS',
      description: 'Should always fail the build process, defaults to false',
      is_string: false,
      optional: true,
      default_value: false
    ),
    PantographCore::ConfigItem.new(
      key: :new_comment,
      env_name: 'DANGER_NEW_COMMENT',
      description: 'Makes Danger post a new comment instead of editing its previous one',
      is_string: false,
      optional: true,
      default_value: false
    ),
    PantographCore::ConfigItem.new(
      key: :remove_previous_comments,
      env_name: 'DANGER_REMOVE_PREVIOUS_COMMENT',
      description: 'Makes Danger remove all previous comment and create a new one in the end of the list',
      is_string: false,
      optional: true,
      default_value: false
    ),
    PantographCore::ConfigItem.new(
      key: :base,
      env_name: 'DANGER_BASE',
      description: 'A branch/tag/commit to use as the base of the diff. [master|dev|stable]',
      type: String,
      optional: true
    ),
    PantographCore::ConfigItem.new(
      key: :head,
      env_name: 'DANGER_HEAD',
      description: 'A branch/tag/commit to use as the head. [master|dev|stable]',
      type: String,
      optional: true
    ),
    PantographCore::ConfigItem.new(
      key: :pr,
      env_name: 'DANGER_PR',
      description: 'Run danger on a specific pull request. e.g. \"https://github.com/danger/danger/pull/518\"',
      type: String,
      optional: true
    )
  ]
end

.categoryObject



143
144
145
# File 'pantograph/lib/pantograph/actions/danger.rb', line 143

def self.category
  :source_control
end

.descriptionObject



29
30
31
# File 'pantograph/lib/pantograph/actions/danger.rb', line 29

def self.description
  'Runs `danger` for the project'
end

.detailsObject



33
34
35
36
37
38
# File 'pantograph/lib/pantograph/actions/danger.rb', line 33

def self.details
  [
    'Stop Saying your Forgot in Source Control',
    'More information: [https://github.com/danger/danger](https://github.com/danger/danger).'
  ].join("\n")
end

.example_codeObject



131
132
133
134
135
136
137
138
139
140
141
# File 'pantograph/lib/pantograph/actions/danger.rb', line 131

def self.example_code
  [
    'danger',
    'danger(
      danger_id: "unit-tests",
      dangerfile: "tests/MyOtherDangerFile",
      github_api_token: ENV["GITHUB_API_TOKEN"],
      verbose: true
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



127
128
129
# File 'pantograph/lib/pantograph/actions/danger.rb', line 127

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'pantograph/lib/pantograph/actions/danger.rb', line 4

def self.run(params)
  ENV['DANGER_GITHUB_API_TOKEN'] = params[:github_api_token] if params[:github_api_token]

  danger_cmd = []

  if params[:use_bundle_exec] && shell_out_should_use_bundle_exec?
    danger_cmd << 'bundle exec'
  end

  danger_cmd << 'danger'
  danger_cmd << "--dangerfile=#{params[:dangerfile]}"
  danger_cmd << "--new-comment"                     if params[:new_comment]
  danger_cmd << "--remove-previous-comments"        if params[:remove_previous_comments]
  danger_cmd << "--base=#{params[:base]}"           if params[:base]
  danger_cmd << "--head=#{params[:head]}"           if params[:head]
  danger_cmd << "pr #{params[:pr]}"                 if params[:pr]
  danger_cmd << "--danger_id=#{params[:danger_id]}" if params[:danger_id]
  danger_cmd << '--verbose'                         if params[:verbose]

  danger_cmd << "--fail-on-errors=#{params[:fail_on_errors]}"
  danger_cmd = danger_cmd.join(' ')

  Actions.sh(danger_cmd)
end