Class: PullRequest
Instance Attribute Summary
Attributes inherited from Command
#args, #known_options, #options, #unknown_options
Instance Method Summary collapse
-
#cmd ⇒ Object
Returns a command appropriate for executing at the command line.
-
#new_pr_url ⇒ Object
Returns the URL for a new pull request.
- #parser ⇒ Object
Methods inherited from Command
#current_branch, #default_branch, #initialize, #origin_url, #parse, #protocol, run!, #run!, #service
Constructor Details
This class inherits a constructor from Command
Instance Method Details
#cmd ⇒ Object
Returns a command appropriate for executing at the command line.
41 42 43 44 45 46 47 |
# File 'lib/git-utils/pull_request.rb', line 41 def cmd push = ["git push-branch"] push += argument_string() unless .empty? push = push.join(" ") c = [push, "open #{new_pr_url}"] c.join("\n") end |
#new_pr_url ⇒ Object
Returns the URL for a new pull request.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/git-utils/pull_request.rb', line 15 def new_pr_url if service == 'stash' && protocol == 'ssh' pattern = /(.*)@([^:]*):?([^\/]*)\/([^\/]*)\/(.*)\.git/ replacement = 'https://\2/projects/\4/repos/\5/pull-requests?create&sourceBranch=' + current_branch elsif service == 'stash' && protocol == 'http' pattern = /(.*)@([^:\/]*)(:?[^\/]*)\/(.*)scm\/([^\/]*)\/(.*)\.git/ replacement = 'https://\2\3/\4projects/\5/repos/\6/pull-requests?create&sourceBranch=' + current_branch elsif service == 'github' && protocol == 'ssh' pattern = /(.*)@(.*):(.*)\.git/ replacement = 'https://\2/\3/pull/new/' + current_branch elsif service == 'github' && protocol == 'http' pattern = /https?\:\/\/(([^@]*)@)?(.*)\.git/ replacement = 'https://\3/pull/new/' + current_branch elsif service == 'bitbucket' && protocol == 'ssh' pattern = /(.*)@(.*):(.*)\.git/ replacement = 'https://\2/\3/pull-request/new/' elsif service == 'bitbucket' && protocol == 'http' pattern = /https?\:\/\/(([^@]*)@)?(.*)\.git/ replacement = 'https://\3/pull-request/new/' end origin_url.sub(pattern, replacement) end |
#parser ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/git-utils/pull_request.rb', line 5 def parser OptionParser.new do |opts| opts. = "Usage: git pull-request" opts.on_tail("-h", "--help", "this usage guide") do puts opts.to_s; exit 0 end end end |