Commit 98eb064
Changed files (5)
lib/jive/cli.rb
@@ -9,6 +9,8 @@ require "jive"
module Jive
module Cli
class App < Thor
+ SSH_REGEX = %r{\Agit@(?<host>.+):(?<account>.+)/(?<repo>.+)\z}.freeze
+
package_name "jive"
def self.exit_on_failure?
@@ -75,7 +77,20 @@ module Jive
end
desc "pr URL", "pull request"
- def pr(url)
+ def pr(url = nil)
+ if url.nil?
+ repo = Rugged::Repository.new(".")
+ remote = repo.remotes.find { |x| x.name == "origin" }
+ return say("origin remote not found") && exit(1) if remote.nil?
+
+ if (match = remote.url.match(SSH_REGEX))
+ url = ["https:/", match[:host], match[:account], match[:repo], repo.head.name].join("/")
+ else
+ uri = URI.parse(remote.url)
+ url = [uri.host, uri.path, repo.head.name].join("/")
+ end
+ end
+
pr = PullRequest.new(url)
pr.edit(ENV["EDITOR"])
end
lib/jive/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
module Jive
- VERSION = "0.4.3"
+ VERSION = "0.4.4"
end
lib/jive.rb
@@ -2,6 +2,7 @@
require "fileutils"
require "open3"
+require "rugged"
require "uri"
require "jive/batch_runner"
Gemfile.lock
@@ -2,6 +2,7 @@ PATH
remote: .
specs:
jive (0.4.3)
+ rugged (~> 1.1)
thor (~> 1.1)
GEM
@@ -32,6 +33,7 @@ GEM
rubocop-rake (0.5.1)
rubocop
ruby-progressbar (1.11.0)
+ rugged (1.1.0)
thor (1.1.0)
unicode-display_width (2.0.0)
jive.gemspec
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
$ jive setup
MESSAGE
+ spec.add_dependency "rugged", "~> 1.1"
spec.add_dependency "thor", "~> 1.1"
spec.add_development_dependency "minitest", "~> 5.0"
spec.add_development_dependency "rake", "~> 13.0"