Permalink
Browse files

initial version

  • Loading branch information...
jnewland committed Feb 16, 2008
0 parents commit ad6810df73d0ffdf0e66de3f7cc854352561a800
Showing with 56 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +12 −0 config.yml.example
  3. +42 −0 github-campfire.rb
@@ -0,0 +1,2 @@
+config.yml
+development.log
@@ -0,0 +1,12 @@
+repo-name:
+ subdomain: chattastic
+ username: campfire-user@foo.com
+ password: p00p
+ room: "My Awesome Room"
+ template: "[<%= commit['repo'] %>] <%= commit['message'] %> - <%= commit['author']['name'] %> (<%= commit['url'] %>)"
+repo-name-2:
+ subdomain: chattastic
+ username: campfire-user@foo.com
+ password: p00p
+ room: "My Awesome Room 2"
+ #template: if template is ommitted, a default will be used
@@ -0,0 +1,42 @@
+require 'rubygems'
+require 'JSON'
+require 'tinder'
+require 'sinatra'
+require 'erb'
+
+REPOS = YAML.load_file('config.yml')
+
+class GithubCampfire
+
+ def initialize(payload)
+ payload = JSON.parse(payload)
+ return unless payload.keys.include?("repository")
+ @repo = payload["repository"]["name"]
+ @template = ERB.new(REPOS[@repo]["template"] || "[<%= commit['repo'] %>] <%= commit['message'] %> - <%= commit['author']['name'] %> (<%= commit['url'] %>)")
+ @room = connect(@repo)
+ payload["commits"].each { |c| process_commit(c.last) }
+ end
+
+ def connect(repo)
+ credentials = REPOS[repo]
+ campfire = Tinder::Campfire.new(credentials['subdomain'])
+ campfire.login(credentials['username'], credentials['password'])
+ return campfire.find_room_by_name(credentials['room'])
+ end
+
+ def process_commit(commit)
+ #we don't need all sorts of local_assigns eval shit here, so this'll do
+ commit["repo"] = @repo
+ proc = Proc.new do
+ commit
+ end
+ @room.speak(@template.result(proc))
+ speak(@template.result(proc))
+ end
+
+end
+
+post '/' do
+ GithubCampfire.new(params[:payload])
+ "OMGPONIES! IT WORKED"
+end

0 comments on commit ad6810d

Please sign in to comment.