Skip to content

Commit

Permalink
Adds github commit url parsing.
Browse files Browse the repository at this point in the history
Closes #42.
  • Loading branch information
rwjblue committed Sep 24, 2013
1 parent 94ab61b commit ff7c1d8
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
51 changes: 51 additions & 0 deletions plugin/url_handler/github_commit_handler.rb
@@ -0,0 +1,51 @@
module UrlHandler
class GithubCommitHandler
include Common

REGEXP = %r{https?://(?:www\.)?github\.com/([^/]+?)/([^/]+)/commit/(\w+)}

attr_accessor :url, :username, :repository, :sha

def self.match?(string)
REGEXP.match(string)
end

def initialize(url)
self.url = url
end

def username
@username ||= REGEXP.match(url)[1]
end

def repository
@repository ||= REGEXP.match(url)[2]
end

def sha
@sha ||= REGEXP.match(url)[3]
end

def api_url
@api_url ||= "https://api.github.com/repos/#{username}/#{repository}/git/commits/#{sha}"
end

def api_data
@api_data ||= get_json_data(api_url)
end

def message
api_data['message'].split("\n\n").first
end

def author
api_data['author']['name']
end

def info
"github commit: \2#{username}/#{repository}\2 \2#{sha[0,7]}\2 - #{message}"
end
end
end


1 change: 1 addition & 0 deletions plugin/url_handler_cinch_plugin.rb
Expand Up @@ -4,6 +4,7 @@
require_relative 'url_handler/common'
require_relative 'url_handler/github_issue_handler'
require_relative 'url_handler/github_pull_request_handler'
require_relative 'url_handler/github_commit_handler'
require_relative 'url_handler/github_repo_handler'
require_relative 'url_handler/gist_handler'
require_relative 'url_handler/twitter_user_handler'
Expand Down
86 changes: 86 additions & 0 deletions spec/fixtures/vcr_cassettes/url_handler_github_commit.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions spec/plugin/url_handler_spec.rb
Expand Up @@ -120,6 +120,17 @@
end
end

context "when a github commit url is given" do
let(:url) {'https://github.com/TampaRuby/turbot/commit/94ab61b10ff94220ca1f7a3fff46b55bb92b9e20'}
let(:message) {double('message', :raw => url)}
let(:reply_text) {"github commit: \x02TampaRuby/turbot\x02 \x0294ab61b\x02 - Merge pull request #37 from rjackson/parse_github_urls"}

it "should reply." do
message.should_receive(:reply).with(reply_text)
VCR.use_cassette('url_handler_github_commit') { plugin.listen(message) }
end
end

context "when an image url is given" do
let(:url) {'http://farm9.staticflickr.com/8013/7619514930_4a1ed85893_z.jpg'}
let(:message) {double('message', :raw => url)}
Expand Down

0 comments on commit ff7c1d8

Please sign in to comment.