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.
-
#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
#delivered_ids, #delivered_ids_since_last_pr, #fast_log_delivered_text, #git_log_delivered_story_ids, #pr_ids, #story_url
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.
66 67 68 69 70 71 72 73 74 75 |
# 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 .quiet end |
#already_accepted?(story_id) ⇒ Boolean
Returns true if a story has already been accepted.
58 59 60 61 62 63 |
# 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 ⇒ 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`.
53 54 55 |
# 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) ⇒ Object
40 41 42 43 44 45 46 |
# 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! ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/pivotal-github/story_accept.rb', line 77 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 |