<commit_before>module Prpr
  module Action
    module Lgtm
      class Comment < Prpr::Action::Base
        def call
          if count == 1
            add_label label(:one)
          elsif count >= 2
            unless already_labeled?(label(:over_2))
              remove_label label(:one)
              add_label label(:over_2)
              add_comment
            end
          end
        end

        private

        def count
          comments.map(&method(:point)).reduce(:+)
        end

        def point(comment)
          case comment[:body]
          when /lgtm/i, /:+1:/
            1
          when /:-1:/
            -1
          else
            0
          end
        end

        def comments
          @comments ||= github.issue_comments(repository, issue_number)
        end

        def add_comment
          github.add_comment(repository, issue_number, message)
        end

        def message
          env.format(:lgtm_body, event.issue.assignee)
        end

        def add_label(label)
          github.add_labels_to_an_issue(repository, issue_number, [label])
        end

        def remove_label(label)
          github.remove_label(repository, issue_number, label)
        end

        def already_labeled?(label)
          labels.map(&:name).any? { |name| name == label }
        end

        def labels
          github.labels_for_issue(repository, issue_number)
        end

        def label(name)
          Config::Env.default[:"lgtm_label_#{name}"] || name.to_s
        end

        def name
          env[:mention_comment_members] || 'MEMBERS.md'
        end

        def repository
          event.repository.full_name
        end

        def issue_number
          event.issue.number
        end

        def github
          Repository::Github.default
        end
      end
    end
  end
end
<commit_msg>fix add/remove label method<commit_after>module Prpr
  module Action
    module Lgtm
      class Comment < Prpr::Action::Base
        def call
          if count == 1
            add_label label(:one)
          elsif count >= 2
            unless already_labeled?(label(:over_2))
              remove_label label(:one)
              add_label label(:over_2)
              add_comment
            end
          end
        end

        private

        def count
          comments.map(&method(:point)).reduce(:+)
        end

        def point(comment)
          case comment[:body]
          when /lgtm/i, /:+1:/
            1
          when /:-1:/
            -1
          else
            0
          end
        end

        def comments
          @comments ||= github.issue_comments(repository, issue_number)
        end

        def add_comment
          github.add_comment(repository, issue_number, message)
        end

        def message
          env.format(:lgtm_body, event.issue.assignee)
        end

        def add_label(label)
          return if already_labeled?(label)
          github.add_labels_to_an_issue(repository, issue_number, [label])
        end

        def remove_label(label)
          return unless already_labeled?(label)
          github.remove_label(repository, issue_number, label)
        end

        def already_labeled?(label)
          labels.map(&:name).any? { |name| name == label }
        end

        def labels
          github.labels_for_issue(repository, issue_number)
        end

        def label(name)
          Config::Env.default[:"lgtm_label_#{name}"] || name.to_s
        end

        def name
          env[:mention_comment_members] || 'MEMBERS.md'
        end

        def repository
          event.repository.full_name
        end

        def issue_number
          event.issue.number
        end

        def github
          Repository::Github.default
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.07795275590551182, 'fraction_numerical': 0.004724409448818898, 'mean_word_length': 1.4445157152020527, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7126441', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1025, 'n_words': 241}