Class: Trackinator::YouTrack
- Inherits:
-
Object
- Object
- Trackinator::YouTrack
- Defined in:
- lib/trackinator/you_track.rb
Instance Method Summary collapse
- #create_ticket(data) ⇒ Object
-
#initialize(opts) ⇒ YouTrack
constructor
A new instance of YouTrack.
- #is_issue_exists?(data) ⇒ Boolean
- #is_logged_in? ⇒ Boolean
- #login(username, password) ⇒ Object
- #project_exists?(project) ⇒ Boolean
-
#required_you_track_fields_defined?(project) ⇒ Boolean
Here’s a potential approach for validating that YouTrack fields are present.
- #update_ticket(issue_id, data) ⇒ Object
Constructor Details
#initialize(opts) ⇒ YouTrack
Returns a new instance of YouTrack.
6 7 8 9 10 11 12 |
# File 'lib/trackinator/you_track.rb', line 6 def initialize opts @stack = [] @host = opts[:host] @port = opts[:port] @path_prefix = opts[:path_prefix] end |
Instance Method Details
#create_ticket(data) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/trackinator/you_track.rb', line 26 def create_ticket data issue_id, create_response = create_youtrack_ticket data success = create_response.eql? "Created" success ? (success = update_ticket(issue_id, data)) : (return success) success ? update_dependencies([issue_id, data['id']]) : success end |
#is_issue_exists?(data) ⇒ Boolean
90 91 92 93 |
# File 'lib/trackinator/you_track.rb', line 90 def is_issue_exists? data find_response_xml = REXML::Document.new(@connection.get("#{@path_prefix}rest/issue/byproject/#{data['project']}?filter=Import+Identifier:+#{data['project']}-#{data['id']}+Subsystem:+#{data['subsystem']}", { 'Cookie' => @cookie, 'Content-Type' => 'text/plain; charset=utf-8' }).body) find_response_xml.elements['issues'].length > 0 ? find_response_xml.elements['issues/issue'].attributes['id'] : nil end |
#is_logged_in? ⇒ Boolean
14 15 16 |
# File 'lib/trackinator/you_track.rb', line 14 def is_logged_in? !@cookie.nil? end |
#login(username, password) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/trackinator/you_track.rb', line 18 def login username, password @connection = Net::HTTP.new @host, @port response = @connection.post "#{@path_prefix}rest/user/login", "login=#{username}&password=#{password}" if response.header.msg.eql? "OK" @cookie = response.response['Set-Cookie'].split('; ')[0] end end |
#project_exists?(project) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/trackinator/you_track.rb', line 44 def project_exists?(project) issues = [] response = @connection.get("#{@path_prefix}rest/admin/project/#{project}", { 'Cookie' => @cookie, 'Content-Type' => 'text/plain; charset=utf-8' }) if response.header.msg.eql?("Not Found") issues << "Project Error: Project doesn't exist!" end issues end |
#required_you_track_fields_defined?(project) ⇒ Boolean
Here’s a potential approach for validating that YouTrack fields are present
get YouTrack fields from server augment YouTrack fields where necessary (import identifier?) copy YouTrack fields and normalize copy (remove spaces, downcase) create map of YouTrack fields to nYouTrack fields get Google fields from doc normalize Google fields (remove spaces, downcase) subtract nGoogle from nYouTrack (leaving only missing YouTrack fields) subtract nYouTrack from nGoogle (leaving only missing Google fields) warn on missing nGoogle fail validation on nYouTrack using map to get actual field names for display … or, just hard code the fucking thing and be done with it
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/trackinator/you_track.rb', line 70 def required_you_track_fields_defined?(project) you_track_fields = [] issues = [] response = @connection.get("#{@path_prefix}rest/admin/project/#{project}/customfield", { 'Cookie' => @cookie, 'Content-Type' => 'text/plain; charset=utf-8' }) response_xml = REXML::Document.new(response.body) response_xml.elements.each('projectCustomFieldRefs/projectCustomField') do |element| you_track_fields << element.attributes["name"] end YOU_TRACK_REQUIRED.each do |required_field| unless you_track_fields.include?(required_field) issues << "Validation Error: Required field '#{required_field}' not found in YouTrack project" end end issues end |
#update_ticket(issue_id, data) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/trackinator/you_track.rb', line 34 def update_ticket issue_id, data success = set_subsystem(issue_id, data['subsystem']) success ? (success = set_summary_and_description(issue_id, data['summary'], data['description'], data['outcome'])) : (return success) success ? (success = set_type(issue_id, data['type'])) : (return success) success ? (success = set_import_identifier(issue_id, "#{data['project']}-#{data['id']}")) : (return success) success ? (success = set_design_reference(issue_id, "#{data['designreference']}")) : (return success) unless data['designreference'].nil? success end |