documentation updates for Rubyforge death
[rainbows.git] / Rakefile
blob58de7fb5f607802276bc032d52b2b70f7de5368f
1 # -*- encoding: binary -*-
2 autoload :Gem, 'rubygems'
3 autoload :Tempfile, 'tempfile'
4 require 'wrongdoc'
6 cgit_url = Wrongdoc.config[:cgit_url]
7 git_url = Wrongdoc.config[:git_url]
9 desc "read news article from STDIN and post to rubyforge"
10 task :publish_news do
11   require 'rubyforge'
12   spec = Gem::Specification.load('rainbows.gemspec')
13   tmp = Tempfile.new('rf-news')
14   _, subject, body = `git cat-file tag v#{spec.version}`.split(/\n\n/, 3)
15   tmp.puts subject
16   tmp.puts
17   tmp.puts spec.description.strip
18   tmp.puts ""
19   tmp.puts "* #{spec.homepage}"
20   tmp.puts "* #{spec.email}"
21   tmp.puts "* #{git_url}"
22   tmp.print "\nChanges:\n\n"
23   tmp.puts body
24   tmp.flush
25   system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
26   msg = File.readlines(tmp.path)
27   subject = msg.shift
28   blank = msg.shift
29   blank == "\n" or abort "no newline after subject!"
30   subject.strip!
31   body = msg.join("").strip!
33   rf = RubyForge.new.configure
34   rf.login
35   rf.post_news('rainbows', subject, body)
36 end
38 desc "post to FM"
39 task :fm_update do
40   require 'net/http'
41   require 'net/netrc'
42   require 'json'
43   version = ENV['VERSION'] or abort "VERSION= needed"
44   uri = URI.parse('https://freecode.com/projects/rainbows/releases.json')
45   rc = Net::Netrc.locate('rainbows-fm') or abort "~/.netrc not found"
46   api_token = rc.password
47   _, subject, body = `git cat-file tag v#{version}`.split(/\n\n/, 3)
48   tmp = Tempfile.new('fm-changelog')
49   tmp.puts subject
50   tmp.puts
51   tmp.puts body
52   tmp.flush
53   system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
54   changelog = File.read(tmp.path).strip
56   req = {
57     "auth_code" => api_token,
58     "release" => {
59       "tag_list" => "Stable",
60       "version" => version,
61       "changelog" => changelog,
62     },
63   }.to_json
64   if ! changelog.strip.empty? && version =~ %r{\A[\d\.]+\d+\z}
65     Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
66       p http.post(uri.path, req, {'Content-Type'=>'application/json'})
67     end
68   else
69     warn "not updating freshmeat for v#{version}"
70   end
71 end