Created
July 19, 2013 14:49
-
-
Save faraazkhan/6039654 to your computer and use it in GitHub Desktop.
Simple Utility to create To start using this:
First gem install jira-ruby
Then change the following constants to your preferences: USERNAME
PASSWORD
URL
FEATURE_DIRECTORY
EXTENSION to run this code try ``` ruby features.rb hioshc-23 ``` KNOWN ISSUE: ONCE IN A WHILE THE JIRA API BLOCKS ACCESS TO THE APPLICATION FROM LOCAL. YOU WILL SEE THE FOLLOW…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'jira' | |
require 'fileutils' | |
class Features | |
USERNAME='yourJIRAusername' | |
PASSWORD= 'yourJIRApassword' | |
URL= 'https://www.cws-cgicloud-apps.com:8443' | |
FEATURE_DIRECTORY= 'Full Path to the Directory Where you would like to save the Feature file' | |
EXTENSION='The extension you would like for the file. Example for .feature just type feature here' | |
def self.jira | |
@jira ||= JIRA::Client.new(credentials) | |
end | |
def self.credentials | |
{ | |
:username => USERNAME, | |
:password => PASSWORD, | |
:site => URL, | |
:context_path => '', | |
:auth_type => :basic | |
} | |
end | |
def self.find_story_by(issuekey) | |
if jira_credentials | |
begin | |
@issue ||= jira.Issue.find(issuekey) | |
rescue | |
raise "Issue Not Found. Please enter a valid JIRA ID" | |
end | |
end | |
end | |
def self.test_cases_for(story) | |
if story | |
@test_cases ||= story.issuelinks.select { |i| i["type"]["name"] == "Test Case" } | |
@tests ||= @test_cases.collect {|t| t["inwardIssue"]["key"] } | |
else | |
raise "User Story Not Found. Please enter a valid JIRA ID" | |
end | |
end | |
def self.feature_file_for(issuekey) | |
string = '' | |
if story = find_story_by(issuekey) | |
raise 'No test cases were related to the Issue ID provided' unless test_cases_for(story).any? | |
string << <<-STORY | |
FEATURE: #{story.summary} \n | |
#{story.description} \n | |
#{story.customfield_10116} \n \n \n | |
STORY | |
test_cases_for(story).each do |test_case_id| | |
tc = jira.Issue.find(test_case_id) rescue nil | |
if tc | |
string << <<-STRING | |
#{tc.summary} \n | |
#{tc.description}\n\n | |
STRING | |
end | |
end | |
end | |
File.open("#{FEATURE_DIRECTORY}/#{issuekey}.#{EXTENSION}", 'w') { |f| f.write(string) } | |
end | |
def self.jira_credentials | |
jira.Issuetype.all rescue raise "Invalid username and /or password" | |
end | |
end | |
issuekey = ARGV[0] | |
file = Features.feature_file_for(issuekey) | |
puts "Your feature file has been saved as #{Features::FEATURE_DIRECTORY}/#{issuekey}.#{Features::EXTENSION}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment