Sha256: e8000970a6dff99cb9699e01109232b9a3df311906daf60291dc746dafedc355
Contents?: true
Size: 1.31 KB
Versions: 6
Compression:
Stored size: 1.31 KB
Contents
#!/usr/bin/env ruby require 'open-uri' require 'json' BASE_URL = "https://www.pivotaltracker.com/services/v5/stories/" def get_story_info(story_id, flags = []) return nil if story_id.empty? begin include_owner_names = flags.any? { |f| f == '--owners' || f == '-O' } url = BASE_URL + "#{story_id}" + "/#{include_owner_names ? '?fields=:default,owners' : ''}" open( url, 'X-TrackerToken' => ENV['PIVOTAL_TRACKER_API_TOKEN'] ).read rescue StandardError => e story_link = "https://www.pivotaltracker.com/story/show/#{story_id}" JSON.generate({ error: "Could not get story info for story #{story_id}: #{e.message}\n\nStory info may be available at #{story_link}", story_link: story_link }) end end flags = ARGV.reduce([]) do |reduced, a| reduced << a if a.include?('--') || a.include?('-') reduced end flags.each { |f| ARGV.delete f } stream = ARGV.any? ? ARGV : ARGF if stream == ARGF && $stdin.tty? puts "Usage:\nget-story-info-from-id STORY_ID\n" puts " OR\n" puts "echo STORY_ID | get-story-info-from-id" puts " OR\n" puts "use --w-owner-names to include owner names" exit 1 end infos = stream.reduce([]) do |reduced, story_id| next reduced unless story_id && story_id =~ /\d+/ reduced << get_story_info(story_id.strip, flags) end puts infos.join("\n")
Version data entries
6 entries across 6 versions & 1 rubygems