class StoryAccept

Public Instance Methods

accept!(story_id) click to toggle source

Changes a story’s state to Accepted.

# File lib/pivotal-github/story_accept.rb, line 66
def accept!(story_id)
  accepted = "<story><current_state>accepted</current_state></story>"
  data =  { 'X-TrackerToken' => api_token,
            'Content-type'   => "application/xml" }
  uri = story_uri(story_id)
  Net::HTTP.start(uri.host, uri.port) do |http|
    http.put(uri.path, accepted, data)
  end
  puts "Accepted story ##{story_id}" unless options.quiet
end
already_accepted?(story_id) click to toggle source

Returns true if a story has already been accepted.

# File lib/pivotal-github/story_accept.rb, line 58
def already_accepted?(story_id)
  response = Net::HTTP.start(uri.host, uri.port) do |http|
    http.get(uri.path, data)
  end
  Nokogiri::XML(response.body).at_css('current_state').content == "accepted"
end
ids_to_accept() click to toggle source

Returns the ids to accept. The stories to accept are the set intersection of the delivered stories according to the Git log and according to Pivotal Tracker.

# File lib/pivotal-github/story_accept.rb, line 36
def ids_to_accept
  git_log_delivered_story_ids & pivotal_tracker_delivered_story_ids
end
parser() click to toggle source
# File lib/pivotal-github/story_accept.rb, line 12
def parser
  OptionParser.new do |opts|
    opts.banner = "Usage: git story-accept [options]"
    opts.on("-o", "--override", "override master branch requirement") do |opt|
      self.options.override = opt
    end
    opts.on("-q", "--quiet", "don't display accepted story ids") do |opt|
      self.options.quiet = opt
    end
    opts.on_tail("-h", "--help", "this usage guide") do
      puts opts.to_s; exit 0
    end
  end
end
pivotal_tracker_delivered_story_ids() click to toggle source

Returns the ids of delivered stories according to Pivotal Tracker. We include ‘includedone:true’ to force Pivotal Tracker to return all delivered ids, no matter when the story was finished. This also appears to be necessary to return the ids of stories marked Delivered by a merge commit, as in ‘git story-merge -d`.

# File lib/pivotal-github/story_accept.rb, line 53
def pivotal_tracker_delivered_story_ids
  pivotal_tracker_ids('state:delivered includedone:true')
end
pivotal_tracker_ids(filter) click to toggle source
# File lib/pivotal-github/story_accept.rb, line 40
def pivotal_tracker_ids(filter)
  uri = URI.parse("#{project_uri}/stories?filter=#{CGI::escape(filter)}")
  response = Net::HTTP.start(uri.host, uri.port) do |http|
    http.get(uri, data)
  end
  Nokogiri::XML(response.body).css('story > id').map(&:content)
end
run!() click to toggle source
# File lib/pivotal-github/story_accept.rb, line 77
def run!
  if story_branch != 'master' && !options['override']
    puts "Runs only on the master branch by default"
    puts "Use --override to override"
    exit 1
  end
  ids_to_accept.each { |id| accept!(id) }
end
story_id() click to toggle source

The story_id has a different meaning in this context, so raise an error if it’s called accidentally.

# File lib/pivotal-github/story_accept.rb, line 29
def story_id
  raise 'Invalid reference to Command#story_id'
end

Private Instance Methods

api_base() click to toggle source
# File lib/pivotal-github/story_accept.rb, line 88
def api_base
  'http://www.pivotaltracker.com/services/v3'
end
data() click to toggle source

Returns data for Pivotal Tracker API calls

# File lib/pivotal-github/story_accept.rb, line 101
def data
  { 'X-TrackerToken' => api_token,
    'Content-type'   => "application/xml" }
end
project_uri() click to toggle source
# File lib/pivotal-github/story_accept.rb, line 92
def project_uri
  URI.parse("#{api_base}/projects/#{project_id}")
end
story_uri(story_id) click to toggle source
# File lib/pivotal-github/story_accept.rb, line 96
def story_uri(story_id)
  URI.parse("#{project_uri}/stories/#{story_id}")
end