<commit_before>#!/usr/bin/env ruby
destination = ARGV.shift

require 'rubygems'
require 'json'
require_relative 'common'
require 'octokit'
require 'English'

def uri
  input['source']['uri'] || "https://github.com/#{input['source']['repo']}"
end

def ref
  input['version']['ref']
end

def remote_ref
  params['fetch_merge'] ? 'merge' : 'head'
end

$stderr.puts 'DEPRECATION: Please note that you should update to using `version: every` on your `get` for this resource.'

pr = Octokit.pull_request(input['source']['repo'], input['version']['pr'])
id = pr['number']
branch_ref = "pr-#{pr['head']['ref']}"

raise 'PR has merge conflicts' if pr['mergeable'] == false && params['fetch_merge']

system("git clone --depth 1 #{uri} #{destination} 1>&2")

raise 'git clone failed' unless $CHILD_STATUS.exitstatus.zero?

Dir.chdir(destination) do
  system('git submodule update --init --recursive 1>&2')
  raise 'git clone failed' unless system("git fetch -q origin pull/#{id}/#{remote_ref}:#{branch_ref} 1>&2")
  system("git checkout #{branch_ref} 1>&2")
  system("git config --add pullrequest.url #{pr['html_url']} 1>&2")
  system("git config --add pullrequest.id #{pr['number']} 1>&2")
  system("git config --add pullrequest.branch #{pr['head']['ref']} 1>&2")
end

puts JSON.generate(version:  { ref: ref, pr: id.to_s },
                   metadata: [{ name: 'url', value: pr['html_url'] }])<commit_msg>submodule init on the PR<commit_after>#!/usr/bin/env ruby
destination = ARGV.shift

require 'rubygems'
require 'json'
require_relative 'common'
require 'octokit'
require 'English'

def uri
  input['source']['uri'] || "https://github.com/#{input['source']['repo']}"
end

def ref
  input['version']['ref']
end

def remote_ref
  params['fetch_merge'] ? 'merge' : 'head'
end

$stderr.puts 'DEPRECATION: Please note that you should update to using `version: every` on your `get` for this resource.'

pr = Octokit.pull_request(input['source']['repo'], input['version']['pr'])
id = pr['number']
branch_ref = "pr-#{pr['head']['ref']}"

raise 'PR has merge conflicts' if pr['mergeable'] == false && params['fetch_merge']

system("git clone --depth 1 #{uri} #{destination} 1>&2")

raise 'git clone failed' unless $CHILD_STATUS.exitstatus.zero?

Dir.chdir(destination) do
  raise 'git clone failed' unless system("git fetch -q origin pull/#{id}/#{remote_ref}:#{branch_ref} 1>&2")
  system("git checkout #{branch_ref} 1>&2")
  system('git submodule update --init --recursive 1>&2')
  system("git config --add pullrequest.url #{pr['html_url']} 1>&2")
  system("git config --add pullrequest.id #{pr['number']} 1>&2")
  system("git config --add pullrequest.branch #{pr['head']['ref']} 1>&2")
end

puts JSON.generate(version:  { ref: ref, pr: id.to_s },
                   metadata: [{ name: 'url', value: pr['html_url'] }])
{'fraction_non_alphanumeric': 0.19393939393939394, 'fraction_numerical': 0.0106951871657754, 'mean_word_length': 5.167032967032967, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '5168663', 'n_tokens_mistral': 956, 'n_tokens_neox': 933, 'n_words': 262}