Skip to content

Commit

Permalink
initial commit of new RubyForge service
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan T. Richardson authored and pjhyett committed Nov 12, 2008
1 parent 2896670 commit a24963a
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/rubyforge
@@ -0,0 +1,30 @@
RubyForge
=========

Special Thanks
-------------

Would like to notice Ara Howard and his RubyForge gem, from which I copied most of the code
used in this service. Would also like to notice the author of the Basecamp service, since
I used that service as a template for the RubyForge service.

This service simply posts a new NewsByte to the RubyForge project (as specified by the groupid).

Install Notes
-------------

1. username should be the username of a user that has access to the RubyForge project
2. password should be the password of the given user
3. groupid should be the group id of the RubyForge project


Developer Notes
---------------

data
- username
- password
- groupid

payload
- refer to docs/github_payload
1 change: 1 addition & 0 deletions github-services.rb
Expand Up @@ -21,6 +21,7 @@
require 'tmail'
require 'xmpp4r'
require 'xmpp4r-simple'
require 'rubyforge'

module GitHub
def service(name, &block)
Expand Down
Empty file modified services/cia.rb 100755 → 100644
Empty file.
11 changes: 11 additions & 0 deletions services/rubyforge.rb
@@ -0,0 +1,11 @@
service :rubyforge do |data, payload|
repository = payload['repository']['name']
branch = payload['ref'].split('/').last
payload['commits'].each do |id, commit|
rf = RubyForge.new(data['username'], data['password'])
group_id = data['groupid']
subject = "Commit Notification (#{repository}/#{branch}): #{id}"
body = "`#{commit['message']}`, pushed by #{commit['author']['name']} (#{commit['author']['email']}). View more details for this change at #{commit['url']}."
rf.post_news(group_id, subject, body)
end
end
74 changes: 74 additions & 0 deletions vendor/rubyforge/lib/rubyforge.rb
@@ -0,0 +1,74 @@
# This code was pretty much copied from Ara Howard's
# RubyForge gem... thanks Ara! :)

require 'net/https'
require 'openssl'
require 'webrick/cookie'

class RubyForge
def initialize(username, password)
@cookies = Array.new
login(username, password)
end

def post_news(group_id, subject, body)
url = URI.parse('http://rubyforge.org/news/submit.php')
form = {
'group_id' => group_id.to_s,
'post_changes' => 'y',
'summary' => subject,
'details' => body,
'submit' => 'Submit'
}
execute(url, form)
end

#######
private
#######

def login(username, password)
url = URI.parse('https://rubyforge.org/account/login.php')
form = {
'return_to' => '',
'form_loginname' => username,
'form_pw' => password,
'login' => 'Login'
}
response = execute(url, form)
bake_cookies(url, response)
end

def execute(url, parameters)
request = Net::HTTP::Post.new(url.request_uri)
request['Content-Type'] = 'application/x-www-form-urlencoded'
@cookies.each do |cookie|
request['Cookie'] = cookie
end
http = Net::HTTP.new(url.host, url.port)
if url.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
request_data = query_string_for(parameters)
request['Content-Length'] = request_data.length.to_s
http.request(request, request_data)
end

def bake_cookies(url, response)
(response.get_fields('Set-Cookie') || []).each do |raw_cookie|
WEBrick::Cookie.parse_set_cookies(raw_cookie).each do |baked_cookie|
baked_cookie.domain ||= url.host
baked_cookie.path ||= url.path
@cookies << baked_cookie
end
end
end

def query_string_for(parameters)
parameters.sort_by { |k,v| k.to_s }.map { |k,v|
k && [ WEBrick::HTTPUtils.escape_form(k.to_s),
WEBrick::HTTPUtils.escape_form(v.to_s) ].join('=')
}.compact.join('&')
end
end

0 comments on commit a24963a

Please sign in to comment.