Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simple mods to copperegg.rb and copperegg_test.rb for working with ru…

…by 1.87
  • Loading branch information...
commit 855ae702f252e7b94974c4c8d4dcb66d7f6ec713 1 parent e22a56b
@scottcjohnson scottcjohnson authored
Showing with 64 additions and 16 deletions.
  1. +14 −8 services/copperegg.rb
  2. +50 −8 test/copperegg_test.rb
View
22 services/copperegg.rb
@@ -1,22 +1,28 @@
class Service::CopperEgg < Service
- string :tag
+ string :url, :tag
boolean :master_only
- password :api_key
+ string :api_key
def receive_push
+
raise_config_error 'API Key must be set' if data['api_key'].blank?
if data['master_only'].to_i == 1 && branch_name != 'master'
return
end
+ http.ssl[:verify] = false
+ http.basic_auth(data['api_key'], "U")
+ http.headers['Content-Type'] = 'application/json'
+ if data['url'] != "" && data['url'] != nil
+ url = data['url']
+ else
+ url = "https://api.copperegg.com/v2/annotations.json"
+ end
note = "GitHub: #{payload['pusher']['name']} has pushed #{payload['commits'].size} commit(s) to #{payload['repository']['name']}"
-
- res = http_post "https://#{api_key}:U@api.copperegg.com/v2/annotations.json",
- :note => note,
- :starttime => Time.now.to_i - 30,
- :endtime => Time.now.to_i + 30,
- :tags => tag
+ body = {"note" => note, "starttime" => Time.now.to_i - 30, "endtime" => Time.now.to_i + 30, "tags" => data['tag']}.to_json
+
+ res = http_post url, body
if res.status < 200 || res.status > 299
raise_config_error
end
View
58 test/copperegg_test.rb
@@ -3,22 +3,64 @@
class CopperEggTest < Service::TestCase
def setup
@stubs = Faraday::Adapter::Test::Stubs.new
+ @data = {
+ 'url' => 'https://api.copperegg.com/custom',
+ 'api_key' => '134567890',
+ 'tag' => 'newtag',
+ 'master_only' => '0'
+ }
+ @payload = {
+ "after" => "a47fd41f3aa4610ea527dcc1669dfdb9c15c5425",
+ "ref" => "refs/heads/master",
+ "before" => "4c8124ffcf4039d292442eeccabdeca5af5c5017",
+ "compare" => "http://github.com/mojombo/grit/compare/4c8124ffcf4039d292442eeccabdeca5af5c5017...a47fd41f3aa4610ea527dcc1669dfdb9c15c5425",
+ "forced" => false,
+ "created" => false,
+ "deleted" => false,
+
+ "repository" => {
+ "name" => "grit",
+ "url" => "http://github.com/mojombo/grit",
+ "owner" => { "name" => "mojombo", "email" => "tom@mojombo.com" }
+ },
+
+ "pusher" => {
+ "name" => "rtomayko"
+ },
+
+ "commits" => [
+ {
+ "distinct" => true,
+ "removed" => [],
+ "message" => "[#WEB-249 status:31 resolution:1] stub git call for Grit#heads test",
+ "added" => [],
+ "timestamp" => "2007-10-10T00:11:02-07:00",
+ "modified" => ["lib/grit/grit.rb", "test/helper.rb", "test/test_grit.rb"],
+ "url" => "http://github.com/mojombo/grit/commit/06f63b43050935962f84fe54473a7c5de7977325",
+ "author" => { "name" => "Tom Preston-Werner", "email" => "tom@mojombo.com" },
+ "id" => "06f63b43050935962f84fe54473a7c5de7977325"
+ }
+ ]
+ }
end
def test_push
- @stubs.post "/v2/annotations.json" do |env|
- assert_match "api_key=beef", env[:body]
- assert_match "tag=taggy", env[:body]
+ svc = service(@data, @payload)
+ assert_equal 1, @payload['commits'].size
+ assert_equal 'rtomayko', @payload['pusher']['name']
+ assert_equal 'grit', @payload['repository']['name']
+
+ @stubs.post "/custom" do |env|
+ assert_match "Basic MTM0NTY3ODkwOlU=", env[:request_headers]["authorization"]
+ assert_equal "application/json", env[:request_headers]["Content-Type"]
+ assert_match "GitHub: rtomayko has pushed 1 commit(s) to grit", env[:body]
+ assert_match "newtag", env[:body]
[200, {}, '']
end
-
- svc = service(
- {'api_key' => 'beef', 'tag' => 'taggy'}, 'a' => 1)
svc.receive_push
end
def service(*args)
- super Service::HipChat, *args
+ super Service::CopperEgg, *args
end
end
-
Please sign in to comment.
Something went wrong with that request. Please try again.