Class: Fastlane::Actions::CreateMergeRequestAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::CreateMergeRequestAction
- Defined in:
- lib/fastlane/plugin/create_merge_request/actions/create_merge_request_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .category ⇒ Object
- .description ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .output ⇒ Object
- .return_value ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
56 57 58 |
# File 'lib/fastlane/plugin/create_merge_request/actions/create_merge_request_action.rb', line 56 def self. ["masashi mizuno"] end |
.available_options ⇒ Object
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 126 127 128 129 130 |
# File 'lib/fastlane/plugin/create_merge_request/actions/create_merge_request_action.rb', line 64 def self. [ FastlaneCore::ConfigItem.new(key: :api_token, env_name: "GITLAB_MERGE_REQUEST_API_TOKEN", description: "Personal API Access Token for GitLab", sensitive: true, default_value: ENV["GITLAB_API_TOKEN"], is_string: true, optional: false), FastlaneCore::ConfigItem.new(key: :project_id, env_name: "GITLAB_MERGE_REQUEST_PROJECT_ID", description: "The id of the project", is_string: true, optional: false), FastlaneCore::ConfigItem.new(key: :target_project_id, env_name: "GITLAB_MERGE_REQUEST_PROJECT_TARGET_PROJECT_ID", description: "The id of the project you want to submit the merge request to", is_string: true, optional: true), FastlaneCore::ConfigItem.new(key: :title, env_name: "GITLAB_MERGE_REQUEST_TITLE", description: "The title of the merge request", is_string: true, optional: false), FastlaneCore::ConfigItem.new(key: :body, env_name: "GITLAB_MERGE_REQUEST_BODY", description: "The contents of the pull request", is_string: true, optional: true), FastlaneCore::ConfigItem.new(key: :source, env_name: "GITLAB_MERGE_REQUEST_SOURCE_BRANCH", description: "The name of the branch where your changes are implemented (defaults to the current branch name)", is_string: true, default_value: Actions.git_branch, optional: true), FastlaneCore::ConfigItem.new(key: :target, env_name: "GITLAB_MERGE_REQUEST_TARGET_BRANCH", description: "The name of the branch you want your changes pulled into (defaults to `master`)", is_string: true, default_value: 'master', optional: true), FastlaneCore::ConfigItem.new(key: :assignee_id, env_name: "GITLAB_MERGE_REQUEST_ASSIGNEE_ID", description: "Assignee user ID", is_string: false, default_value: '0', optional: true), FastlaneCore::ConfigItem.new(key: :labels, env_name: "GITLAB_MERGE_REQUEST_LABELS", description: "Labels for MR as a comma-separated list", is_string: false, default_value: '', optional: true), FastlaneCore::ConfigItem.new(key: :milestone_id, env_name: "GITLAB_MERGE_REQUEST_MILESTONE_ID", description: "The global ID of a milestone", is_string: false, default_value: '0', optional: true), FastlaneCore::ConfigItem.new(key: :api_url, env_name: "GITLAB_MERGE_REQUEST_API_URL", description: "The URL of GitLab API", is_string: true, default_value: 'https://gitlab.com/api/v4', optional: true) ] end |
.category ⇒ Object
157 158 159 |
# File 'lib/fastlane/plugin/create_merge_request/actions/create_merge_request_action.rb', line 157 def self.category :source_control end |
.description ⇒ Object
52 53 54 |
# File 'lib/fastlane/plugin/create_merge_request/actions/create_merge_request_action.rb', line 52 def self.description "This will create a new marge request on GitLab" end |
.example_code ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/fastlane/plugin/create_merge_request/actions/create_merge_request_action.rb', line 142 def self.example_code [ 'create_merge_request( api_token: ENV["GITLAB_TOKEN"], project_id: "100", target_project_id: "90" title: "Amazing new feature", source: "my-feature", # optional, defaults to current branch name target: "master", # optional, defaults to "master" body: "Please pull this in!", # optional api_url: "http://yourdomain/api/v3" # optional )' ] end |
.is_supported?(platform) ⇒ Boolean
138 139 140 |
# File 'lib/fastlane/plugin/create_merge_request/actions/create_merge_request_action.rb', line 138 def self.is_supported?(platform) return true end |
.output ⇒ Object
132 133 134 135 136 |
# File 'lib/fastlane/plugin/create_merge_request/actions/create_merge_request_action.rb', line 132 def self.output [ ['CREATE_MARGE_REQUEST_HTML_URL', 'Web url of the merge request that we created.'] ] end |
.return_value ⇒ Object
60 61 62 |
# File 'lib/fastlane/plugin/create_merge_request/actions/create_merge_request_action.rb', line 60 def self.return_value "The marge request URL when successful" 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fastlane/plugin/create_merge_request/actions/create_merge_request_action.rb', line 10 def self.run(params) require 'excon' target_project_id = params[:target_project_id] || params[:project_id] UI.("Creating new merge request from #{params[:source]} to branch #{params[:target]} of project_id #{target_project_id}") url = "#{params[:api_url]}/projects/#{params[:project_id]}/merge_requests" headers = { 'Content-Type' => 'application/json', 'Private-Token' => "#{params[:api_token]}" } payload = { 'title' => params[:title], 'source_branch' => params[:source], 'target_branch' => params[:target], 'assignee_id' => params[:assignee_id], 'labels' => params[:labels], 'milestone_id' => params[:milestone_id], 'target_project_id' => target_project_id, } payload['description'] = params[:body] if params[:body] response = Excon.post(url, headers: headers, body: payload.to_json) if response[:status] == 201 body = JSON.parse(response.body) id = body['iid'] web_url = body['web_url'] Actions.lane_context[SharedValues::CREATE_MARGE_REQUEST_HTML_URL] = web_url UI.success("Successfully created pull request ##{id}. You can see it at '#{web_url}'") return web_url elsif response[:status] != 200 body = JSON.parse(response.body) UI.error("GitLab responded with #{response[:status]}: #{body['message']}") return nil end end |