<commit_before>desc 'Publish a release of this project.'
task :pub => %w[ pub:gem pub:web pub:ann ]

#-----------------------------------------------------------------------------
# RubyGems
#-----------------------------------------------------------------------------

desc 'Publish gem release package to RubyGems.org.'
task 'pub:gem' do
  Rake::Task[:@project].invoke
  Rake::Task[:gem].invoke unless File.exist? @project_gem_file
  sh 'gem', 'push', @project_gem_file
end

#-----------------------------------------------------------------------------
# website
#-----------------------------------------------------------------------------

desc 'Publish help manual, API docs, and RSS feed to project website.'
task 'pub:web' => %w[ man api ann:feed ] do |t|
  Rake::Task[:@project].invoke

  if target = @project_options[:pub_web_target]
    options = @project_options[:pub_web_options]
    sources = [@man_html_dst, @api_dir, @ann_feed_dst,
      @project_options[:pub_web_extras]].compact

    sh ['rsync', options, sources, target].join(' ')
  end
end

#-----------------------------------------------------------------------------
# announcements
#-----------------------------------------------------------------------------

desc 'Announce release on all news outlets.'
task 'pub:ann' => %w[ pub:ann:raa pub:ann:ruby-talk ]

desc 'Announce release on ruby-talk mailing list.'
task 'pub:ann:ruby-talk' do
  site = 'http://ruby-forum.com'

  require 'mechanize'
  browser = Mechanize.new

  # fetch login form
  page = browser.get("#{site}/user/login")
  form = page.forms_with(:action => '/user/login').first or
    raise "cannot find login form on Web page: #{page.uri}"

  # fill login information
  require 'highline'
  highline = HighLine.new

  form['name'] = highline.ask("#{site} username: ")
  form['password'] = highline.ask("#{site} password: ") {|q| q.echo = false }

  # submit login form
  page = form.click_button
  page.at('a[href="/user/logout"]') or
    raise "invalid login for #{site}"

  # make the announcement
  page = browser.get("#{site}/topic/new?forum_id=4")
  form = page.forms_with(:action => '/topic/new#postform').first or
    raise "cannot find post creation form on Web page: #{page.uri}"

  # enable notification by email whenever
  # someone replies to this announcement
  form['post[subscribed_by_author]'] = '1'

  Rake::Task[:@ann_subject].invoke
  form['post[subject]'] = @ann_subject

  Rake::Task[@ann_text_dst].invoke
  form['post[text]'] = File.read(@ann_text_dst)

  # submit the announcement
  page = form.submit

  if error = page.at('.error')
    raise "Announcement to #{site} failed:\n#{error.text}"
  else
    puts "Successfully announced to #{site}:", page.uri
  end
end

desc 'Announce release on RAA (Ruby Application Archive).'
task 'pub:ann:raa' do
  site = 'http://raa.ruby-lang.org'

  Rake::Task[:@project].invoke
  project = @project_package_name

  require 'mechanize'
  browser = Mechanize.new

  # fetch project information form
  page = browser.get("#{site}/update.rhtml?name=#{project}")
  form = page.forms_with(:action => 'regist.rhtml').first or
    raise "cannot find project information form on Web page: #{page.uri}"

  # fill project information
  Rake::Task[:@ann_nfo_text].invoke
  form['description']       = @ann_nfo_text
  form['description_style'] = 'Plain'

  Rake::Task[:@project].invoke
  form['short_description'] = @project_module::TAGLINE<commit_msg>let user verify ANN before publishing to ruby-talk<commit_after>desc 'Publish a release of this project.'
task :pub => %w[ pub:gem pub:web pub:ann ]

#-----------------------------------------------------------------------------
# RubyGems
#-----------------------------------------------------------------------------

desc 'Publish gem release package to RubyGems.org.'
task 'pub:gem' do
  Rake::Task[:@project].invoke
  Rake::Task[:gem].invoke unless File.exist? @project_gem_file
  sh 'gem', 'push', @project_gem_file
end

#-----------------------------------------------------------------------------
# website
#-----------------------------------------------------------------------------

desc 'Publish help manual, API docs, and RSS feed to project website.'
task 'pub:web' => %w[ man api ann:feed ] do |t|
  Rake::Task[:@project].invoke

  if target = @project_options[:pub_web_target]
    options = @project_options[:pub_web_options]
    sources = [@man_html_dst, @api_dir, @ann_feed_dst,
      @project_options[:pub_web_extras]].compact

    sh ['rsync', options, sources, target].join(' ')
  end
end

#-----------------------------------------------------------------------------
# announcements
#-----------------------------------------------------------------------------

desc 'Announce release on all news outlets.'
task 'pub:ann' => %w[ pub:ann:raa pub:ann:ruby-talk ]

desc 'Announce release on ruby-talk mailing list.'
task 'pub:ann:ruby-talk' => @ann_text_dst do
  site = 'http://ruby-forum.com'

  # let user verify announcement before publishing
  ann_text = File.read(@ann_text_dst)
  puts ann_text, nil

  require 'highline'
  highline = HighLine.new

  if highline.agree "Really publish this announcement to #{site}?"
    require 'mechanize'
    browser = Mechanize.new

    # fetch login form
    page = browser.get("#{site}/user/login")
    form = page.forms_with(:action => '/user/login').first or
      raise "cannot find login form on Web page: #{page.uri}"

    # fill login information
    form['name'] = highline.ask("#{site} username: ")
    form['password'] = highline.ask("#{site} password: ") {|q| q.echo = false }

    # submit login form
    page = form.click_button
    page.at('a[href="/user/logout"]') or
      raise "invalid login for #{site}"

    # make the announcement
    page = browser.get("#{site}/topic/new?forum_id=4")
    form = page.forms_with(:action => '/topic/new#postform').first or
      raise "cannot find post creation form on Web page: #{page.uri}"

    # enable notification by email whenever
    # someone replies to this announcement
    form['post[subscribed_by_author]'] = '1'

    Rake::Task[:@ann_subject].invoke
    form['post[subject]'] = @ann_subject

    form['post[text]'] = ann_text

    # submit the announcement
    page = form.submit

    if error = page.at('.error')
      raise "Announcement to #{site} failed:\n#{error.text}"
    else
      puts "Successfully announced to #{site}:", page.uri
    end
  end
end

desc 'Announce release on RAA (Ruby Application Archive).'
task 'pub:ann:raa' do
  site = 'http://raa.ruby-lang.org'

  Rake::Task[:@project].invoke
  project = @project_package_name

  require 'mechanize'
  browser = Mechanize.new

  # fetch project information form
  page = browser.get("#{site}/update.rhtml?name=#{project}")
  form = page.forms_with(:action => 'regist.rhtml').first or
    raise "cannot find project information form on Web page: #{page.uri}"

  # fill project information
  Rake::Task[:@ann_nfo_text].invoke
  form['description']       = @ann_nfo_text
  form['description_style'] = 'Plain'

  Rake::Task[:@project].invoke
  form['short_description'] = @project_module::TAGLINE
{'fraction_non_alphanumeric': 0.2561300266218299, 'fraction_numerical': 0.0005604595768530195, 'mean_word_length': 2.337073398784479, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '4376294', 'n_tokens_mistral': 2120, 'n_tokens_neox': 2043, 'n_words': 548}