Sha256: 8e260d826f6768932f96cd231c736eae1afd4b4fd75118c4887b3aa3e36dd15f

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 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' : ''}"
    URI.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

4 entries across 4 versions & 1 rubygems

Version Path
pivotoolz-2.4.2 exe/get-story-info-from-id
pivotoolz-2.4.1 exe/get-story-info-from-id
pivotoolz-2.4.0 exe/get-story-info-from-id
pivotoolz-2.3.0 exe/get-story-info-from-id