This repository has been archived by the owner on Jan 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39db84b
commit e9408ff
Showing
3 changed files
with
100 additions
and
137 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 |
---|---|---|
@@ -1,23 +1,25 @@ | ||
service :freckle do |data, payload| | ||
class Service::Freckle < Service | ||
self.hook_name = :freckle | ||
|
||
entries, subdomain, token, project = | ||
[], data['subdomain'].strip, data['token'].strip, data['project'].strip | ||
def receive_push | ||
entries, subdomain, token, project = | ||
[], data['subdomain'].strip, data['token'].strip, data['project'].strip | ||
|
||
payload['commits'].each do |commit| | ||
minutes = (commit["message"].split(/\s/).find { |item| /^f:/ =~ item } || '')[2,100] | ||
next unless minutes | ||
entries << { | ||
:date => commit["timestamp"], | ||
:minutes => minutes, | ||
:description => commit["message"].gsub(/(\s|^)f:.*(\s|$)/, '').strip, | ||
:url => commit['url'], | ||
:project_name => project, | ||
:user => commit['author']['email'] | ||
} | ||
payload['commits'].each do |commit| | ||
minutes = (commit["message"].split(/\s/).find { |item| /^f:/ =~ item } || '')[2,100] | ||
next unless minutes | ||
entries << { | ||
:date => commit["timestamp"], | ||
:minutes => minutes, | ||
:description => commit["message"].gsub(/(\s|^)f:.*(\s|$)/, '').strip, | ||
:url => commit['url'], | ||
:project_name => project, | ||
:user => commit['author']['email'] | ||
} | ||
end | ||
|
||
http.headers['Content-Type'] = 'application/json' | ||
http_post "http://#{data['subdomain']}.letsfreckle.com/api/entries/import", | ||
{:entries => entries, :token => data['token']}.to_json | ||
end | ||
uri = URI.parse("http://#{data['subdomain']}.letsfreckle.com/api/entries/import") | ||
req = Net::HTTP::Post.new(uri.path) | ||
req.set_content_type('application/json') | ||
req.body = { :entries => entries, :token => data['token'] }.to_json | ||
Net::HTTP.new(uri.host, uri.port).start {|http| http.request(req) } | ||
end |
This file was deleted.
Oops, something went wrong.
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,79 @@ | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
class FreckleTest < Service::TestCase | ||
def setup | ||
@stubs = Faraday::Adapter::Test::Stubs.new | ||
end | ||
|
||
def test_posts_with_2_entries | ||
data = call_service :push | ||
assert_equal 2, data['entries'].size | ||
end | ||
|
||
def test_includes_auth_token | ||
data = call_service :push | ||
assert_equal '12345', data['token'] | ||
end | ||
|
||
def test_parses_minutes_from_commit_message | ||
data = call_service :push | ||
assert_equal '15', data['entries'][0]['minutes'] | ||
assert_equal '2hrs', data['entries'][1]['minutes'] | ||
end | ||
|
||
def test_strips_freckle_tags | ||
data = call_service :push | ||
assert_equal 'stub git call for Grit#heads test', | ||
data['entries'][0]['description'] | ||
assert_equal 'clean up heads test', | ||
data['entries'][1]['description'] | ||
end | ||
|
||
def test_includes_project_name | ||
data = call_service :push | ||
assert_equal 'Test Project', | ||
data['entries'][0]['project_name'] | ||
end | ||
|
||
def test_includes_author_email_as_user | ||
data = call_service :push | ||
assert_equal 'tom@mojombo.com', | ||
data['entries'][0]['user'] | ||
end | ||
|
||
def test_includes_commit_url | ||
data = call_service :push | ||
assert_equal 'http://github.com/mojombo/grit/commit/06f63b43050935962f84fe54473a7c5de7977325', | ||
data['entries'][0]['url'] | ||
end | ||
|
||
def test_includes_timestamp_as_date | ||
data = call_service :push | ||
assert_equal '2007-10-10T00:11:02-07:00', | ||
data['entries'][0]['date'] | ||
end | ||
|
||
def data | ||
{ | ||
"subdomain" => "abloom", | ||
"token" => "12345", | ||
"project" => "Test Project" | ||
} | ||
end | ||
|
||
def service(*args) | ||
super Service::Freckle, *args | ||
end | ||
|
||
def call_service(event) | ||
res = nil | ||
svc = service event, data, payload | ||
@stubs.post '/api/entries/import' do |env| | ||
res = JSON.parse env[:body] | ||
end | ||
svc.send "receive_#{event}" | ||
res | ||
end | ||
end | ||
|
||
|