Created
September 9, 2012 04:11
-
-
Save trevershick/3682539 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'rally_rest_api.rb' | |
require 'base64' | |
require 'mime/types' | |
class CreateDefect | |
attr_accessor :workspace, :project, :rally | |
def initialize(h) | |
# Add a log file (only needed for development) | |
h.each {|k,v| send("#{k}=",v)} | |
end | |
def create(arg_hash) | |
print "Creating the Defect\n" | |
defect = @rally.create(:defect, :name=>arg_hash[:title] ) | |
print "New defect created " + defect.formatted_i_d + "\n" | |
unless arg_hash[:file].nil? | |
File.open(arg_hash[:file], 'r') do |image_file| | |
print "Uploading the file..., file size is " + File.size(image_file).to_s + "\n" | |
attachmentContent = @rally.create(:attachment_content, | |
:content=>Base64.encode64(image_file.read)) | |
print "Upload Complete" + "\n" | |
print "Creating the Attachment\n" | |
attachment = @rally.create(:attachment, | |
:name => File.basename(image_file.path), | |
:size => File.size(image_file), | |
:content_type=> MIME::Types.type_for(image_file.path).first, | |
:content=>attachmentContent, | |
:artifact=>defect) | |
end | |
end | |
print "Done\n" | |
end | |
end | |
if ARGV[0].nil? || ARGV[1].nil? || ARGV[2].nil? | |
puts "Usage" | |
puts "createdefect.rb <Title> <Attachment> <Project Name>" | |
exit | |
end | |
defect_title = ARGV[0] | |
# Modify the instance variables below | |
@user_name = "XXXXXXX" | |
@password = "XXXXX" | |
@workspace_name = "XXXXX" | |
@project_name = ARGV[2] | |
@base_url = "https://rally1.rallydev.com/slm" | |
@logger = Logger.new("/Users/trevershick/bin/createdefect.log") | |
@logger.level = Logger::DEBUG | |
# Login to the Rally app | |
rally = RallyRestAPI.new(:base_url => @base_url, | |
:username => @user_name, | |
:password => @password, | |
:logger => @logger) | |
workspace = rally.user.subscription.workspaces.find { |w| w.name == @workspace_name } | |
if workspace.nil? | |
print "Workspace: " + workspace_name + " not found\n" | |
exit | |
end | |
print "Found Workspace: " + workspace.name + "\n" | |
# Find the project by name | |
project = workspace.projects.find { |p| p.name.downcase.start_with?(@project_name.downcase) } | |
if project.nil? | |
print "Project: " + project_name + " not found\n" | |
exit | |
end | |
print "Found Project: " + project.name + "\n" | |
f = CreateDefect.new(:rally => rally, :workspace => workspace, :project => project) | |
f.create(:title=> ARGV[0], :file => ARGV[1]) | |
#f.run(@user_name, @password, @workspace_name, @project_name, @base_url, defect_title) |
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
on run {input, parameters} | |
set thePrefix to "" | |
set defectTitle to "Default Defect Title" | |
set theIcon to note | |
repeat | |
display dialog thePrefix & "Please enter a defect title for " & input & " : " default answer defectTitle with icon theIcon | |
set theTitle to text returned of result | |
try | |
if theTitle = "" then error | |
exit repeat | |
on error | |
set thePrefix to "INVALID ENTRY! " | |
set theIcon to stop | |
end try | |
end repeat | |
return theTitle as text | |
end run |
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
on run {input, parameters} | |
set projects to {"LOA", "Rizzo"} | |
set project to (choose from list projects with prompt "Choose the project" without multiple selections allowed) as text | |
if project is "false" then | |
error number -128 | |
end if | |
return project as text | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment