Sha256: 2de3dbabe272b1a40f91c020902e100ff5f795a77f2da20e8b8406474d76c31d

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

#!/usr/bin/env ruby

require 'open-uri'
require 'json'

BASE_URL = ENV['JIRA_API_BASE_URL']

def get_story_info(story_id, flags = [], subdomain)
  return nil if story_id.empty?

  begin
    url = BASE_URL + "#{story_id}"
    URI.open(
      url,
      'Authorization' => "Basic #{ENV['JIRA_API_BASIC_AUTH_BASE64_ENCODED']}"
    ).read
  rescue StandardError => e
    story_link = "https://#{subdomain}.atlassian.net/browse/#{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

if BASE_URL.nil? || BASE_URL.empty?
  puts "Please set JIRA_API_BASE_URL. It looks something like 'https://YOUR-COMPANY.atlassian.net/rest/api/2/issue/'"
  exit 1
end

begin
  subdomain = URI.parse(BASE_URL).host.split('.atlassian.net').first
rescue => e
  puts "Error determining your Jira subdomain. Please check your JIRA_API_BASE_URL environment variable"
  exit 1
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-jira-id STORY_ID\n"
  puts " OR\n"
  puts "echo STORY_ID | get-story-info-from-id"
  puts " OR\n"
  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, subdomain)
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-jira-id
pivotoolz-2.4.1 exe/get-story-info-from-jira-id
pivotoolz-2.4.0 exe/get-story-info-from-jira-id
pivotoolz-2.3.0 exe/get-story-info-from-jira-id