<commit_before>module DiscourseChat
  module Provider
    module HipchatProvider
      PROVIDER_NAME = "hipchat".freeze
      PROVIDER_ENABLED_SETTING = :chat_integration_hipchat_enabled
      CHANNEL_PARAMETERS = [
                        { key: "name", regex: '^\S+' },
                        { key: "webhook_url", regex: 'hipchat\.com', unique: true, hidden: true },
                        { key: "color", regex: '^(yellow|green|red|purple|gray|random)$' }
                       ]

      def self.send_message(url, message)
        uri = URI(url)

        http = Net::HTTP.new(uri.host, uri.port)
        http.use_ssl = true

        req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
        req.body = message.to_json
        response = http.request(req)

        return response
      end

      def self.generate_hipchat_message(post)

        display_name = "@#{post.user.username}"
        full_name = post.user.name || ""

        if !(full_name.strip.empty?) && (full_name.strip.gsub(' ', '_').casecmp(post.user.username) != 0) && (full_name.strip.gsub(' ', '').casecmp(post.user.username) != 0)
          display_name = "#{full_name} @#{post.user.username}"
        end
<commit_msg>Fix HipChat WebHook URL validation.<commit_after>module DiscourseChat
  module Provider
    module HipchatProvider
      PROVIDER_NAME = "hipchat".freeze
      PROVIDER_ENABLED_SETTING = :chat_integration_hipchat_enabled
      CHANNEL_PARAMETERS = [
                        { key: "name", regex: '^\S+' },
                        { key: "webhook_url", regex: 'hipchat\.', unique: true, hidden: true },
                        { key: "color", regex: '^(yellow|green|red|purple|gray|random)$' }
                       ]

      def self.send_message(url, message)
        uri = URI(url)

        http = Net::HTTP.new(uri.host, uri.port)
        http.use_ssl = true

        req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
        req.body = message.to_json
        response = http.request(req)

        return response
      end

      def self.generate_hipchat_message(post)

        display_name = "@#{post.user.username}"
        full_name = post.user.name || ""

        if !(full_name.strip.empty?) && (full_name.strip.gsub(' ', '_').casecmp(post.user.username) != 0) && (full_name.strip.gsub(' ', '').casecmp(post.user.username) != 0)
          display_name = "#{full_name} @#{post.user.username}"
        end

{'fraction_non_alphanumeric': 0.14577378521845652, 'fraction_numerical': 0.0016333197223356473, 'mean_word_length': 2.2754010695187166, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1083290', 'n_tokens_mistral': 774, 'n_tokens_neox': 751, 'n_words': 136}