<commit_before>module Flow
  module Workflow
    class PullRequest
      attr_accessor :client, :repo, :pull, :jira

      def initialize(client, repo, pull)
        @client = client
        @repo   = repo
        @pull   = pull
      end

      def has_comment_with?(patterns)
        patterns.each do |pattern|
          return true if comments.any? { |s| s.body.include?(pattern) }
        end
        false
      end

      def blocked?
        has_comment_with?(dictionary['blocked'])
      end

      def reviewed?
        has_comment_with?(dictionary['reviewed'])
      end

      def uat?
        has_comment_with?(dictionary['uat_ok'])
      end

      def uat_ko?
        has_comment_with?(dictionary['uat_ko'])
      end

      def green?
        client.statuses(repo.name, pull.head.attrs[:sha]).each do |state|
          return true if state.attrs[:state] == 'success'
        end
        false
      end

      def status
        @__status__ ||= begin
          return :blocked       if blocked?
          return :failed        if !green?
          return :not_reviewed  if !reviewed?
          return :uat_ko        if uat_ko?
          return :not_uat       if !uat?
          :success
        end
      end

      def comments
        @__comments__ ||= []
        @__comments__[pull.id] ||= pull.rels[:comments].get.data
      end

      def merge
        message = "#{original_branch} #UAT-OK - PR #{number} merged"
        response = client.merge_pull_request(repo.name, pull.number, message)
        response['merged']
      end

      def delete_original_branch
        client.delete_ref(repo.name, "heads/#{original_branch}") unless original_branch.include? 'master'
      end

      def original_branch
        @__original_branch__ ||= pull.head[:label].split(':')[1]
      end

      def number
        pull.number
      end

      def jira_id
        original_branch.match('([a-zA-Z]{2,3})-([0-9]{1,})')
      end

      def save_comments_to_be_discussed
        comments.each do |comment|
          issue! 'To Discuss', comment.body if comment.body.include? ':exclamation:'
        end
      end

      def ship_it!<commit_msg>Fix can't merge response from github'<commit_after>module Flow
  module Workflow
    class PullRequest
      attr_accessor :client, :repo, :pull, :jira

      def initialize(client, repo, pull)
        @client = client
        @repo   = repo
        @pull   = pull
      end

      def has_comment_with?(patterns)
        patterns.each do |pattern|
          return true if comments.any? { |s| s.body.include?(pattern) }
        end
        false
      end

      def blocked?
        has_comment_with?(dictionary['blocked'])
      end

      def reviewed?
        has_comment_with?(dictionary['reviewed'])
      end

      def uat?
        has_comment_with?(dictionary['uat_ok'])
      end

      def uat_ko?
        has_comment_with?(dictionary['uat_ko'])
      end

      def green?
        client.statuses(repo.name, pull.head.attrs[:sha]).each do |state|
          return true if state.attrs[:state] == 'success'
        end
        false
      end

      def status
        @__status__ ||= begin
          return :blocked       if blocked?
          return :failed        if !green?
          return :not_reviewed  if !reviewed?
          return :uat_ko        if uat_ko?
          return :not_uat       if !uat?
          :success
        end
      end

      def comments
        @__comments__ ||= []
        @__comments__[pull.id] ||= pull.rels[:comments].get.data
      end

      def merge
        message = "#{original_branch} #UAT-OK - PR #{number} merged"
        begin
          response = client.merge_pull_request(repo.name, pull.number, message)
          response['merged']
        rescue
          false
        end
      end

      def delete_original_branch
        client.delete_ref(repo.name, "heads/#{original_branch}") unless original_branch.include? 'master'
      end

      def original_branch
        @__original_branch__ ||= pull.head[:label].split(':')[1]
      end

      def number
        pull.number
      end

      def jira_id
        original_branch.match('([a-zA-Z]{2,3})-([0-9]{1,})')
      end

      def save_comments_to_be_discussed
        comments.each do |comment|
          issue! 'To Discuss', comment.body if comment.body.include? ':exclamation:'
        end
      end

      def ship_it!
{'fraction_non_alphanumeric': 0.10202687314962423, 'fraction_numerical': 0.002732862673650649, 'mean_word_length': 1.8705882352941177, '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': '5910411', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1294, 'n_words': 308}