<commit_before>module CodeclimateCi
  class GetGpa
    RETRY_COUNT = ENV['RETRY_COUNT'] || 3
    SLEEP_TIME = ENV['SLEEP_TIME'] || 5

    def initialize(codeclimate_api, branch)
      @codeclimate_api, @branch = codeclimate_api, branch
    end

    def gpa
      retrieve_branch_info
    end

    private

    def retrieve_branch_info
      RETRY_COUNT.times do
        if analyzed?
          return last_snapshot_gpa
        else
          Messages.result_not_ready
          sleep(SLEEP_TIME)
        end
      end
    end

    def last_snapshot_gpa
      branch_info['last_snapshot']['gpa'].to_f
    end

    def analyzed?
      branch_info.include?('last_snapshot')
    end

    def branch_info
      @branch_info ||= @codeclimate_api.branch_info(@branch)
    end
  end
end<commit_msg>Add refresh method in GetGpa<commit_after>module CodeclimateCi
  class GetGpa
    RETRY_COUNT = ENV['RETRY_COUNT'] || 3
    SLEEP_TIME = ENV['SLEEP_TIME'] || 5

    def initialize(codeclimate_api, branch)
      @codeclimate_api, @branch = codeclimate_api, branch
    end

    def gpa
      retrieve_branch_info
    end

    private

    def retrieve_branch_info
      RETRY_COUNT.times do
        if analyzed?
          return last_snapshot_gpa
        else
          Messages.result_not_ready
          refresh!
          sleep(SLEEP_TIME)
        end
      end
    end

    def last_snapshot_gpa
      branch_info['last_snapshot']['gpa'].to_f
    end

    def analyzed?
      branch_info.include?('last_snapshot')
    end

    def branch_info
      @branch_info ||= @codeclimate_api.branch_info(@branch)
    end

    def refresh!
      @branch_info = nil
    end
  end
end
{'fraction_non_alphanumeric': 0.06855081178592905, 'fraction_numerical': 0.0024052916416115455, 'mean_word_length': 2.3616161616161615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '493600', 'n_tokens_mistral': 558, 'n_tokens_neox': 544, 'n_words': 113}