<commit_before>require './lib/v1defect'
require 'httparty'
require 'nokogiri'
require 'sanitize'
require 'json'

require 'awesome_print'

class V1Jira 
  include HTTParty
#  debug_output $stdout

  $JIRA = YAML::load(File.open("config/jiraconfig.yml"))
  basic_auth $JIRA['username'], $JIRA['password']
  base_uri $JIRA['base_uri'] 

  def initialize(defect)
    @DEFAULT = YAML::load(File.open("default/jira.yml"))
    @customFieldMap = getAllFieldsMap
    @defect = defect
  end

  def getAllFieldsMap
    @customFieldMap = self.class.get("/rest/api/2/field")
  end

  def jiraAPIMapping
    mapping = Hash.new
    mp = @customFieldMap
    for i in 0..mp.size-1 do
      mapping[mp[i]['name']] = mp[i]['id']
    end

    return mapping
  end

  def create_ticket
    jiraPair = @defect.getJiraList

    mapping = jiraAPIMapping
    payload = {
        :fields =>
            {:project =>
                 {:key => "#{@DEFAULT['project']}"},
             :summary => jiraPair['Summary'] + " (#{@defect.get_story})",
             :description => Sanitize.clean(jiraPair['Description']),
             :customfield_10143 => [
                 {
                     :value => jiraPair['Environment'],
                 }
             ],
             :issuetype => {:name => jiraPair['issuetype']},
             mapping['Functional Group'] => {:value => jiraPair['Functional Group']},
             mapping['Project Manager'] => {:value => jiraPair['Project Manager']},
             :versions => [
                 {
                     :name => "#{jiraPair['Release']}",<commit_msg>- Correctly maps all needed fields, - Includes the use of sanatize gem - dynamically fets from V1 all fields<commit_after>require './lib/v1defect'
require 'httparty'
require 'nokogiri'
require 'sanitize'
require 'json'

require 'awesome_print'

class V1Jira 
  include HTTParty
#  debug_output $stdout

  $JIRA = YAML::load(File.open("config/jiraconfig.yml"))
  basic_auth $JIRA['username'], $JIRA['password']
  base_uri $JIRA['base_uri'] 

  def initialize(defect)
    @customFieldMap = getAllFieldsMap
    @defect = defect
  end

  def getAllFieldsMap
    @customFieldMap = self.class.get("/rest/api/2/field")
  end

  def jiraAPIMapping
    mapping = Hash.new
    mp = @customFieldMap
    for i in 0..mp.size-1 do
      mapping[mp[i]['name']] = mp[i]['id']
    end

    return mapping
  end

  def create_ticket
    jiraPair = @defect.getJiraList
    mapping = jiraAPIMapping
    payload = {
        :fields =>
            {:project =>
                 {:key => "#{jiraPair['Project']}"},
             :summary => jiraPair['Summary'] + " (#{@defect.get_story})",
             :description => Sanitize.clean(jiraPair['Description']),
             mapping['Release Milestone'] => {:value => jiraPair['Release Milestone']},
             :customfield_10143 => [
                 {
                     :value => jiraPair['Environment'],
                 }
             ],
             :issuetype => {:name => jiraPair['issuetype']},
             mapping['Functional Group'] => {:value => jiraPair['Functional Group']},
             mapping['Project Manager'] => {:value => jiraPair['Project Manager']},
             :versions => [
                 {
                     :name => "#{jiraPair['Release']}",
{'fraction_non_alphanumeric': 0.14803533353639964, 'fraction_numerical': 0.006396588486140725, 'mean_word_length': 2.371663244353183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '709581', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1006, 'n_words': 201}