public
Description: Sinatra app that pushes your Github Commit info to twitter
Homepage: http://groups.google.com/group/github-twitter/
Clone URL: git://github.com/jnunemaker/github-twitter.git
commit  7e9825c9ab4488707f0aea1d991fe707b4d70162
tree    02169d423dc44fef9467bc03baaadb710cad553a
parent  eb40914e7c7f4cec9e6542eb2921c945e75be9eb
github-twitter / github-twitter.rb
100644 38 lines (31 sloc) 0.935 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'rubygems'
require 'json'
require 'twitter'
require 'sinatra'
require 'erb'
 
REPOS = YAML.load_file('config.yml')
 
class GithubTwitter
  
  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['url'] %> by <%= commit['author']['name'] %> - <%= commit['message'] %>")
    @twitter = connect(@repo)
    payload["commits"].each { |c| process_commit(c.last) }
  end
  
  def connect(repo)
    credentials = REPOS[repo]
    return Twitter::Base.new(credentials['username'], credentials['password'])
  end
  
  def process_commit(commit)
    commit["repo"] = @repo
    proc = Proc.new do
      commit
    end
    @twitter.post(@template.result(proc))
  end
  
end
 
post '/' do
  GithubTwitter.new(params[:payload])
  "OMGPONIES! IT WORKED"
end