<commit_before>require 'jira_tracker/version'
require 'yaml'
require 'pp'
require 'jira'

module JiraTracker

  @config = nil

  def self.run(issue, time_spent)
    begin
      @config = YAML.load_file "#{Dir.home}/.jira_tracker.yml"
    rescue
      p 'Setting file jira_tracker.yml not found!'
      exit
    end

    options = @config.merge({
      context_path:   '',
      rest_base_path: '/rest/api/2',
      auth_type:      :basic
    })

    client = JIRA::Client.new(options)
    JiraTracker.worklog(issue, time_spent, client)
  end

  def self.worklog(issue, time_spent, client)
    jira_issue = JiraTracker.find do
      if issue.include?('-')
        client.Issue.find(issue)
      else
        project_name = JiraTracker.get_project_name_from_issue(issue)
        jql = "project = #{project_name} AND summary ~ \"#{@config['time_track_issue_summary']}\""
        client.Issue.jql(jql).first
      end
    end

    worklog = jira_issue.worklogs.build

    worklog.save({'timeSpent' => time_spent})
    p "Thanks! #{time_spent} was added to #{jira_issue.key} - #{jira_issue.summary}"

    unless worklog.issue.timespent.nil?
      time_spent_till_now = worklog.issue.timespent / 3600
      p "Time spent on this issue before #{time_spent_till_now}h"
    end
  end

  def self.find
    begin
      return yield
    rescue JIRA::HTTPError => e
      p e.response
      exit
    end
  end

  def self.get_project_name_from_issue(issue)
    issue.split('-').first.upcase
  end

end
<commit_msg>Jira client expects hash keys as symbols<commit_after>require 'jira_tracker/version'
require 'yaml'
require 'pp'
require 'jira'

module JiraTracker

  @config = nil

  def self.run(issue, time_spent)
    begin
      @config = YAML.load_file "#{Dir.home}/.jira_tracker.yml"
    rescue
      p 'Setting file jira_tracker.yml not found!'
      exit
    end

    options = {
      :username       => @config['username'],
      :password       => @config['password'],
      :site           => @config['site'],
      :context_path   => '',
      :rest_base_path => '/rest/api/2',
      :auth_type      => :basic
    }

    client = JIRA::Client.new(options)
    JiraTracker.worklog(issue, time_spent, client)
  end

  def self.worklog(issue, time_spent, client)
    jira_issue = JiraTracker.find do
      if issue.include?('-')
        client.Issue.find(issue)
      else
        project_name = JiraTracker.get_project_name_from_issue(issue)
        jql = "project = #{project_name} AND summary ~ \"#{@config['time_track_issue_summary']}\""
        client.Issue.jql(jql).first
      end
    end

    worklog = jira_issue.worklogs.build

    worklog.save({'timeSpent' => time_spent})
    p "Thanks! #{time_spent} was added to #{jira_issue.key} - #{jira_issue.summary}"

    unless worklog.issue.timespent.nil?
      time_spent_till_now = worklog.issue.timespent / 3600
      p "Time spent on this issue before #{time_spent_till_now}h"
    end
  end

  def self.find
    begin
      return yield
    rescue JIRA::HTTPError => e
      p e.response
      exit
    end
  end

  def self.get_project_name_from_issue(issue)
    issue.split('-').first.upcase
  end

end

{'fraction_non_alphanumeric': 0.1162496040544821, 'fraction_numerical': 0.0031675641431738993, 'mean_word_length': 2.724056603773585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1635433', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1092, 'n_words': 227}