class Dude::CodeManagement::Github::CreatePullRequest
Attributes
issue[R]
owner[R]
params[R]
repo[R]
Public Instance Methods
call(client, issue:, owner:, repo:, params:)
click to toggle source
# File lib/dude/code_management/github/create_pull_request.rb, line 9 def call(client, issue:, owner:, repo:, params:) @issue = issue @owner = owner @repo = repo @params = params return unless issue response = client.post("https://api.github.com/repos/#{owner}/#{repo}/pulls", body.to_json) res = JSON.parse(response.body) return github_error if res['errors'] && !res['errors'].empty? url = res['html_url'] puts "Pull request has been created: #{url}" end
Private Instance Methods
body()
click to toggle source
# File lib/dude/code_management/github/create_pull_request.rb, line 36 def body { title: params[:title] || template[:title], body: params[:body] || template[:body], head: params[:head], base: params[:base] } end
fill_variables(text)
click to toggle source
# File lib/dude/code_management/github/create_pull_request.rb, line 52 def fill_variables(text) text .then { _1.gsub('{issue_id}', issue.id) }.chomp .then { _1.gsub('{issue_url}', issue.url) } .then { _1.gsub('{issue_title}', issue.title) } end
github_error()
click to toggle source
# File lib/dude/code_management/github/create_pull_request.rb, line 30 def github_error puts <<~HEREDOC #{'Error:'.red.bold} GitHub cannot create new Pull Request from #{params[:head].bold} branch. Try to push your branch and try again HEREDOC end
template()
click to toggle source
# File lib/dude/code_management/github/create_pull_request.rb, line 45 def template Dude::SETTINGS.dig(:github, :pr_template).tap do |template| template[:title] = fill_variables(template[:title]) template[:body] = fill_variables(template[:body]) end end