Class: Open::PullRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/open-pull-request.rb,
lib/open-pull-request/version.rb

Constant Summary collapse

VERSION =
"0.0.4"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePullRequest

Returns a new instance of PullRequest.



10
11
12
# File 'lib/open-pull-request.rb', line 10

def initialize
  @options = OpenStruct.new
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/open-pull-request.rb', line 9

def options
  @options
end

Instance Method Details

#request!Object



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
# File 'lib/open-pull-request.rb', line 14

def request!
  option_parser.parse!(ARGV)
  branch = get_branch_name
  abort unless $?.success?
  pr_description = "Please give a description"
  if options.trello_card_id
    developer_public_key = `git config trello.developer-public-key`.strip
    member_token = `git config trello.member-token`.strip
    trello_details = TrelloDetails.new(
      options.trello_card_id,
      developer_public_key,
      member_token
    )
    pr_description = trello_details.pull_request_description
  end
  root_url = "https://www.github.com/#{repo_url}/compare/"
  compared_branches = "master...#{CGI.escape(branch.strip)}"
  options = [
    ["pull_request[title]", pr_title],
    ["pull_request[body]", pr_description]
  ].map{|pair|
      pair.map{ |el| CGI.escape(el) }.join("=")
    }.join("&")

  system("open", "#{root_url}#{compared_branches}?#{options}")
end