<commit_before>require 'json'
require 'launchy'
require 'octokit'

class GitReview

  REVIEW_CACHE_FILE = '.git/review_cache.json'

  ## COMMANDS ##

  # Default command to show a quick reference of available commands.
  def help
    puts 'Usage: git review <command>'
    puts 'Manage review workflow for projects hosted on GitHub (using pull requests).'
    puts ''
    puts 'Available commands:'
    puts '   list [--reverse]          List all open requests.'
    puts '   show <number> [--full]    Show details of a single request.'
    puts '   browse <number>           Open a browser window and review a specified request.'
    # puts '   checkout <number>         Checkout a specified request\'s changes to your local repository.'
    puts '   accept <number>           Accept a specified request by merging it into master.'
    puts '   decline <number>          Decline and close a specified request.'
    puts '   create                    Create a new request.'
  end

  # List all open requests.
  def list
    puts "Open requests for '#{source_repo}/#{source_branch}'"
    option = @args.shift
    open_requests = get_pull_info
    open_requests.reverse! if option == '--reverse'
    # TODO: Refactor to get rid of unnecessary variables and computation.
    count = 0
    puts 'ID     Date       Comments   Title'
    open_requests.each do |pull|
      line = []
      line << format_text(pull['number'], 6)
      line << format_text(Date.parse(pull['created_at']).strftime('%d-%b-%y'), 10)
      line << format_text(pull['comments'], 10)
      line << format_text(pull['title'], 94)
      sha = pull['head']['sha']
      if not_merged?(sha)
        puts line.join ' '
        count += 1
      end
    end
    if count == 0
      puts ' -- No open requests. --'
    end
  end

  # Show details of a single request.
  def show
    return unless review_exists?
    option = @args.shift
    puts "Number   : #{@review['number']}"
    puts "Label    : #{@review['head']['label']}"
    puts "Created  : #{@review['created_at']}"
    puts "Votes    : #{@review['votes']}"
    puts "Comments : #{@review['comments']}"
    puts
    puts "Title    : #{@review['title']}"
    puts "Body     :"
    puts
    puts @review['body']<commit_msg>Refactor 'list' to get rid of unnecessary variables and computation.<commit_after>require 'json'
require 'launchy'
require 'octokit'

class GitReview

  REVIEW_CACHE_FILE = '.git/review_cache.json'

  ## COMMANDS ##

  # Default command to show a quick reference of available commands.
  def help
    puts 'Usage: git review <command>'
    puts 'Manage review workflow for projects hosted on GitHub (using pull requests).'
    puts ''
    puts 'Available commands:'
    puts '   list [--reverse]          List all open requests.'
    puts '   show <number> [--full]    Show details of a single request.'
    puts '   browse <number>           Open a browser window and review a specified request.'
    # puts '   checkout <number>         Checkout a specified request\'s changes to your local repository.'
    puts '   accept <number>           Accept a specified request by merging it into master.'
    puts '   decline <number>          Decline and close a specified request.'
    puts '   create                    Create a new request.'
  end

  # List all open requests.
  def list
    open_requests = get_pull_info
    if open_requests.size == 0
      puts "No open requests for '#{source_repo}/#{source_branch}'"
      return
    end
    puts "Open requests for '#{source_repo}/#{source_branch}'"
    puts 'ID     Date       Comments   Title'
    open_requests.reverse! if @args.shift == '--reverse'
    open_requests.each do |pull|
      next unless not_merged?(pull['head']['sha'])
      line = []
      line << format_text(pull['number'], 6)
      line << format_text(Date.parse(pull['created_at']).strftime('%d-%b-%y'), 10)
      line << format_text(pull['comments'], 10)
      line << format_text(pull['title'], 94)
      puts line.join ' '
    end
  end

  # Show details of a single request.
  def show
    return unless review_exists?
    option = @args.shift
    puts "Number   : #{@review['number']}"
    puts "Label    : #{@review['head']['label']}"
    puts "Created  : #{@review['created_at']}"
    puts "Votes    : #{@review['votes']}"
    puts "Comments : #{@review['comments']}"
    puts
    puts "Title    : #{@review['title']}"
    puts "Body     :"
    puts
    puts @review['body']
{'fraction_non_alphanumeric': 0.12311840035946978, 'fraction_numerical': 0.004044035048303752, 'mean_word_length': 2.5961227786752827, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 15, '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': '2593959', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1318, 'n_words': 435}