forked from github/github-services
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit of new RubyForge service
- Loading branch information
Showing
5 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |