<commit_before>#!/usr/bin/env ruby

require 'github_api'
require 'json'
require 'colorize'
require 'benchmark'

require_relative 'github_changelog_generator/parser'
require_relative 'github_changelog_generator/generator'
require_relative 'github_changelog_generator/version'

module GitHubChangelogGenerator
  class ChangelogGenerator

    attr_accessor :options, :all_tags, :github

    PER_PAGE_NUMBER = 30

    def initialize

      @options = Parser.parse_options

      if options[:verbose]
        puts 'Input options:'
        pp options
        puts ''
      end

      github_token

      github_options = {per_page: PER_PAGE_NUMBER}
      github_options[:oauth_token] = @github_token unless @github_token.nil?
      github_options[:endpoint] = options[:github_endpoint] unless options[:github_endpoint].nil?
      github_options[:site] = options[:github_endpoint] unless options[:github_site].nil?

      @github = Github.new github_options

      @generator = Generator.new(@options)

      @all_tags = self.get_all_tags
      @pull_requests = self.get_filtered_pull_requests
      if @options[:issues]
        @issues = self.get_all_issues
        fetch_event_for_issues(@issues)
        detect_actual_closed_dates
      else
        @issues = []
      end

      @tag_times_hash = {}
    end

    def detect_actual_closed_dates
      @issues.each{|issue|
        closed_date = find_closed_date_by_commit(issue)

      }

    end

    def find_closed_date_by_commit(issue)
      puts issue[:number]
      unless issue['events'].nil?
        issue['events'].each{|event|
          puts event[:event]
        }
      end
      0
    end

    def print_json(json)
      puts JSON.pretty_generate(json)
    end

    def exec_command(cmd)
      exec_cmd = "cd #{$project_path} and #{cmd}"
      %x[#{exec_cmd}]
    end

    def get_all_closed_pull_requests
      if @options[:verbose]
        print "Fetching pull requests...\r"
      end
      response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'

      pull_requests = []
      page_i = 0<commit_msg>put in actual date right closed date<commit_after>#!/usr/bin/env ruby

require 'github_api'
require 'json'
require 'colorize'
require 'benchmark'

require_relative 'github_changelog_generator/parser'
require_relative 'github_changelog_generator/generator'
require_relative 'github_changelog_generator/version'

module GitHubChangelogGenerator
  class ChangelogGenerator

    attr_accessor :options, :all_tags, :github

    PER_PAGE_NUMBER = 30

    def initialize

      @options = Parser.parse_options

      if options[:verbose]
        puts 'Input options:'
        pp options
        puts ''
      end

      github_token

      github_options = {per_page: PER_PAGE_NUMBER}
      github_options[:oauth_token] = @github_token unless @github_token.nil?
      github_options[:endpoint] = options[:github_endpoint] unless options[:github_endpoint].nil?
      github_options[:site] = options[:github_endpoint] unless options[:github_site].nil?

      @github = Github.new github_options

      @generator = Generator.new(@options)

      @all_tags = self.get_all_tags
      @pull_requests = self.get_filtered_pull_requests
      if @options[:issues]
        @issues = self.get_all_issues
        fetch_event_for_issues(@issues)
        detect_actual_closed_dates
      else
        @issues = []
      end

      @tag_times_hash = {}
    end

    def detect_actual_closed_dates
      @issues.each{|issue|
        closed_date = find_closed_date_by_commit(issue)

      }

    end

    def find_closed_date_by_commit(issue)
      closed_date = nil
      puts issue[:number]
      unless issue['events'].nil?
        # reverse! - to find latest closed event. (event goes in date order)
        issue['events'].reverse!.each{|event|
          if event[:event].eql? 'closed'
            if event[:commit_id].nil?
              issue[:actual_date] = issue[:closed_at]
            else
              commit = @github.git_data.commits.get @options[:user], @options[:project], event[:commit_id]
              issue[:actual_date] = commit[:author][:date]
            end

            break
          end
        }
      end
      closed_date
    end

    def print_json(json)
      puts JSON.pretty_generate(json)
    end

    def exec_command(cmd)
      exec_cmd = "cd #{$project_path} and #{cmd}"
      %x[#{exec_cmd}]
    end

    def get_all_closed_pull_requests
      if @options[:verbose]
        print "Fetching pull requests...\r"
      end
      response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'

      pull_requests = []
      page_i = 0
{'fraction_non_alphanumeric': 0.09638811711904254, 'fraction_numerical': 0.0014960461637101945, 'mean_word_length': 2.832923832923833, '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': '3725426', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1386, 'n_words': 284}