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

require 'octokit'
require 'open-uri'
require_relative 'release-notes-creator'
require_relative '../../lib/git-client'


previous_version = File.read('previous-stacks-release/version').strip
new_version = File.read('version/number').strip

if ENV['STACK'] == 'stacks'
  old_receipt_uri = "https://raw.githubusercontent.com/cloudfoundry/stacks/#{previous_version}/cflinuxfs2/cflinuxfs2_receipt"
  cve_yaml_file = 'new-cves/new-cve-notifications/ubuntu14.04.yml'
elsif ENV['STACK'] == 'stacks-nc'
  Octokit.configure do |c|
    c.login    = ENV.fetch('GITHUB_USERNAME')
    c.password = <PASSWORD>.fetch('<PASSWORD>')
  end

  old_receipt_uri = Octokit.contents('pivotal-cf/stacks-nc', :path => 'cflinuxfs2/cflinuxfs2_receipt', :ref => previous_version)[:download_url]
  cve_yaml_file = 'new-cves/new-cves-stacks-nc/ubuntu14.04.yml'
else
  raise "Unsupported stack: #{ENV['STACK']}"
end

new_receipt_file = 'stacks/cflinuxfs2/cflinuxfs2_receipt'
old_receipt_file = open(old_receipt_uri)

body_file = 'release-body/body'
notes = ReleaseNotesCreator.new(cve_yaml_file, old_receipt_file, new_receipt_file).release_notes
puts notes
File.write(body_file, notes)

cves = YAML.load_file(cve_yaml_file)

updated_cves = cves.map do |cve|
  if cve['stack_release'] == 'unreleased'
    cve['stack_release'] = new_version
  end
  cve
end

File.write(cve_yaml_file, updated_cves.to_yaml)

Dir.chdir('new-cves') do
  GitClient.add_file('ubuntu14.04.yml')
  commit_message = "Updating CVEs for #{ENV['STACK']} release #{new_version}\n\n[ci skip]"
  GitClient.safe_commit(commit_message)
end

system "rsync -a new-cves/ new-cves-artifacts"<commit_msg>Specify which directory in robots repo cves are in<commit_after>#!/usr/bin/env ruby

require 'octokit'
require 'open-uri'
require_relative 'release-notes-creator'
require_relative '../../lib/git-client'


previous_version = File.read('previous-stacks-release/version').strip
new_version = File.read('version/number').strip

if ENV['STACK'] == 'stacks'
  old_receipt_uri = "https://raw.githubusercontent.com/cloudfoundry/stacks/#{previous_version}/cflinuxfs2/cflinuxfs2_receipt"
  cve_yaml_file = 'new-cves/new-cve-notifications/ubuntu14.04.yml'
  cves_dir = 'new-cve-notifications'
elsif ENV['STACK'] == 'stacks-nc'
  Octokit.configure do |c|
    c.login    = ENV.fetch('GITHUB_USERNAME')
    c.password = <PASSWORD>('<PASSWORD>')
  end

  old_receipt_uri = Octokit.contents('pivotal-cf/stacks-nc', :path => 'cflinuxfs2/cflinuxfs2_receipt', :ref => previous_version)[:download_url]
  cve_yaml_file = 'new-cves/new-cves-stacks-nc/ubuntu14.04.yml'
  cves_dir = 'new-cves-stacks-nc'
else
  raise "Unsupported stack: #{ENV['STACK']}"
end

new_receipt_file = 'stacks/cflinuxfs2/cflinuxfs2_receipt'
old_receipt_file = open(old_receipt_uri)

body_file = 'release-body/body'
notes = ReleaseNotesCreator.new(cve_yaml_file, old_receipt_file, new_receipt_file).release_notes
puts notes
File.write(body_file, notes)

cves = YAML.load_file(cve_yaml_file)

updated_cves = cves.map do |cve|
  if cve['stack_release'] == 'unreleased'
    cve['stack_release'] = new_version
  end
  cve
end

File.write(cve_yaml_file, updated_cves.to_yaml)


robots_cve_dir = File.join('new-cves', cves_dir)
Dir.chdir(robots_cve_dir) do
  GitClient.add_file('ubuntu14.04.yml')
  commit_message = "Updating CVEs for #{ENV['STACK']} release #{new_version}\n\n[ci skip]"
  GitClient.safe_commit(commit_message)
end

system "rsync -a new-cves/ new-cves-artifacts"
{'fraction_non_alphanumeric': 0.14347079037800686, 'fraction_numerical': 0.010309278350515464, 'mean_word_length': 5.653333333333333, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '358548', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1375, 'n_words': 202}