class PivotalIntegration::Command::Finish

The class that encapsulates finishing a Pivotal Tracker Story

Public Instance Methods

run(*arguments) click to toggle source

Finishes a Pivotal Tracker story by doing the following steps:

  • Check that the pending merge will be trivial

  • Merge the development branch into the root branch

  • Delete the development branch

  • Push changes to remote

@return [void]

# File lib/pivotal-integration/command/finish.rb, line 29
def run(*arguments)
  no_complete = @options.fetch(:no_complete, false)
  no_delete = @options.fetch(:no_delete, false)
  no_merge = @options.fetch(:no_merge, false)
  pull_request = @options.fetch(:pull_request, false) || PivotalIntegration::Util::Git.finish_mode == :pull_request

  if pull_request
    root_branch = PivotalIntegration::Util::Git.get_config('root-branch', :branch)
    root_branch = nil if root_branch == 'master'

    PivotalIntegration::Util::Git.push PivotalIntegration::Util::Git.branch_name
    PivotalIntegration::Util::Git.create_pull_request(@configuration.story, root_branch)
    PivotalIntegration::Util::Story.mark(@configuration.story, :finished)
    return
  end

  unless no_merge
    PivotalIntegration::Util::Git.trivial_merge?
    PivotalIntegration::Util::Git.merge(@configuration.story, no_complete, no_delete)
  end

  PivotalIntegration::Util::Git.push PivotalIntegration::Util::Git.branch_name
end