Class: Fastlane::Actions::CreateBitbucketPullRequestAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



37
38
39
# File 'lib/fastlane/plugin/create_bitbucket_pull_request/actions/create_bitbucket_pull_request_action.rb', line 37

def self.authors
  ['Issarapong Poesua']
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/create_bitbucket_pull_request/actions/create_bitbucket_pull_request_action.rb', line 50

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :head,
                                 env_name: 'CREATE_BITBUCKET_PULL_REQUEST_HEAD',
                                 description: 'The name of the branch where your changes are implemented',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :target,
                                 env_name: 'CREATE_BITBUCKET_PULL_REQUEST_TARGET',
                                 description: 'The name of the branch you want your changes pulled into',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :owner,
                                 env_name: 'CREATE_BITBUCKET_PULL_REQUEST_REPOSITORY_OWNER',
                                 description: 'The name of the repository owner (slug)',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :repository,
                                 env_name: 'CREATE_BITBUCKET_PULL_REQUEST_REPOSITORY_NAME',
                                 description: 'The name of the repository you want to submit the pull request to',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :title,
                                 env_name: 'CREATE_BITBUCKET_PULL_REQUEST_TITLE',
                                 description: 'The title of the pull request',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :description,
                                 env_name: 'CREATE_BITBUCKET_PULL_REQUEST_DESCRIPTION',
                                 description: 'The contents of the pull request',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :username,
                                 env_name: 'CREATE_BITBUCKET_PULL_REQUEST_USERNAME',
                                 description: 'The Bitbucket username (email)',
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :password,
                                 env_name: 'CREATE_BITBUCKET_PULL_REQUEST_PASSWORD',
                                 description: 'The Bitbucket password',
                                 type: String)
  ]
end

.descriptionObject



33
34
35
# File 'lib/fastlane/plugin/create_bitbucket_pull_request/actions/create_bitbucket_pull_request_action.rb', line 33

def self.description
  'This lane creates create bitbucket pull request'
end

.detailsObject



45
46
47
48
# File 'lib/fastlane/plugin/create_bitbucket_pull_request/actions/create_bitbucket_pull_request_action.rb', line 45

def self.details
  # Optional:
  'This lane creates create bitbucket pull request'
end

.is_supported?(_platform) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
90
91
92
93
# File 'lib/fastlane/plugin/create_bitbucket_pull_request/actions/create_bitbucket_pull_request_action.rb', line 87

def self.is_supported?(_platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.return_valueObject



41
42
43
# File 'lib/fastlane/plugin/create_bitbucket_pull_request/actions/create_bitbucket_pull_request_action.rb', line 41

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fastlane/plugin/create_bitbucket_pull_request/actions/create_bitbucket_pull_request_action.rb', line 10

def self.run(params)
  UI.message("Creating new bitbucket pull request from '#{params[:head]}' to branch '#{params[:target]}' of '#{params[:owner]}/#{params[:repository]}'")
  response = JSON.parse(Net::HTTP.post(
    URI("https://api.bitbucket.org/2.0/repositories/#{params[:owner]}/#{params[:repository]}/pullrequests"),
    {
      "destination": { "branch": { "name": params[:target] } },
      "source": { "branch": { "name": params[:head] } },
      "title": params[:title],
      "description": params[:description]
    }.to_json,
    "Authorization": "Basic #{Base64.encode64("#{params[:username]}:#{params[:password]}").gsub("\n", '')}",
    "Content-Type": 'application/json'
  ).body)

  if response['error']
    raise(response['error']['message'])
  else
    UI.message('The pull request has been created successfully')
    UI.message((response['links']['html']['href']).to_s)
    response['links']['html']['href']
  end
end