<commit_before>require "activemodel-url_validator"
require "securerandom"

require "qiita/team/services/hooks/base"

module Qiita::Team::Services
  module Hooks
    class Webhook < Base
      include Concerns::HttpClient

      define_property :url
      define_property :token

      validates :token, format: %r{\A[A-Za-z0-9+/=]{20,40}\z}
      validates :url, presence: true,
                      url: { scheme: ['http', 'https'],
                             message: :invalid_scheme,
                             allow_blank: true }

      # @note Override {Qiita::Team::Services::Hooks::Base.service_name}.
      def self.service_name
        "Webhook"
      end

      # @return [String]
      def self.generate_token
        SecureRandom.base64(20)
      end

      # @param hash [Hash{String => Object}]
      def initialize(hash)
        unless hash.key?("token")
          hash = hash.dup.merge("token" => self.class.generate_token)
        end
        super(hash)
      end

      def ping
        send_hook(
          action: "requested",
          message: "ping",
          model: "ping",
        )
      end

      # @param event [Qiita::Team::Services::Events::ItemCreated]
      def item_created(event)<commit_msg>Fix lint errors of `lib/qiita/team/services/hook/webhook.rb`<commit_after>require "activemodel-url_validator"
require "securerandom"

require "qiita/team/services/hooks/base"

module Qiita::Team::Services
  module Hooks
    class Webhook < Base
      include Concerns::HttpClient

      define_property :url
      define_property :token

      validates :token, format: %r{\A[A-Za-z0-9+/=]{20,40}\z}
      validates :url, presence: true,
                      url: { scheme: %w(http https),
                             message: :invalid_scheme,
                             allow_blank: true }

      # @note Override {Qiita::Team::Services::Hooks::Base.service_name}.
      def self.service_name
        "Webhook"
      end

      # @return [String]
      def self.generate_token
        SecureRandom.base64(20)
      end

      # @param hash [Hash{String => Object}]
      def initialize(hash)
        unless hash.key?("token")
          hash = hash.dup.merge("token" => self.class.generate_token)
        end
        super(hash)
      end

      def ping
        send_hook(
          action: "requested",
          message: "ping",
          model: "ping",
        )
      end

      # @param event [Qiita::Team::Services::Events::ItemCreated]
      def item_created(event)
{'fraction_non_alphanumeric': 0.11633466135458168, 'fraction_numerical': 0.00796812749003984, 'mean_word_length': 2.0436363636363635, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5382595', 'n_tokens_mistral': 779, 'n_tokens_neox': 738, 'n_words': 157}