Class: Fastlane::Actions::PrCreateAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/stream_actions/actions/pr_create.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.available_optionsObject



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
70
71
72
73
74
# File 'lib/fastlane/plugin/stream_actions/actions/pr_create.rb', line 39

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      env_name: 'GITHUB_REPOSITORY',
      key: :github_repo,
      description: 'GitHub repo name',
      verify_block: proc do |name|
        UI.user_error!("GITHUB_REPOSITORY should not be empty") if name.to_s.empty?
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :base_branch,
      description: 'Base branch',
      is_string: true,
      default_value: 'develop'
    ),
    FastlaneCore::ConfigItem.new(
      key: :head_branch,
      description: 'Head branch',
      is_string: true,
      optional: false
    ),
    FastlaneCore::ConfigItem.new(
      key: :title,
      description: 'Title',
      is_string: true,
      optional: false
    ),
    FastlaneCore::ConfigItem.new(
      key: :git_add,
      description: 'Path that should be commited',
      is_string: true,
      default_value: '-A'
    )
  ]
end

.descriptionObject



35
36
37
# File 'lib/fastlane/plugin/stream_actions/actions/pr_create.rb', line 35

def self.description
  'Create PR'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/fastlane/plugin/stream_actions/actions/pr_create.rb', line 76

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
28
29
# File 'lib/fastlane/plugin/stream_actions/actions/pr_create.rb', line 4

def self.run(params)
  sh("git checkout -b #{params[:head_branch]}")
  sh('git restore Brewfile.lock.json || true')
  sh("git add #{params[:git_add]}")
  staged_files = sh('git diff --cached --name-only').split
  if staged_files.empty?
    unstaged_files = sh('git diff --name-only')
    UI.important("There is nothing to commit. See unstaged files for more details:\n#{unstaged_files}")
  else
    sh("git commit -m '#{params[:title]}'")
    other_action.push_to_git_remote(tags: false)

    run_url = "#{ENV['GITHUB_SERVER_URL']}/#{ENV['GITHUB_REPOSITORY']}/actions/runs/#{ENV['GITHUB_RUN_ID']}" if ENV['GITHUB_RUN_ID']
    body = 'This PR was created automatically by CI.'
    body += "\n\nTriggered by: #{run_url}" if run_url

    other_action.create_pull_request(
      api_token: ENV.fetch('GITHUB_TOKEN'),
      repo: params[:github_repo],
      title: params[:title],
      head: params[:head_branch],
      base: params[:base_branch],
      body: body
    )
  end
end