Skip to content

Commit

Permalink
Resolves #1 - Basic skeleton is now working.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Mar 24, 2008
1 parent b521099 commit 300afdb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
3 changes: 2 additions & 1 deletion config.example
@@ -1,11 +1,12 @@
unfuddle:
subdomain: something
use_ssl: false
user: yourusername
password: yourpassword
people:
githubemailaddress@something.com: 1111

repositories:
github-unfuddle:
unfuddle-project-id: 1111
unfuddle_project_id: 1111

67 changes: 56 additions & 11 deletions github_unfuddle.rb
Expand Up @@ -2,33 +2,78 @@
require 'sinatra'
require 'json'
require 'yaml'
require 'net/http'

CONFIG = YAML.load_file("config.yml")

post '/' do
puts "\n\n#{params[:payload]}\n\n"
push = JSON.parse(params[:payload])
build_unfuddle_xml_from(push)
end

def build_unfuddle_xml_from(push)
puts push.inspect
config = YAML.load_file("config.yml")
repository = push["repository"]
commits = push["commits"]
output = ""
@repository = push["repository"]
@commits = push["commits"]

raise "Must specify Unfuddle subdomain, user, and password." unless CONFIG["unfuddle"]["subdomain"] && CONFIG["unfuddle"]["user"] && CONFIG["unfuddle"]["password"]
raise "Could not map from GitHub project name to Unfuddle Project ID." unless unfuddle_project_id

successes = []

commits.each do |id, commit|
@commits.each do |id, commit|
timestamp = Time.parse(commit['timestamp'])
xml = <<-XML
<changeset>
#{"<author-id type=\"integer\">#{config["unfuddle"]["people"][commit["author"]["email"]]}</author-id>" if config["unfuddle"]["people"][commit["author"]["email"]]}
#{"<author-id type=\"integer\">#{unfuddle_author_id(commit)}</author-id>" if unfuddle_author_id(commit)}
<message>#{commit["message"]}
[More Detail](#{commit["url"]})</message>
Details: #{commit["url"]}</message>
<revision type="integer">#{timestamp.strftime("%y%m%d%H%M")}</revision>
</changeset>
XML

output << xml
successes << post_changeset_to_unfuddle(xml)
end
output

successes.inspect
end

def post_changeset_to_unfuddle(xml)
http = Net::HTTP.new("#{CONFIG["unfuddle"]["subdomain"]}.unfuddle.com", CONFIG["unfuddle"]["use_ssl"] ? 443 : 80)

# if using ssl, then set it up
if CONFIG["unfuddle"]["use_ssl"]
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

begin
path = "/api/v1/projects/#{unfuddle_project_id}/changesets.xml"
puts path.inspect
request = Net::HTTP::Post.new(path, {'Content-type' => 'application/xml'})
request.basic_auth CONFIG["unfuddle"]["user"], CONFIG["unfuddle"]["password"]
request.body = xml

puts request.inspect

response = http.request(request)

if response.code == "201"
return response['Location']
else
puts response.body
return false
end
rescue => e
puts e.message
return false
end
end

def unfuddle_project_id
CONFIG["repositories"][@repository["name"]]["unfuddle_project_id"]
end

def unfuddle_author_id(commit)
CONFIG["unfuddle"]["people"][commit["author"]["email"]]
end

0 comments on commit 300afdb

Please sign in to comment.