about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-02-01 07:08:30 +0000
committerEric Wong <normalperson@yhbt.net>2011-02-01 07:08:30 +0000
commit8301a96e8f11f668a717afbdf95f3695cdc9ca3b (patch)
tree21244277738b4c1c41f513481f1b1433151ae5b1
parenta8e266ee000b8477d7ed0882cc072fd5422b57d5 (diff)
downloadlibnodelay-8301a96e8f11f668a717afbdf95f3695cdc9ca3b.tar.gz
add update-freshmeat script
We use it to... update freshmeat!
-rwxr-xr-xupdate-freshmeat.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/update-freshmeat.rb b/update-freshmeat.rb
new file mode 100755
index 0000000..9f9252e
--- /dev/null
+++ b/update-freshmeat.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+require "tempfile"
+require "net/http"
+require "net/netrc"
+require "json"
+version = ENV["VERSION"] or abort "VERSION= needed"
+uri = URI.parse("http://freshmeat.net/projects/libnodelay/releases.json")
+rc = Net::Netrc.locate("libnodelay-fm") or abort "~/.netrc not found"
+api_token = rc.password
+_, subject, body = `git cat-file tag v#{version}`.split(/\n\n/, 3)
+tmp = Tempfile.new("fm-changelog")
+tmp.puts subject
+tmp.puts
+tmp.puts body
+tmp.flush
+system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
+changelog = File.read(tmp.path).strip
+
+req = {
+  "auth_code" => api_token,
+  "release" => {
+    "tag_list" => "Stable",
+    "version" => version,
+    "changelog" => changelog,
+  },
+}.to_json
+
+if ! changelog.strip.empty? && version =~ %r{\A[\d\.]+\d+\z}
+  Net::HTTP.start(uri.host, uri.port) do |http|
+    p http.post(uri.path, req, {"Content-Type"=>"application/json"})
+  end
+else
+  warn "not updating freshmeat for v#{version}"
+end