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

require "net/https"
require 'rubygems'
require 'json'

unless ARGV[2] && ARGV[3]
  puts 'You need to supply TOKEN (api-key) as third argument and user key as fourth argument'
  exit
end

TOKEN = ARGV[2]
USER  = ARGV[3]
MAX_URL = 512
MAX_URL_TITLE = 100
MAX_TITLE = 250
MAX_BODY = 1024
ELLIPSIS = '…'

def truncate s, length = MAX_URL_TITLE, ellipsis = ELLIPSIS
  if s.length > length
    s.to_s[0..length-ellipsis.bytesize].gsub(/[^\w]\w+\s*$/, ellipsis)
  else
    s
  end
end

def parse_issue(payload)
  issue = payload['issue']
  title = "#{issue['user']['login']} #{payload['action']} issue '#{issue['title']}'"
  labels = " (#{issue['labels'].join ', '})" if issue['labels'].any?
  message = "#{payload['repository']['full_name']} issue ##{issue['number']}#{labels}:\n#{issue['body']}"
  url = issue['html_url']
  url_title = 'View issue on GitHub'
  {url: url, title: title, message: message, url_title: url_title}<commit_msg>Refactored parsing of issues<commit_after>#!/usr/bin/env ruby
#

require "net/https"
require 'rubygems'
require 'json'

unless ARGV[2] && ARGV[3]
  puts 'You need to supply TOKEN (api-key) as third argument and user key as fourth argument'
  exit
end

TOKEN = ARGV[2]
USER  = ARGV[3]
MAX_URL = 512
MAX_URL_TITLE = 100
MAX_TITLE = 250
MAX_BODY = 1024
ELLIPSIS = '…'

def truncate s, length = MAX_URL_TITLE, ellipsis = ELLIPSIS
  if s.length > length
    s.to_s[0..length-ellipsis.bytesize].gsub(/[^\w]\w+\s*$/, ellipsis)
  else
    s
  end
end

def parse_issue(payload)
  issue = payload['issue']
  action = payload['action']
  ignore = ['unassigned', 'labeled', 'unlabeled']
  if ignore.include? action
    puts "Issue parsing: ignoring action '#{action}'"
    exit
  end

  repo = payload['repository']['full_name']
  issue_num = issue['number']
  issuee = issue['user']['login']
  issue_title = issue['title']

  case action
  when "assigned"
    assignee = payload['assignee']['login']
    message = "#{assignee} were assigned to '#{issue_title}'"
  else
    message = issue_title
  end

  title = "#{issuee} #{action} issue #{repo}##{issue_num}"
  url = issue['html_url']
  url_title = 'View issue on GitHub'
  {url: url, title: title, message: message, url_title: url_title}
{'fraction_non_alphanumeric': 0.16229435304579815, 'fraction_numerical': 0.01600711427301023, 'mean_word_length': 4.357142857142857, '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': '306419', 'n_tokens_mistral': 882, 'n_tokens_neox': 826, 'n_words': 217}