Class: StoryAccept
- Includes:
- ConfigFiles, Story
- Defined in:
- lib/pivotal-github/story_accept.rb
Instance Attribute Summary
Attributes inherited from Command
#args, #cmd, #known_options, #options, #unknown_options
Instance Method Summary collapse
-
#accept!(story_id) ⇒ Object
Changes a story’s state to Accepted.
-
#already_accepted?(story_id) ⇒ Boolean
Returns true if a story has already been accepted.
-
#git_log_delivered_story_ids ⇒ Object
Returns the ids of delivered stories according to the Git log.
-
#ids_to_accept ⇒ Object
Returns the ids to accept.
- #parser ⇒ Object
-
#pivotal_tracker_delivered_story_ids ⇒ Object
Returns the ids of delivered stories according to Pivotal Tracker.
- #pivotal_tracker_ids(filter) ⇒ Object
- #run! ⇒ Object
-
#story_id ⇒ Object
The story_id has a different meaning in this context, so raise an error if it’s called accidentally.
Methods included from ConfigFiles
#api_token, #config_filename, #project_id
Methods included from Story
Methods inherited from Command
#initialize, #message, #message_ids, #parse, run!, #story_branch, #story_ids
Constructor Details
This class inherits a constructor from Command
Instance Method Details
#accept!(story_id) ⇒ Object
Changes a story’s state to Accepted.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/pivotal-github/story_accept.rb', line 75 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 .quiet end |
#already_accepted?(story_id) ⇒ Boolean
Returns true if a story has already been accepted.
67 68 69 70 71 72 |
# File 'lib/pivotal-github/story_accept.rb', line 67 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 |
#git_log_delivered_story_ids ⇒ Object
Returns the ids of delivered stories according to the Git log. These ids are of the form [Delivers #<story id>] or [Delivers #<story id> #<another story id>]. The difference is handled by the delivered_ids method.
44 45 46 47 |
# File 'lib/pivotal-github/story_accept.rb', line 44 def git_log_delivered_story_ids delivered_text = `git log -E --grep '\\[Deliver(s|ed) #'` delivered_ids(delivered_text).uniq end |
#ids_to_accept ⇒ Object
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.
36 37 38 |
# 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 ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pivotal-github/story_accept.rb', line 12 def parser OptionParser.new do |opts| opts. = "Usage: git story-accept [options]" opts.on("-o", "--override", "override master branch requirement") do |opt| self..override = opt end opts.on("-q", "--quiet", "don't display accepted story ids") do |opt| self..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 ⇒ Object
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`.
62 63 64 |
# File 'lib/pivotal-github/story_accept.rb', line 62 def pivotal_tracker_delivered_story_ids pivotal_tracker_ids('state:delivered includedone:true') end |
#pivotal_tracker_ids(filter) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/pivotal-github/story_accept.rb', line 49 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! ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/pivotal-github/story_accept.rb', line 86 def run! if story_branch != 'master' && !['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 ⇒ Object
The story_id has a different meaning in this context, so raise an error if it’s called accidentally.
29 30 31 |
# File 'lib/pivotal-github/story_accept.rb', line 29 def story_id raise 'Invalid reference to Command#story_id' end |