Sha256: f739cfa98e3cfa5d949685de9e419f948dd09b3f09eeb3304306726e49471983

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

require 'pivotal-github/command'
require 'pivotal-github/finished_command'

class StoryPullRequest < FinishedCommand

  def parser
    OptionParser.new do |opts|
      opts.banner = "Usage: git story-pull-request [options]"
      opts.on("-f", "--force", "override unfinished story warning") do |opt|
        self.options.force = opt
      end
      opts.on("-s", "--skip", "skip `git story-push`") do |opt|
        self.options.skip = opt
      end
      opts.on_tail("-h", "--help", "this usage guide") do
        puts opts.to_s; exit 0
      end
    end
  end

  # Returns a command appropriate for executing at the command line
  # I.e., 'open https://www.pivotaltracker.com/story/show/6283185'
  def cmd
    if skip?
      "open #{uri}"
    else
      "git story-push && open #{uri}"
    end
  end

  def uri
    "#{origin_uri}/pull/new/#{story_branch}"
  end

  private

    # Returns the raw remote location for the repository.
    # E.g., http://github.com/mhartl/pivotal-github or
    # git@github.com:mhartl/pivotal-github
    def remote_location
      `git config --get remote.origin.url`.strip.chomp('.git')
    end

    # Returns the remote URI for the repository.
    # Both https://... and git@... remote formats are supported.
    def origin_uri
      remote_location.sub(/^git@(.+?):(.+)$/, 'https://\1/\2')
    end

    def skip?
      options.skip
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pivotal-github-0.7.0 lib/pivotal-github/story_pull_request.rb
pivotal-github-0.6.14 lib/pivotal-github/story_pull_request.rb