Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add CircleCi service #522

Closed
wants to merge 4 commits into from

4 participants

@pbiggar

Adds CircleCi service, with tests, in accordance with CONTRIBUTING.md.

lib/services/circleci.rb
((2 lines not shown))
+
+ url "https://circleci.com"
+ logo_url "https://circleci.com/favicon.ico"
+
+ maintained_by :github => 'circleci'
+ supported_by :web => 'https://circleci.com/about',
+ :email => 'sayhi@circleci.com'
+
+ default_events Service::ALL_EVENTS
+
+
+ def receive_event
+
+ http.headers['content-type'] = 'application/x-www-form-urlencoded'
+ http.params.merge!(:payload => JSON.generate(payload) , :event_type => JSON.generate({ :event_type => self.event }))
+ http_post circleci_url, payload.to_json
@technoweenie Owner

Why are you posting JSON when the content type is application/x-www-form-urlencoded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@technoweenie
Owner

This looks fine, but why is it receiving all hooks? Does circleci run builds when someone follows your repository?

I'd prefer you only listen to the services that you need to function. Otherwise, update your documentation with what events that your service will receive.

@pbiggar

We're posting a form taking JSON strings, because that's what our backend accepts.

The main reason we're adding this service is that we want to embrace a lot more of github's features. We're starting to use some more events in the short term, but anticipate using a large majority over the next few months. When someone follows a repo, we want to mark them as following so that we can suggest they follow that repo from within circleci.

We have a use for nearly all features right now: commit_comment, create, delete, follow, fork, fork_apply, issue_comment, member, public, pull_request, push, team_add, watch, pull_request_review_comment and status. We want to do some experiments with how to support gist and gollum. We also want to be able to support new events without making a pull request, as we will almost certainly have a use for them.

@pbiggar

@technoweenie: how does this look now? OK to merge?

@technoweenie

As I mentioned, you need to update the documentation stating that you are listening to all of the events.

Also, you're still posting JSON as they body, and as the Get query parameters. You should do something like this:

http_post circleci_url,
  :payload => generate_json(payload) , :event_type =>  generate_json({ :event_type => self.event })

You'll have to parse the body in the tests to confirm you're passing it through properly.

@reillyse

@technoweenie how is that ? any better ?

@technoweenie

I think sending JSON as form values is ridiculous. My only point is that you were specifying the form type, but sending JSON in the body and sending the JSON as URI query params.

Just send JSON if you want my opinion :)

@technoweenie

Hey, I read your question wrong. I took it as "how is that any better" :) This looks good.

@technoweenie

This branch is based off an ancient master branch on your fork. I had to cherry pick your commits. You can see them here:

ca814d7...ee47e58

We'll get this pushed out later today. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 9, 2013
  1. @reillyse
  2. @pbiggar

    Merge pull request #1 from reillyse/master

    pbiggar authored
    Adding circleci services
Commits on Apr 24, 2013
  1. @reillyse
  2. @reillyse
This page is out of date. Refresh to see the latest.
Showing with 157 additions and 0 deletions.
  1. +13 −0 docs/circleci
  2. +26 −0 lib/services/circleci.rb
  3. +118 −0 test/circleci_test.rb
View
13 docs/circleci
@@ -0,0 +1,13 @@
+CircleCI continuous integration
+
+[CircleCi](https://circleci.com) will add these hooks automatically to projects which you test using CircleCi. By enabling all the events github offers it allows tighter integeration between github and CircleCI. To sign up, go to https://circleci.com, sign in, and start testing!
+
+Install Notes
+-------------
+
+1. Sign up at https://circleci.com with your github credentials
+2. Follow your repository
+3. You're done!
+
+For more details about CircleCI go to https://circleci.com
+
View
26 lib/services/circleci.rb
@@ -0,0 +1,26 @@
+class Service::Circleci < Service
+
+ url "https://circleci.com"
+ logo_url "https://circleci.com/favicon.ico"
+
+ maintained_by :github => 'circleci'
+ supported_by :web => 'https://circleci.com/about',
+ :email => 'sayhi@circleci.com'
+
+ default_events Service::ALL_EVENTS
+
+
+ def receive_event
+
+ http.headers['content-type'] = 'application/x-www-form-urlencoded'
+ http_post circleci_url, "payload" => JSON.generate(payload) , "event_type" => JSON.generate({ :event_type => self.event })
+
+ end
+
+
+ private
+
+ def circleci_url
+ "https://circleci.com/hooks/github"
+ end
+end
View
118 test/circleci_test.rb
@@ -0,0 +1,118 @@
+require File.expand_path('../helper', __FILE__)
+class CircleciTest < Service::TestCase
+
+ def setup
+ @stubs = Faraday::Adapter::Test::Stubs.new
+ end
+
+
+ # currently supported events
+
+ # commit_comment create delete download follow fork fork_apply gist gollum
+ # issue_comment issues member public pull_request push team_add watch
+ # pull_request_review_comment status
+
+ def test_commit_comment
+ post_to_service(:commit_comment)
+ end
+
+ def test_create
+ post_to_service(:create)
+ end
+
+ def test_delete
+ post_to_service(:delete)
+ end
+
+ def test_download
+ post_to_service(:download)
+ end
+
+ def test_follow
+ post_to_service(:follow)
+ end
+
+ def test_fork
+ post_to_service(:fork)
+ end
+
+ def test_fork_apply
+ post_to_service(:fork_apply)
+ end
+
+ def test_gist
+ post_to_service(:gist)
+ end
+
+ def test_gollum
+ post_to_service(:gollum)
+ end
+
+ def test_issue_comment
+ post_to_service(:issue_comment)
+ end
+
+ def test_issues
+ post_to_service(:issues)
+ end
+
+ def test_member
+ post_to_service(:member)
+ end
+
+ def test_public
+ post_to_service(:public)
+ end
+
+
+
+ def test_push
+ post_to_service(:push)
+ end
+
+
+ def test_team_add
+ post_to_service(:team_add)
+ end
+
+ def test_watch
+ post_to_service(:watch)
+ end
+
+ def test_pull_request_review_comment
+ post_to_service(:pull_request_review_comment)
+ end
+
+ def test_status
+ post_to_service(:status)
+ end
+
+ def test_supported_events
+ assert_equal Service::Circleci.supported_events.sort , Service::ALL_EVENTS.sort
+ end
+
+
+ private
+
+ def service(*args)
+ super Service::Circleci, *args
+ end
+
+ def post_to_service(event_name)
+ assert Service::ALL_EVENTS.include? event_name.to_s
+ svc = service(event_name, {'token' => 'abc'},payload)
+
+ @stubs.post "/hooks/github" do |env|
+ body = CGI.parse env[:body]
+ assert_match "https://circleci.com/hooks/github", env[:url].to_s
+ assert_match 'application/x-www-form-urlencoded', env[:request_headers]['content-type']
+ assert_equal payload, JSON.parse(body["payload"].to_s)
+ assert_equal event_name.to_s, JSON.parse(body["event_type"].to_s)["event_type"]
+ end
+
+ svc.receive_event
+
+ end
+
+end
+
Something went wrong with that request. Please try again.