jira_attachment_importer-csv.rb
def uploadCSV()
	log_file_creation()
	$log.unknown "---------------------------------------------SCRIPT STARTED---------------------------------------------"
	if test_connection()
		attachments_to_upload = CSV.read("#{$csv_path}", headers: true)
		
		attachments_to_upload.each do |attachment|
			#convert row from string to array
			attachment_arr = "#{attachment}".split(',')
			
			path = "#{attachment_arr[0]}".strip
			project_name = "#{attachment_arr[1]}".strip
			issue_name = "#{attachment_arr[2]}".strip
			
			path_arr = "#{path}".split('\\')
			#check if path has a filename with extention -- includes a period or not 
			if "#{path_arr[path_arr.length() - 1]}".include? "." 
				#if it does -- need to grab that individual file and upload it.
				attach(project_name, issue_name, path)
			else 
				#if it doesn't -- need to iterate over all attachments in directory
				#begin
					files_in_dir = Dir.entries(path)
					for file in files_in_dir do
						if "#{file}" != "." && "#{file}" != ".."
							file_path = "#{path}\\" + file
							attach(project_name, issue_name, file_path)
						end
					end
				#rescue
				#	puts "Directory #{path} does not exist."
				#	$upload_failed_count += 1
				#	write_to_file("Directory #{path} does not exist", "error")
				#end
			end
		end	
			
		if "#{$upload_failed_count}" != "0"
			puts "----------------------------------------------------------------------------------------------------------"
			puts ""
			puts "Script completed with errors: Not all files were uploaded successfully, please check log file for more details --- #{$log_path}"
			puts ""
			puts "----------------------------------------------------------------------------------------------------------"
		else
			puts "----------------------------------------------------------------------------------------------------------"
			puts ""
			puts "                  Script completed with no errors: All files were uploaded successfully."
			puts ""
			puts "----------------------------------------------------------------------------------------------------------"

		end
	end
	$log.unknown "---------------------------------------------SCRIPT ENDED---------------------------------------------"
	$log.close()
end
#Iterates over each row in CSV file to upload each attachment. 
Iterates over each row in CSV file to upload each attachment.
Iterates over each row in CSV file to upload each attachment .
def uploadCSV()
	log_file_creation()
	$log.unknown "---------------------------------------------SCRIPT STARTED---------------------------------------------"
	if test_connection()
		attachments_to_upload = CSV.read("#{$csv_path}", headers: true)
		attachments_to_upload.each do |attachment|
			attachment_arr = "#{attachment}".split(',')
			path = "#{attachment_arr[0]}".strip
			project_name = "#{attachment_arr[1]}".strip
			issue_name = "#{attachment_arr[2]}".strip
			path_arr = "#{path}".split('\\')
			if "#{path_arr[path_arr.length() - 1]}".include? "." 
				attach(project_name, issue_name, path)
			else 
					files_in_dir = Dir.entries(path)
					for file in files_in_dir do
						if "#{file}" != "." && "#{file}" != ".."
							file_path = "#{path}\\" + file
							attach(project_name, issue_name, file_path)
						end
					end
			end
		end	
		if "#{$upload_failed_count}" != "0"
			puts "----------------------------------------------------------------------------------------------------------"
			puts ""
			puts "Script completed with errors: Not all files were uploaded successfully, please check log file for more details --- #{$log_path}"
			puts ""
			puts "----------------------------------------------------------------------------------------------------------"
		else
			puts "----------------------------------------------------------------------------------------------------------"
			puts ""
			puts "                  Script completed with no errors: All files were uploaded successfully."
			puts ""
			puts "----------------------------------------------------------------------------------------------------------"
		end
	end
	$log.unknown "---------------------------------------------SCRIPT ENDED---------------------------------------------"
	$log.close()
end
def uploadCSV ( ) log_file_creation ( ) $log . unknown "---------------------------------------------SCRIPT STARTED---------------------------------------------" if test_connection ( ) attachments_to_upload = CSV . read ( "#{$csv_path}" , headers : true ) attachments_to_upload . each do | attachment | attachment_arr = "#{attachment}" . split ( ',' ) path = "#{attachment_arr[0]}" . strip project_name = "#{attachment_arr[1]}" . strip issue_name = "#{attachment_arr[2]}" . strip path_arr = "#{path}" . split ( '\\' ) if "#{path_arr[path_arr.length() - 1]}" . include? "." attach ( project_name , issue_name , path ) else files_in_dir = Dir . entries ( path ) for file in files_in_dir do if "#{file}" != "." && "#{file}" != ".." file_path = "#{path}\\" + file attach ( project_name , issue_name , file_path ) end end end end if "#{$upload_failed_count}" != "0" puts "----------------------------------------------------------------------------------------------------------" puts "" puts "Script completed with errors: Not all files were uploaded successfully, please check log file for more details --- #{$log_path}" puts "" puts "----------------------------------------------------------------------------------------------------------" else puts "----------------------------------------------------------------------------------------------------------" puts "" puts "                  Script completed with no errors: All files were uploaded successfully." puts "" puts "----------------------------------------------------------------------------------------------------------" end end $log . unknown "---------------------------------------------SCRIPT ENDED---------------------------------------------" $log . close ( ) end
Iterates over each row in CSV file to upload each attachment.
Iterates over each row in CSV file to upload each attachment .
#convert row from string to array #check if path has a filename with extention -- includes a period or not  #if it does -- need to grab that individual file and upload it. #if it doesn't -- need to iterate over all attachments in directory #begin #rescue #	puts "Directory #{path} does not exist." #	$upload_failed_count += 1 #	write_to_file("Directory #{path} does not exist", "error") #end